From ca10d0eaf80fc60ed8bb9b1ae1ada2a2c670c545 Mon Sep 17 00:00:00 2001 From: Matt Hamann Date: Sat, 21 Oct 2017 16:01:01 -0400 Subject: [PATCH] Add basic linting rules --- .eslintignore | 2 ++ .eslintrc.json | 8 ++++++++ .gitignore | 3 ++- lib/nconf.js | 3 +-- lib/nconf/provider.js | 1 - lib/nconf/stores/file.js | 17 +++++++---------- package.json | 4 +++- test/common-test.js | 1 - test/complete-test.js | 1 - .../scripts/nconf-hierarchical-load-save.js | 3 +-- test/helpers.js | 1 - test/hierarchy-test.js | 4 +++- test/nconf-test.js | 3 +-- test/provider-test.js | 1 - test/stores/argv-test.js | 1 - test/stores/env-test.js | 1 - test/stores/literal-test.js | 1 - 17 files changed, 28 insertions(+), 27 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc.json diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..512b8b5 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +node_modules +usage.js diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..be3757b --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,8 @@ +{ + "env": { + "node": true + }, + "rules": { + "no-unused-vars": "error" + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index af1c85e..4c0e4c7 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ test/fixtures/*.json node_modules/ node_modules/* npm-debug.log -coverage \ No newline at end of file +coverage +package-lock.json diff --git a/lib/nconf.js b/lib/nconf.js index 09d6848..26f6286 100644 --- a/lib/nconf.js +++ b/lib/nconf.js @@ -5,8 +5,7 @@ * */ -var async = require('async'), - common = require('./nconf/common'), +var common = require('./nconf/common'), Provider = require('./nconf/provider').Provider; // diff --git a/lib/nconf/provider.js b/lib/nconf/provider.js index 5e39e38..3f766e2 100644 --- a/lib/nconf/provider.js +++ b/lib/nconf/provider.js @@ -91,7 +91,6 @@ Provider.prototype.file = function (key, options) { // Provider.prototype.use = function (name, options) { options = options || {}; - var type = options.type || name; function sameOptions (store) { return Object.keys(options).every(function (key) { diff --git a/lib/nconf/stores/file.js b/lib/nconf/stores/file.js index b79df1c..10d98a1 100644 --- a/lib/nconf/stores/file.js +++ b/lib/nconf/stores/file.js @@ -10,8 +10,9 @@ var fs = require('fs'), util = require('util'), Secure = require('secure-keys'), formats = require('../formats'), - Memory = require('./memory').Memory, - exists = fs.exists || path.exists, + Memory = require('./memory').Memory; + +var exists = fs.exists || path.exists, existsSync = fs.existsSync || path.existsSync; // @@ -22,7 +23,7 @@ var fs = require('fs'), // var File = exports.File = function (options) { if (!options || !options.file) { - throw new Error ('Missing required option `file`'); + throw new Error('Missing required option `file`'); } Memory.call(this, options); @@ -83,12 +84,10 @@ File.prototype.save = function (value, callback) { // // ### function saveSync (value, callback) -// #### @value {Object} _Ignored_ Left here for consistency -// #### @callback {function} **Optional** Continuation to respond to when complete. // Saves the current configuration object to disk at `this.file` // using the format specified by `this.format` synchronously. // -File.prototype.saveSync = function (value) { +File.prototype.saveSync = function () { fs.writeFileSync(this.file, this.stringify()); return this.store; }; @@ -168,8 +167,7 @@ File.prototype.loadSync = function () { // `this.secure` is enabled // File.prototype.stringify = function () { - var data = this.store, - self = this; + var data = this.store; if (this.secure) { data = this.keys.encrypt(data); @@ -184,8 +182,7 @@ File.prototype.stringify = function () { // `this.secure` is enabled. // File.prototype.parse = function (contents) { - var parsed = this.format.parse(contents), - self = this; + var parsed = this.format.parse(contents); if (!this.secure) { return parsed; diff --git a/package.json b/package.json index e7233c2..c1c98ee 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ }, "devDependencies": { "coveralls": "^2.11.4", + "eslint": "^4.9.0", "istanbul": "^0.4.1", "vows": "0.8.x" }, @@ -27,7 +28,8 @@ "scripts": { "test": "vows test/*-test.js test/**/*-test.js --spec", "cover": "istanbul cover vows -- test/*-test.js test/**/*-test.js --spec", - "coveralls": "cat coverage/lcov.info | coveralls" + "coveralls": "cat coverage/lcov.info | coveralls", + "lint": "eslint ." }, "engines": { "node": ">= 0.4.0" diff --git a/test/common-test.js b/test/common-test.js index d50c267..4f0a3fb 100644 --- a/test/common-test.js +++ b/test/common-test.js @@ -8,7 +8,6 @@ var fs = require('fs'), path = require('path'), vows = require('vows'), - assert = require('assert'), helpers = require('./helpers'), nconf = require('../lib/nconf'); diff --git a/test/complete-test.js b/test/complete-test.js index 88f0374..b6d86c0 100644 --- a/test/complete-test.js +++ b/test/complete-test.js @@ -6,7 +6,6 @@ */ var fs = require('fs'), - path = require('path'), vows = require('vows'), assert = require('assert'), nconf = require('../lib/nconf'), diff --git a/test/fixtures/scripts/nconf-hierarchical-load-save.js b/test/fixtures/scripts/nconf-hierarchical-load-save.js index 8b86847..5ac860b 100644 --- a/test/fixtures/scripts/nconf-hierarchical-load-save.js +++ b/test/fixtures/scripts/nconf-hierarchical-load-save.js @@ -5,8 +5,7 @@ * */ -var fs = require('fs'), - path = require('path'), +var path = require('path'), nconf = require('../../../lib/nconf'); // diff --git a/test/helpers.js b/test/helpers.js index b6e034d..8402ae7 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -7,7 +7,6 @@ var assert = require('assert'), spawn = require('child_process').spawn, - util = require('util'), fs = require('fs'), path = require('path'), nconf = require('../lib/nconf'); diff --git a/test/hierarchy-test.js b/test/hierarchy-test.js index d1c0030..de8dc4a 100644 --- a/test/hierarchy-test.js +++ b/test/hierarchy-test.js @@ -54,7 +54,9 @@ vows.describe('nconf/hierarchy').addBatch({ child; try { fs.unlinkSync(configFile) } - catch (ex) { } + catch (ex) { + // No-op + } child = spawn('node', [script].concat(argv)); diff --git a/test/nconf-test.js b/test/nconf-test.js index ba6c75c..94e6eff 100644 --- a/test/nconf-test.js +++ b/test/nconf-test.js @@ -9,8 +9,7 @@ var fs = require('fs'), path = require('path'), vows = require('vows'), assert = require('assert'), - nconf = require('../lib/nconf'), - data = require('./fixtures/data').data; + nconf = require('../lib/nconf') vows.describe('nconf').addBatch({ "When using the nconf": { diff --git a/test/provider-test.js b/test/provider-test.js index e9cd40a..091101a 100644 --- a/test/provider-test.js +++ b/test/provider-test.js @@ -8,7 +8,6 @@ var assert = require('assert'), fs = require('fs'), path = require('path'), - spawn = require('child_process').spawn, vows = require('vows'), helpers = require('./helpers'), nconf = require('../lib/nconf'); diff --git a/test/stores/argv-test.js b/test/stores/argv-test.js index a6f4bff..f90c833 100644 --- a/test/stores/argv-test.js +++ b/test/stores/argv-test.js @@ -7,7 +7,6 @@ var vows = require('vows'), assert = require('assert'), - helpers = require('../helpers'), nconf = require('../../lib/nconf'); vows.describe('nconf/stores/argv').addBatch({ diff --git a/test/stores/env-test.js b/test/stores/env-test.js index 8811af6..88c5f4e 100644 --- a/test/stores/env-test.js +++ b/test/stores/env-test.js @@ -7,7 +7,6 @@ var vows = require('vows'), assert = require('assert'), - helpers = require('../helpers'), nconf = require('../../lib/nconf'); vows.describe('nconf/stores/env').addBatch({ diff --git a/test/stores/literal-test.js b/test/stores/literal-test.js index 6de5c07..6c1e46e 100644 --- a/test/stores/literal-test.js +++ b/test/stores/literal-test.js @@ -7,7 +7,6 @@ var vows = require('vows'), assert = require('assert'), - helpers = require('../helpers'), nconf = require('../../lib/nconf'); vows.describe('nconf/stores/literal').addBatch({