Skip to content

Commit e734651

Browse files
committed
eslint update + fixed new js lint issues
1 parent 13702e4 commit e734651

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1779
-536
lines changed

.eslintrc.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"prefer-destructuring": ["error", {"object": true, "array": false}],
3333
"padded-blocks": 0,
3434
"no-sparse-arrays": 0,
35-
"array-bracket-spacing": 0
35+
"array-bracket-spacing": 0,
36+
"import/no-named-as-default": 0,
37+
"implicit-arrow-linebreak": 0
3638
}
3739
}

package-lock.json

+1,562-471
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"lint:js": "eslint src/js && eslint test/js",
2222
"lint:ts": "tslint -c tslint.json 'src/ts/**/*.ts' && tslint -c tslint.json 'test/ts/**/*.ts'",
2323
"lint": "npm run lint:js && npm run lint:ts",
24+
"eslintFix": "eslint src/js --fix && eslint test/js --fix",
2425
"test:js": "mocha --compilers js:babel-core/register ./test/js --recursive --reporter mochawesome",
2526
"test:ts": "mocha -r ts-node/register ./test/ts/**/*.spec.ts ./test/ts/**/**/*.spec.ts --recursive",
2627
"test": "npm run test:js && npm run test:ts",
@@ -58,15 +59,15 @@
5859
"@types/mocha": "^5.0.0",
5960
"babel-cli": "^6.26.0",
6061
"babel-core": "^6.26.3",
61-
"babel-eslint": "^8.2.2",
62-
"babel-loader": "^7.1.4",
63-
"babel-plugin-add-module-exports": "^0.2.1",
62+
"babel-eslint": "^10.0.1",
63+
"babel-loader": "^8.0.5",
64+
"babel-plugin-add-module-exports": "^1.0.0",
6465
"babel-plugin-transform-es2015-modules-umd": "^6.24.1",
6566
"babel-preset-env": "^1.7.0",
6667
"chai": "^4.1.2",
6768
"codecov": "^3.2.0",
68-
"eslint": "^4.18.2",
69-
"eslint-config-airbnb-base": "^12.1.0",
69+
"eslint": "^5.15.1",
70+
"eslint-config-airbnb-base": "^13.1.0",
7071
"eslint-plugin-import": "^2.16.0",
7172
"istanbul": "^v1.1.0-alpha.1",
7273
"mocha": "^5.0.4",

src/js/algorithms/backtracking/sudoku-solver.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ function usedInBox(matrix, boxStartRow, boxStartCol, num) {
3131

3232
function isSafe(matrix, row, col, num) {
3333
return (
34-
!usedInRow(matrix, row, num) &&
35-
!usedInCol(matrix, col, num) &&
36-
!usedInBox(matrix, row - (row % 3), col - (col % 3), num)
34+
!usedInRow(matrix, row, num)
35+
&& !usedInCol(matrix, col, num)
36+
&& !usedInBox(matrix, row - (row % 3), col - (col % 3), num)
3737
);
3838
}
3939
function solveSudoku(matrix) {

src/js/algorithms/dynamic-programing/matrix-chain-multiplication.js

-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,3 @@ export function matrixChainOrder(p) {
4343
printOptimalParenthesis(s, 1, n - 1);
4444
return m[1][n - 1];
4545
}
46-

src/js/algorithms/dynamic-programing/min-coin-change.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export function minCoinChange(coins, amount) {
1818
newMin = makeChange(newAmount);
1919
}
2020
if (
21-
newAmount >= 0 &&
22-
(newMin.length < min.length - 1 || !min.length) &&
23-
(newMin.length || !newAmount)
21+
newAmount >= 0
22+
&& (newMin.length < min.length - 1 || !min.length)
23+
&& (newMin.length || !newAmount)
2424
) {
2525
min = [coin].concat(newMin);
2626
// console.log('new Min ' + min + ' for ' + amount);

src/js/algorithms/greedy/matrix-chain-multiplication.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ export function matrixChainOrder(p, i = 1, j = p.length - 1) {
44
}
55
let min = Number.MAX_SAFE_INTEGER;
66
for (let k = i; k < j; k++) {
7-
const count =
8-
matrixChainOrder(p, i, k) + matrixChainOrder(p, k + 1, j) + ((p[i - 1] * p[k]) * p[j]);
7+
const count = matrixChainOrder(p, i, k)
8+
+ matrixChainOrder(p, k + 1, j) + ((p[i - 1] * p[k]) * p[j]);
99
if (count < min) {
1010
min = count;
1111
}

src/js/algorithms/search/interpolation-search.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export function interpolationSearch(
2121
let position = -1;
2222
let delta = -1;
2323
while (
24-
low <= high &&
25-
biggerEquals(value, array[low], compareFn) &&
26-
lesserEquals(value, array[high], compareFn)
24+
low <= high
25+
&& biggerEquals(value, array[low], compareFn)
26+
&& lesserEquals(value, array[high], compareFn)
2727
) {
2828
delta = diffFn(value, array[low]) / diffFn(array[high], array[low]);
2929
position = low + Math.floor((high - low) * delta);

src/js/data-structures/avl-tree.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ export default class AVLTree extends BinarySearchTree {
1616
this.compareFn = compareFn;
1717
this.root = null;
1818
}
19+
1920
getNodeHeight(node) {
2021
if (node == null) {
2122
return -1;
2223
}
2324
return Math.max(this.getNodeHeight(node.left), this.getNodeHeight(node.right)) + 1;
2425
}
26+
2527
/**
2628
* Left left case: rotate right
2729
*
@@ -39,6 +41,7 @@ export default class AVLTree extends BinarySearchTree {
3941
tmp.right = node;
4042
return tmp;
4143
}
44+
4245
/**
4346
* Right right case: rotate left
4447
*
@@ -56,6 +59,7 @@ export default class AVLTree extends BinarySearchTree {
5659
tmp.left = node;
5760
return tmp;
5861
}
62+
5963
/**
6064
* Left right case: rotate left then right
6165
* @param node Node<T>
@@ -64,6 +68,7 @@ export default class AVLTree extends BinarySearchTree {
6468
node.left = this.rotationRR(node.left);
6569
return this.rotationLL(node);
6670
}
71+
6772
/**
6873
* Right left case: rotate right then left
6974
* @param node Node<T>
@@ -72,6 +77,7 @@ export default class AVLTree extends BinarySearchTree {
7277
node.right = this.rotationLL(node.right);
7378
return this.rotationRR(node);
7479
}
80+
7581
getBalanceFactor(node) {
7682
const heightDifference = this.getNodeHeight(node.left) - this.getNodeHeight(node.right);
7783
switch (heightDifference) {
@@ -87,13 +93,15 @@ export default class AVLTree extends BinarySearchTree {
8793
return BalanceFactor.BALANCED;
8894
}
8995
}
96+
9097
insert(key) {
9198
this.root = this.insertNode(this.root, key);
9299
}
100+
93101
insertNode(node, key) {
94102
if (node == null) {
95103
return new Node(key);
96-
} else if (this.compareFn(key, node.key) === Compare.LESS_THAN) {
104+
} if (this.compareFn(key, node.key) === Compare.LESS_THAN) {
97105
node.left = this.insertNode(node.left, key);
98106
} else if (this.compareFn(key, node.key) === Compare.BIGGER_THAN) {
99107
node.right = this.insertNode(node.right, key);
@@ -122,6 +130,7 @@ export default class AVLTree extends BinarySearchTree {
122130
}
123131
return node;
124132
}
133+
125134
removeNode(node, key) {
126135
node = super.removeNode(node, key); // {1}
127136
if (node == null) {
@@ -132,8 +141,8 @@ export default class AVLTree extends BinarySearchTree {
132141
if (balanceFactor === BalanceFactor.UNBALANCED_LEFT) {
133142
// Left left case
134143
if (
135-
this.getBalanceFactor(node.left) === BalanceFactor.BALANCED ||
136-
this.getBalanceFactor(node.left) === BalanceFactor.SLIGHTLY_UNBALANCED_LEFT
144+
this.getBalanceFactor(node.left) === BalanceFactor.BALANCED
145+
|| this.getBalanceFactor(node.left) === BalanceFactor.SLIGHTLY_UNBALANCED_LEFT
137146
) {
138147
return this.rotationLL(node);
139148
}
@@ -145,8 +154,8 @@ export default class AVLTree extends BinarySearchTree {
145154
if (balanceFactor === BalanceFactor.UNBALANCED_RIGHT) {
146155
// Right right case
147156
if (
148-
this.getBalanceFactor(node.right) === BalanceFactor.BALANCED ||
149-
this.getBalanceFactor(node.right) === BalanceFactor.SLIGHTLY_UNBALANCED_RIGHT
157+
this.getBalanceFactor(node.right) === BalanceFactor.BALANCED
158+
|| this.getBalanceFactor(node.right) === BalanceFactor.SLIGHTLY_UNBALANCED_RIGHT
150159
) {
151160
return this.rotationRR(node);
152161
}

src/js/data-structures/binary-search-tree.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default class BinarySearchTree {
66
this.compareFn = compareFn;
77
this.root = undefined;
88
}
9+
910
insert(key) {
1011
// special case: first key
1112
if (this.root == null) {
@@ -14,6 +15,7 @@ export default class BinarySearchTree {
1415
this.insertNode(this.root, key);
1516
}
1617
}
18+
1719
insertNode(node, key) {
1820
if (this.compareFn(key, node.key) === Compare.LESS_THAN) {
1921
if (node.left == null) {
@@ -27,84 +29,99 @@ export default class BinarySearchTree {
2729
this.insertNode(node.right, key);
2830
}
2931
}
32+
3033
getRoot() {
3134
return this.root;
3235
}
36+
3337
search(key) {
3438
return this.searchNode(this.root, key);
3539
}
40+
3641
searchNode(node, key) {
3742
if (node == null) {
3843
return false;
3944
}
4045
if (this.compareFn(key, node.key) === Compare.LESS_THAN) {
4146
return this.searchNode(node.left, key);
42-
} else if (this.compareFn(key, node.key) === Compare.BIGGER_THAN) {
47+
} if (this.compareFn(key, node.key) === Compare.BIGGER_THAN) {
4348
return this.searchNode(node.right, key);
4449
}
4550
return true;
4651
}
52+
4753
inOrderTraverse(callback) {
4854
this.inOrderTraverseNode(this.root, callback);
4955
}
56+
5057
inOrderTraverseNode(node, callback) {
5158
if (node != null) {
5259
this.inOrderTraverseNode(node.left, callback);
5360
callback(node.key);
5461
this.inOrderTraverseNode(node.right, callback);
5562
}
5663
}
64+
5765
preOrderTraverse(callback) {
5866
this.preOrderTraverseNode(this.root, callback);
5967
}
68+
6069
preOrderTraverseNode(node, callback) {
6170
if (node != null) {
6271
callback(node.key);
6372
this.preOrderTraverseNode(node.left, callback);
6473
this.preOrderTraverseNode(node.right, callback);
6574
}
6675
}
76+
6777
postOrderTraverse(callback) {
6878
this.postOrderTraverseNode(this.root, callback);
6979
}
80+
7081
postOrderTraverseNode(node, callback) {
7182
if (node != null) {
7283
this.postOrderTraverseNode(node.left, callback);
7384
this.postOrderTraverseNode(node.right, callback);
7485
callback(node.key);
7586
}
7687
}
88+
7789
min() {
7890
return this.minNode(this.root);
7991
}
92+
8093
minNode(node) {
8194
let current = node;
8295
while (current != null && current.left != null) {
8396
current = current.left;
8497
}
8598
return current;
8699
}
100+
87101
max() {
88102
return this.maxNode(this.root);
89103
}
104+
90105
maxNode(node) {
91106
let current = node;
92107
while (current != null && current.right != null) {
93108
current = current.right;
94109
}
95110
return current;
96111
}
112+
97113
remove(key) {
98114
this.root = this.removeNode(this.root, key);
99115
}
116+
100117
removeNode(node, key) {
101118
if (node == null) {
102119
return undefined;
103120
}
104121
if (this.compareFn(key, node.key) === Compare.LESS_THAN) {
105122
node.left = this.removeNode(node.left, key);
106123
return node;
107-
} else if (this.compareFn(key, node.key) === Compare.BIGGER_THAN) {
124+
} if (this.compareFn(key, node.key) === Compare.BIGGER_THAN) {
108125
node.right = this.removeNode(node.right, key);
109126
return node;
110127
}
@@ -122,7 +139,7 @@ export default class BinarySearchTree {
122139
if (node.left == null) {
123140
node = node.right;
124141
return node;
125-
} else if (node.right == null) {
142+
} if (node.right == null) {
126143
node = node.left;
127144
return node;
128145
}

src/js/data-structures/circular-linked-list.js

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default class CircularLinkedList extends LinkedList {
66
constructor(equalsFn = defaultEquals) {
77
super(equalsFn);
88
}
9+
910
push(element) {
1011
const node = new Node(element);
1112
let current;
@@ -19,6 +20,7 @@ export default class CircularLinkedList extends LinkedList {
1920
node.next = this.head;
2021
this.count++;
2122
}
23+
2224
insert(element, index) {
2325
if (index >= 0 && index <= this.count) {
2426
const node = new Node(element);
@@ -45,6 +47,7 @@ export default class CircularLinkedList extends LinkedList {
4547
}
4648
return false;
4749
}
50+
4851
removeAt(index) {
4952
if (index >= 0 && index < this.count) {
5053
let current = this.head;

0 commit comments

Comments
 (0)