Skip to content

Commit

Permalink
Use eslint for linting instead of an old version of jshint
Browse files Browse the repository at this point in the history
  • Loading branch information
felipernb committed Aug 4, 2015
1 parent 6d41da9 commit 1cb5b97
Show file tree
Hide file tree
Showing 31 changed files with 144 additions and 74 deletions.
91 changes: 91 additions & 0 deletions .eslintrc
@@ -0,0 +1,91 @@
{
"env": {
"jasmine": true,
"node": true,
"mocha": true,
"browser": true,
"builtin": true
},
"globals": {
"describe": false,
"it": false,
"before": false,
"beforeEach": false,
"after": false,
"afterEach": false,
"system": false,
"phantom": false
},
"rules": {
"block-scoped-var": 2,
"camelcase": 2,
"comma-style": [
2,
"last"
],
"curly": [
0,
"all"
],
"dot-notation": [
2,
{
"allowKeywords": true,
"allowPattern": "^[a-z]+(_[a-z]+)+$"
}
],
"eqeqeq": [
2,
"allow-null"
],
"strict": [
2,
"global"
],
"guard-for-in": 2,
"max-len": [
2,
80,
2
],
"new-cap": 2,
"no-caller": 2,
"no-cond-assign": [
2,
"except-parens"
],
"no-debugger": 2,
"no-empty": 2,
"no-eval": 2,
"no-extend-native": 2,
"no-extra-parens": 0,
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-loop-func": 2,
"no-multi-str": 2,
"no-new": 2,
"no-plusplus": 0,
"no-proto": 2,
"no-script-url": 2,
"no-sequences": 2,
"no-shadow": 0,
"no-undef": 2,
"no-underscore-dangle": 0,
"no-unused-vars": 2,
"no-use-before-define": 0,
"no-with": 2,
"quotes": [
2,
"single"
],
"semi": [
0,
"never"
],
"valid-typeof": 2,
"wrap-iife": [
2,
"inside"
]
}
}
25 changes: 0 additions & 25 deletions .jshintrc

This file was deleted.

8 changes: 4 additions & 4 deletions Makefile
@@ -1,4 +1,4 @@
all: jshint coverage
all: lint coverage

setup:
npm install
Expand All @@ -13,10 +13,10 @@ dist: all
cp README.md _build
cp CHANGELOG _build

jshint: setup
jshint src
lint: setup
eslint src

test: jshint
test: lint
mocha -R spec --recursive src/test

coverage: setup
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -9,8 +9,8 @@
"dependencies": {},
"devDependencies": {
"coveralls": "^2.11.2",
"eslint": "^1.0.0",
"istanbul": "^0.3.5",
"jshint": "~2.4.4",
"mocha": "^2.1.0"
},
"repository": {
Expand Down
6 changes: 3 additions & 3 deletions src/algorithms/graph/SPFA.js
Expand Up @@ -8,7 +8,7 @@
* @param {string} start the starting node
*
*/
function SPFA(graph, s) {
function spfa(graph, s) {
var distance = {};
var previous = {};
var queue = {};
Expand All @@ -30,7 +30,7 @@ function SPFA(graph, s) {
});

var currNode;
while (head != tail) {
while (head !== tail) {
currNode = queue[head++];
isInQue[currNode] = false;
var neighbors = graph.neighbors(currNode);
Expand Down Expand Up @@ -61,4 +61,4 @@ function SPFA(graph, s) {
};
}

module.exports = SPFA;
module.exports = spfa;
2 changes: 1 addition & 1 deletion src/algorithms/graph/bellman_ford.js
Expand Up @@ -61,7 +61,7 @@ var bellmanFord = function (graph, startNode) {
}

// If the loop did not break early, then there is a negative-weighted cycle.
if (iteration == adjacencyListSize) {
if (iteration === adjacencyListSize) {
// Empty 'distance' object indicates Negative-Weighted Cycle
return {
distance: {}
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/graph/breadth_first_search.js
Expand Up @@ -41,7 +41,7 @@ var normalizeCallbacks = function (callbacks, seenVertices) {
return false;
}
};
}());
})();

var noop = function () {};
callbacks.onTraversal = callbacks.onTraversal || noop;
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/graph/depth_first_search.js
Expand Up @@ -41,7 +41,7 @@ var normalizeCallbacks = function (callbacks, seenVertices) {
}
return false;
};
}());
})();

var noop = function () {};
callbacks.beforeTraversal = callbacks.beforeTraversal || noop;
Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/graph/euler_path.js
Expand Up @@ -48,12 +48,12 @@ var eulerEndpoints = function (graph) {
var start, finish, v;

graph.vertices.forEach(function (vertex) {
if (rank[vertex] == 1) {
if (rank[vertex] === 1) {
if (start) {
throw new Error('Duplicate start vertex.');
}
start = vertex;
} else if (rank[vertex] == -1) {
} else if (rank[vertex] === -1) {
if (finish) {
throw new Error('Duplicate finish vertex.');
}
Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/graph/floyd_warshall.js
Expand Up @@ -72,7 +72,7 @@ var floydWarshall = function (graph) {

var path = [src];

if (src != dest) {
if (src !== dest) {
(function pushInOrder(src, dest) {
if (middleVertex[src][dest] === undefined) {
path.push(dest);
Expand All @@ -81,7 +81,7 @@ var floydWarshall = function (graph) {
pushInOrder(src, middle);
pushInOrder(middle, dest);
}
}(src, dest));
})(src, dest);
}

return path;
Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/graph/prim.js
Expand Up @@ -25,7 +25,7 @@ var prim = function (graph) {
q.insert(vertex, Infinity);
});

var relax = function (neighbor) {
var relax = function (vertex, neighbor) {
var weight = graph.edge(vertex, neighbor);
if (weight < q.priority(neighbor)) {
q.changePriority(neighbor, weight);
Expand All @@ -45,7 +45,7 @@ var prim = function (graph) {
mst.addVertex(vertex);
}

graph.neighbors(vertex).forEach(relax);
graph.neighbors(vertex).forEach(relax.bind(null, vertex));
}

return mst;
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/math/fast_power.js
Expand Up @@ -22,7 +22,7 @@ var fastPower = function (base, power, mul, identity) {
mul = multiplicationOperator;
identity = 1;
}
if (power < 0 || Math.floor(power) != power) {
if (power < 0 || Math.floor(power) !== power) {
throw new Error('Power must be a positive integer or zero.');
}

Expand Down
3 changes: 2 additions & 1 deletion src/algorithms/math/gcd.js
Expand Up @@ -43,9 +43,10 @@ var gcdBinaryIterative = function (a, b) {
return a;
}

var shift;
// Let shift = log(K), where K is the greatest power of 2
// dividing both a and b
for (var shift = 0; ((a | b) & 1) === 0; ++shift) {
for (shift = 0; ((a | b) & 1) === 0; ++shift) {
a >>= 1;
b >>= 1;
}
Expand Down
9 changes: 4 additions & 5 deletions src/algorithms/math/power_set.js
Expand Up @@ -15,8 +15,9 @@ var powerSetIterative = function (array) {

var powerSet = [];
var cache = [];
var i;

for (var i = 0; i < array.length; i++) {
for (i = 0; i < array.length; i++) {
cache[i] = true;
}

Expand Down Expand Up @@ -46,11 +47,9 @@ var powerSetIterative = function (array) {
var powerSetRecursive = function (array) {
if (array.length === 0) {
return [];
}
else if (array.length == 1) {
} else if (array.length === 1) {
return [ [], [ array[0] ] ];
}
else {
} else {
var powerSet = [];
var firstElem = array[0];

Expand Down
3 changes: 2 additions & 1 deletion src/algorithms/sorting/counting_sort.js
Expand Up @@ -15,8 +15,9 @@ var countingSort = function (array) {
var max = maximumKey(array);
var auxiliaryArray = [];
var length = array.length;
var i;

for (var i = 0; i < length; i++) {
for (i = 0; i < length; i++) {
var position = array[i].key;

if (auxiliaryArray[position] === undefined) {
Expand Down
3 changes: 2 additions & 1 deletion src/algorithms/sorting/radix_sort.js
Expand Up @@ -40,8 +40,9 @@ var radixSort = function (array) {
var auxiliaryCountingSort = function (array, mod) {
var length = array.length;
var bucket = [];
var i;

for (var i = 0; i < 10; i++) {
for (i = 0; i < 10; i++) {
bucket[i] = [];
}

Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/sorting/selection_sort.js
Expand Up @@ -13,7 +13,7 @@ var selectionSort = function (a, comparatorFn) {
min = j;
}
}
if (min != i) {
if (min !== i) {
var tmp = a[i];
a[i] = a[min];
a[min] = tmp;
Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/string/hamming.js
Expand Up @@ -9,14 +9,14 @@
'use strict';

var hamming = function (a, b) {
if (a.length != b.length) {
if (a.length !== b.length) {
throw new Error('Strings must be equal in length');
}

var dist = 0;

for (var i = 0; i < a.length; i++) {
if (a[i] != b[i]) {
if (a[i] !== b[i]) {
dist++;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/algorithms/string/huffman.js
Expand Up @@ -26,7 +26,7 @@ var compress = function (string) {
currentBlock = (currentBlock << 1) | char;
currentBlockSize += 1;

if (currentBlockSize == MAX_BLOCK_SIZE) {
if (currentBlockSize === MAX_BLOCK_SIZE) {
blocks.push(currentBlock);
currentBlock = currentBlockSize = 0;
}
Expand Down Expand Up @@ -54,7 +54,7 @@ var decompress = function (array) {
if (!array.length) {
return '';
}
else if (array.length == 1) {
else if (array.length === 1) {
throw new Error('Compressed array must be either empty ' +
'or at least 2 blocks big.');
}
Expand Down Expand Up @@ -145,7 +145,7 @@ huffman.encode = function (string, compressed) {
unroll(a);
unroll(b);
}
}(root));
})(root);

var encoding = letters.reduce(function (acc, letter) {
acc[letter.char] = letter.code.split('').reverse().join('');
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/string/levenshtein.js
Expand Up @@ -39,7 +39,7 @@ var levenshtein = function (a, b) {
editDistance[i - 1][j], // if we delete the char from a
editDistance[i][j - 1] // if we add the char from b
) +
(a[i - 1] != b[j - 1] ? 1 : 0);
(a[i - 1] !== b[j - 1] ? 1 : 0);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/string/longest_common_subsequence.js
Expand Up @@ -20,7 +20,7 @@ var longestCommonSubsequence = function (s1, s2) {
// Fill in the cache
for (i = 1; i <= s1.length; i++) {
for (j = 1; j <= s2.length; j++) {
if (s1[i - 1] == s2[j - 1]) {
if (s1[i - 1] === s2[j - 1]) {
cache[i][j] = cache[i - 1][j - 1] + 1;
} else {
cache[i][j] = Math.max(cache[i][j - 1], cache[i - 1][j]);
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/string/longest_common_substring.js
Expand Up @@ -23,7 +23,7 @@ var longestCommonSubstring = function (s1, s2) {
// Fill in the cache
for (i = 1; i <= s1.length; i++) {
for (j = 1; j <= s2.length; j++) {
if (s1[i - 1] == s2[j - 1]) {
if (s1[i - 1] === s2[j - 1]) {
cache[i][j] = cache[i - 1][j - 1] + 1;
if (cache[i][j] > lcsLength) {
lcsPosition.i = i;
Expand Down

0 comments on commit 1cb5b97

Please sign in to comment.