GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

src/util/moveTreeNode.js   A
last analyzed

Complexity

Total Complexity 4
Complexity/F 4

Size

Lines of Code 58
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
wmc 4
nc 1
mnd 1
bc 4
fnc 1
dl 0
loc 58
rs 10
bpm 4
cpm 4
noi 6
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A moveTreeNode.js ➔ ??? 0 54 4
1
import { List } from 'immutable';
2
3
import { findTreeNode } from './findTreeNode';
4
5
export const moveTreeNode = (
6
    treeData,
7
    currentIndex,
8
    currentPath,
9
    nextIndex,
10
    nextPath,
11
    childIdentifier = 'children',
12
    rootIdentifier = 'root'
13
) => {
14
15
    const originalTreeData = treeData;
16
17
    const { node: currentParent, indexPath: currentIndexPath } = findTreeNode(
18
        treeData,
19
        currentPath,
20
        childIdentifier,
21
        rootIdentifier
22
    );
23
24
    if (!currentParent) {
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable currentParent is declared in the current environment, consider using typeof currentParent === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
25
        return originalTreeData;
26
    }
27
28
    currentIndexPath.push(...[childIdentifier, currentIndex]);
0 ignored issues
show
Bug introduced by
The variable currentIndexPath seems to be never declared. If this is a global, consider adding a /** global: currentIndexPath */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
29
30
    let node = treeData.getIn(currentIndexPath);
0 ignored issues
show
introduced by
You seem to be assigning a new value to the const node. Consider using a var instead.
Loading history...
Comprehensibility Naming Best Practice introduced by
The variable node already seems to be declared on line 17. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
31
    treeData = treeData.deleteIn(currentIndexPath);
32
33
    const { node: nextParent, indexPath: nextIndexPath } = findTreeNode(
34
        treeData,
35
        nextPath,
36
        childIdentifier,
37
        rootIdentifier
38
    );
39
40
    if (!nextParent) {
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable nextParent is declared in the current environment, consider using typeof nextParent === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
41
        return originalTreeData;
42
    }
43
44
    nextIndexPath.push(childIdentifier);
0 ignored issues
show
Bug introduced by
The variable nextIndexPath seems to be never declared. If this is a global, consider adding a /** global: nextIndexPath */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
45
46
    if (!List.isList(treeData.getIn(nextIndexPath))) {
47
        treeData = treeData.setIn(nextIndexPath, List());
48
    }
49
50
    node = node.set('parentId', nextPath.last());
51
52
    treeData = treeData.setIn(
53
        nextIndexPath,
54
        treeData.getIn(nextIndexPath).insert(nextIndex, node)
55
    );
56
57
    return treeData;
58
};
59