diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..a6c57f5f --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +*.json diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 00000000..17350214 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,34 @@ +{ + "env": { + "node": true, + "browser": true, + "mocha": true, + "commonjs": true + }, + + "extends": "eslint:recommended", + + "rules": { + "indent": [ + "error", + 4, + { SwitchCase: 1 } + ], + "linebreak-style": [ + "error", + "unix" + ], + "quotes": [ + "error", + "single" + ], + "semi": [ + "error", + "always" + ], + "strict": 2, + "no-unused-vars": 2, + "no-cond-assign": 2, + "camelcase": 1 + } +} diff --git a/.npmignore b/.npmignore index 9daeafb9..8cd94105 100644 --- a/.npmignore +++ b/.npmignore @@ -1 +1,2 @@ test +.eslint* diff --git a/lib/html-to-dom-client.js b/lib/html-to-dom-client.js index 2ead30e0..f6ed615d 100644 --- a/lib/html-to-dom-client.js +++ b/lib/html-to-dom-client.js @@ -43,7 +43,8 @@ function formatDOM(nodes, parentNode) { }; // set the next node for the previous node (if applicable) - if (prevNode = result[i - 1]) { + prevNode = result[i - 1]; + if (prevNode) { prevNode.next = nodeObj; } diff --git a/package.json b/package.json index 01f90ff1..a812919b 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "author": "Mark ", "main": "index.js", "scripts": { - "test": "mocha" + "test": "mocha", + "lint": "eslint index.js \"lib/**\" \"test/**\"" }, "repository": { "type": "git", @@ -26,6 +27,7 @@ "htmlparser2": "^3.9.1" }, "devDependencies": { + "eslint": "^3.3.1", "jsdomify": "^2.1.0", "mocha": "^3.0.2", "react": "^15.3.0", diff --git a/test/helpers.js b/test/helpers.js index ac21dba0..aa766877 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -30,9 +30,9 @@ describe('test helper', function() { var obj1; var obj2; - var obj1 = { foo: 'bar', baz: ['qux', 42, null], obj: {} }; + obj1 = { foo: 'bar', baz: ['qux', 42, null], obj: {} }; obj1.ref = obj1.obj; - var obj2 = { obj: {}, baz: ['qux', 42, null], foo: 'bar' }; + obj2 = { obj: {}, baz: ['qux', 42, null], foo: 'bar' }; obj2.ref = obj2.obj; deepEqualCircular(obj1, obj2); }); diff --git a/test/helpers/index.js b/test/helpers/index.js index d9905bea..e6cd4ba8 100644 --- a/test/helpers/index.js +++ b/test/helpers/index.js @@ -4,6 +4,7 @@ * Module dependencies. */ var assert = require('assert'); +var util = require('util'); /** * Test for deep equality between objects that have circular references. diff --git a/test/utilities.js b/test/utilities.js index 52c45387..c19bca18 100644 --- a/test/utilities.js +++ b/test/utilities.js @@ -30,7 +30,7 @@ describe('utilties', function() { [undefined, null, 1337, {}, []].forEach(function(parameter) { assert.throws(function() { camelCase(parameter); }); }); - }) + }); }); describe('`invertObject` helper', function() { @@ -40,7 +40,7 @@ describe('utilties', function() { [undefined, null, 'foo', 1337].forEach(function(parameter) { assert.throws(function() { invertObject(parameter); }); }); - }) + }); it('swaps key with value for object', function() { assert.deepEqual( @@ -67,7 +67,7 @@ describe('utilties', function() { it('uses override if valid', function() { assert.deepEqual( - invertObject({ foo: 'bar', baz: 'qux' }, function(key, value) { + invertObject({ foo: 'bar', baz: 'qux' }, function(key) { if (key === 'foo') { return ['key', 'value']; } @@ -78,7 +78,7 @@ describe('utilties', function() { it('does not use override if invalid', function() { assert.deepEqual( - invertObject({ foo: 'bar', baz: 'qux' }, function(key, value) { + invertObject({ foo: 'bar', baz: 'qux' }, function(key) { if (key === 'foo') { return ['key']; } else if (key === 'baz') {