From 2483a0fb7eaa833276a41ffe79c0e5bfc8a36e49 Mon Sep 17 00:00:00 2001 From: Jon Duckworth Date: Mon, 20 Nov 2017 15:11:55 -0700 Subject: [PATCH 1/8] Remove jscs and jshint dependencies --- package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/package.json b/package.json index c84130d..7d3e73d 100644 --- a/package.json +++ b/package.json @@ -46,8 +46,6 @@ "concat-stream": "^1.4.6", "coveralls": "^2.10.0", "istanbul": "^0.4.2", - "jscs": "^3.0.4", - "jshint": "^2.8.0", "mocha": "^2.0.1", "sinon": "^1.10.2", "sinon-chai": "^2.8.0", From 796814f4a235b42a852fab66662a50f55f7fbc57 Mon Sep 17 00:00:00 2001 From: Jon Duckworth Date: Mon, 20 Nov 2017 15:18:28 -0700 Subject: [PATCH 2/8] Basic running install of eslint --- .eslintrc.yml | 1 + package.json | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 .eslintrc.yml diff --git a/.eslintrc.yml b/.eslintrc.yml new file mode 100644 index 0000000..36b7af3 --- /dev/null +++ b/.eslintrc.yml @@ -0,0 +1 @@ +extends: airbnb-base diff --git a/package.json b/package.json index 7d3e73d..bb66761 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,9 @@ "chai-as-promised": "^5.1.0", "concat-stream": "^1.4.6", "coveralls": "^2.10.0", + "eslint": "4.11.0", + "eslint-config-airbnb-base": "12.1.0", + "eslint-plugin-import": "2.8.0", "istanbul": "^0.4.2", "mocha": "^2.0.1", "sinon": "^1.10.2", From e28216895578fc56706c06d2c2e39f6229734c03 Mon Sep 17 00:00:00 2001 From: Jon Duckworth Date: Mon, 20 Nov 2017 16:51:51 -0700 Subject: [PATCH 3/8] Create eslint configs consistent with current project style --- .eslintrc-es6.yml | 10 ++++++ .eslintrc.yml | 78 ++++++++++++++++++++++++++++++++++++++++++++++- package.json | 4 +-- 3 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 .eslintrc-es6.yml diff --git a/.eslintrc-es6.yml b/.eslintrc-es6.yml new file mode 100644 index 0000000..25cb990 --- /dev/null +++ b/.eslintrc-es6.yml @@ -0,0 +1,10 @@ +env: + es6: false +rules: + prefer-arrow-callback: off + prefer-template: off + prefer-destructuring: off + import/no-unresolved: off + no-var: off + object-shorthand: off + prefer-rest-params: off diff --git a/.eslintrc.yml b/.eslintrc.yml index 36b7af3..06e1e59 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -1 +1,77 @@ -extends: airbnb-base +extends: + - airbnb-base + - ./.eslintrc-es6.yml +env: + node: true +parserOptions: + sourceType: script +rules: + curly: + - error + - all + no-undefined: error + strict: + - error + - global + comma-dangle: + - error + - always-multiline + no-mixed-spaces-and-tabs: + - error + - smart-tabs + no-empty: off + func-style: + - error + - expression + keyword-spacing: + - error + - overrides: + function: + after: false + no-multiple-empty-lines: off + max-len: + - error + - 80 + max-lines: + - error + - 1000 + padding-line-between-statements: + - error + - blankLine: always + prev: '*' + next: export + - blankLine: always + prev: directive + next: '*' + consistent-this: + - error + - self + space-before-function-paren: + - error + - never + valid-jsdoc: error + func-names: off + consistent-return: off + no-console: off + indent: + - error + - 2 + - MemberExpression: 0 + CallExpression: + arguments: off + FunctionExpression: + parameters: off + function-paren-newline: off + one-var: off + padded-blocks: off + global-require: off + no-underscore-dangle: off + vars-on-top: off + no-param-reassign: off + one-var-declaration-per-line: off + no-return-assign: off + no-mixed-operators: off + brace-style: off + wrap-iife: + - error + - inside diff --git a/package.json b/package.json index bb66761..e82fc94 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "avn": "./bin-public/avn" }, "scripts": { - "test": "jshint . && jscs . && istanbul cover node_modules/.bin/_mocha --report html --", - "test-travis": "jshint . && jscs . && istanbul cover node_modules/.bin/_mocha --report lcovonly --" + "test": "eslint lib && istanbul cover node_modules/.bin/_mocha --report html --", + "test-travis": "eslint lib && istanbul cover node_modules/.bin/_mocha --report lcovonly --" }, "repository": { "type": "git", From 12bd7484d06947eb94d4bbdcecfa2c59e06552d0 Mon Sep 17 00:00:00 2001 From: Jon Duckworth Date: Tue, 21 Nov 2017 10:19:51 -0700 Subject: [PATCH 4/8] Add npm-debug.log to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7bbe1a3..b092af1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +npm-debug.log /node_modules /coverage From 60f82a8a2fc0f2dfc6e51e80da9b7d025ef4cc21 Mon Sep 17 00:00:00 2001 From: Jon Duckworth Date: Tue, 21 Nov 2017 10:20:05 -0700 Subject: [PATCH 5/8] Clean up JSDocs lint errors --- lib/fmt.js | 8 ++++---- lib/hooks.js | 4 ++-- lib/plugins.js | 4 ++-- lib/setup.js | 2 +- lib/setup/config.js | 2 +- lib/setup/install.js | 14 +++++++++----- lib/setup/plugins.js | 5 +++-- lib/setup/profile.js | 10 ++++++---- lib/util/codes.js | 3 ++- 9 files changed, 30 insertions(+), 22 deletions(-) diff --git a/lib/fmt.js b/lib/fmt.js index c6c5bfc..c694255 100644 --- a/lib/fmt.js +++ b/lib/fmt.js @@ -12,7 +12,7 @@ var chalk = require('chalk'); * @param {String} result The exact version number that was activated * @param {String} via The file that triggered the activation. Only supply * this if the file is not `./.node-version`. - * @return {String} + * @return {String} The formatted string to be displayed on success. */ exports.success = function(version, result, via) { return util.format(chalk.bold.magenta('avn') + @@ -29,7 +29,7 @@ exports.success = function(version, result, via) { * @private * @function fmt.~errorDetail * @param {Error} error The error for which to build a string. - * @return {String} + * @return {String} The formatted string to be displayed on error. */ var errorDetail = function(error) { return util.format(' %s: %s', @@ -43,10 +43,10 @@ var errorDetail = function(error) { * @private * @function fmt.failure * @param {String} version The requested version number to be activated - * @param {String} result The error that was generated while trying to + * @param {String} error The error that was generated while trying to * activate * @param {Boolean} verbose True if full error details should be included. - * @return {String} + * @return {String} The formatted string to be displayed on failure. */ exports.failure = function(version, error, verbose) { var message = util.format('%s %s', diff --git a/lib/hooks.js b/lib/hooks.js index 38eed5b..187fd95 100644 --- a/lib/hooks.js +++ b/lib/hooks.js @@ -19,7 +19,7 @@ var isNoEntry = require('./util/codes').isNoEntry; */ var match = function(version) { var result; - /** local */ + /* local */ var ensure = function(key) { return function(r) { if (r && !r[key]) { throw new Error('result missing ' + key); } @@ -38,7 +38,7 @@ var match = function(version) { }); }; -/** +/* * Hook for `chpwd` which is triggered after changing the current working * directory. * diff --git a/lib/plugins.js b/lib/plugins.js index 4d983d7..742c53c 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -22,7 +22,7 @@ exports.all = (function() { }; })(); -/** +/* * Helper for getting all installed plugins. * * This uses the `plugins` property from the configuration file, `~/.avnrc` to @@ -99,7 +99,7 @@ exports.first = function(predicate) { }); }; -/** +/* * Rethrow when the error is not for a failed `require`. * * @private diff --git a/lib/setup.js b/lib/setup.js index 72e4d1b..0e8cd17 100644 --- a/lib/setup.js +++ b/lib/setup.js @@ -9,7 +9,7 @@ var chalk = require('chalk'); * * @private * @function setup - * @return {Promise} + * @return {Promise} Promise that resolves when all setup scripts are complete. */ module.exports = function() { return Promise.all([ diff --git a/lib/setup/config.js b/lib/setup/config.js index eaaa229..5aafd6e 100644 --- a/lib/setup/config.js +++ b/lib/setup/config.js @@ -7,7 +7,7 @@ var chalk = require('chalk'); var installedPlugins = require('./plugins').installed; var isNoEntry = require('../util/codes').isNoEntry; -/** +/* * Update `~/.avnrc` configuration file. * * This locates all installed plugins and uses them to create a configuration diff --git a/lib/setup/install.js b/lib/setup/install.js index c398e55..19afef6 100644 --- a/lib/setup/install.js +++ b/lib/setup/install.js @@ -15,7 +15,7 @@ var isNoEntry = require('../util/codes').isNoEntry; * @private * @function setup.install.~moduleVersion * @param {String} module The path to the module. - * @return {Promise} + * @return {Promise} Promise that resolves to version number. */ var moduleVersion = function(module) { return fs.readFile(path.join(module, 'package.json'), 'utf8') @@ -32,7 +32,8 @@ var moduleVersion = function(module) { * @function setup.install.~install * @param {String} src The source location. * @param {String} dst The destination location. - * @return {Promise} + * @return {Promise} Promise that resolves to a string indicating if the / + * module was updated or complete. */ var install = function(src, dst) { var srcVersion, dstVersion; @@ -63,7 +64,8 @@ var install = function(src, dst) { * * @private * @function setup.install.~avn - * @return {Promise} + * @return {Promise} Promise that resolves when install avn setup is complete / + * and indicates if any action took place. */ var avn = function() { var src = path.resolve(path.join(__dirname, '../..')) + '/'; @@ -81,7 +83,8 @@ var avn = function() { * * @private * @function setup.install.~plugins - * @return {Promise} + * @return {Promise} Promise that resolves when plugin installation is / + * complete and indicates if any action took place. */ var plugins = function() { return installedPlugins().then(function(plugins) { @@ -104,7 +107,8 @@ var plugins = function() { * * @private * @function setup.install.all - * @return {Promise} + * @return {Promise} Promise that resolves when avn and plugins have been / + * installed. * @see {@link plugins.~all} */ module.exports.all = function() { diff --git a/lib/setup/plugins.js b/lib/setup/plugins.js index 006d118..cb8c990 100644 --- a/lib/setup/plugins.js +++ b/lib/setup/plugins.js @@ -10,7 +10,7 @@ var path = require('path'); * * @private * @function setup.plugins.~modules - * @return {Promise} + * @return {Promise} Promise that resolves to a list of plugins. */ var modules = function() { return Promise.resolve() @@ -31,7 +31,8 @@ var modules = function() { * * @private * @function setup.plugins.installed - * @return {Promise} + * @return {Promise} Promise that resolves to a list of globally installed / + * plugins. */ module.exports.installed = function() { return Promise.resolve() diff --git a/lib/setup/profile.js b/lib/setup/profile.js index aed6980..667f7ef 100644 --- a/lib/setup/profile.js +++ b/lib/setup/profile.js @@ -13,7 +13,7 @@ var isNoEntry = require('../util/codes').isNoEntry; * * @private * @function setup.profile.~script - * @return {String} + * @return {String} The string to be included in the init script. */ var script = function() { var script = '$HOME/.avn/bin/avn.sh'; @@ -28,9 +28,10 @@ var script = function() { * @private * @function setup.profile.~appendScript * @param {String} name The name of the profile file. - * @param {Object} [options] + * @param {Object} options Additional function options (see below). * @param {Boolean} [options.force] Force the creation of the file. - * @return {Promise} + * @return {Promise} Promise that resolves when the profile file has been / + * updated. */ var appendScript = function(name, options) { var opts = options || {}; @@ -72,7 +73,8 @@ var appendScript = function(name, options) { * * @private * @function setup.profile.update - * @return {Promise} + * @return {Promise} Promise that resolves when the ~/.bash_profile file has / + * been updated. */ module.exports.update = function() { var handled = false; diff --git a/lib/util/codes.js b/lib/util/codes.js index 44eed8b..b3d033f 100644 --- a/lib/util/codes.js +++ b/lib/util/codes.js @@ -5,6 +5,7 @@ * * @private * @function hooks.isNoEntry - * @param {Error} error The error to check. + * @param {Error} e The error to check. + * @return {Boolean} Whether the error code is `ENOENT`. */ exports.isNoEntry = function(e) { return e.code === 'ENOENT'; }; From 55dcbe989d8630fed665764ba09855a85a52bc3e Mon Sep 17 00:00:00 2001 From: Jon Duckworth Date: Tue, 21 Nov 2017 10:26:14 -0700 Subject: [PATCH 6/8] Clean up style-related lint errors --- lib/hooks.js | 2 +- lib/plugins.js | 3 +++ lib/setup.js | 7 ++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/hooks.js b/lib/hooks.js index 187fd95..595a211 100644 --- a/lib/hooks.js +++ b/lib/hooks.js @@ -59,7 +59,7 @@ var match = function(version) { * @param {Boolean} [options.verbose] Enable verbose output. * @return {Promise} */ -exports.chpwd = function(/*dir, [versionFile], [options]*/) { +exports.chpwd = function(/* dir, [versionFile], [options] */) { var args = Array.prototype.slice.call(arguments, 0); var dir = args.shift(); var file = _.isString(args[0]) && args.shift() || '.node-version'; diff --git a/lib/plugins.js b/lib/plugins.js index 742c53c..238ff47 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -1,9 +1,12 @@ +/* eslint-disable import/no-dynamic-require */ + 'use strict'; var _ = require('lodash'); var Promise = require('bluebird'); var path = require('path'); var fs = require('mz/fs'); +// eslint-disable-next-line import/newline-after-import var isNoEntry = require('./util/codes').isNoEntry; var rethrowUnlessFailedRequire; diff --git a/lib/setup.js b/lib/setup.js index 0e8cd17..c9a388a 100644 --- a/lib/setup.js +++ b/lib/setup.js @@ -19,9 +19,10 @@ module.exports = function() { ]) .then(function(results) { var errors = _(results) - .filter(_.method('isRejected')) - .map(_.method('reason')) - .map('message').value(); + .filter(_.method('isRejected')) + .map(_.method('reason')) + .map('message') + .value(); if (errors.length) { console.error('%s: %s', chalk.bold.red('error'), errors.join(', ')); From c28f3da53b321316ff956afb262bfce82982cf32 Mon Sep 17 00:00:00 2001 From: Jon Duckworth Date: Tue, 21 Nov 2017 10:28:54 -0700 Subject: [PATCH 7/8] Clean up shadowed variables --- lib/setup/install.js | 4 ++-- lib/setup/plugins.js | 10 +++++----- lib/setup/profile.js | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/setup/install.js b/lib/setup/install.js index 19afef6..ac96b52 100644 --- a/lib/setup/install.js +++ b/lib/setup/install.js @@ -87,8 +87,8 @@ var avn = function() { * complete and indicates if any action took place. */ var plugins = function() { - return installedPlugins().then(function(plugins) { - return Promise.all(plugins.map(function(plugin) { + return installedPlugins().then(function(_plugins) { + return Promise.all(_plugins.map(function(plugin) { var src = plugin.path + '/'; var dst = path.join(process.env.HOME, path.join('.avn/plugins', plugin.moduleName)); diff --git a/lib/setup/plugins.js b/lib/setup/plugins.js index cb8c990..18505a1 100644 --- a/lib/setup/plugins.js +++ b/lib/setup/plugins.js @@ -15,11 +15,11 @@ var path = require('path'); var modules = function() { return Promise.resolve() .then(function() { return npm.loadAsync(); }) - .then(function(npm) { - npm.config.set('spin', false); - npm.config.set('global', true); - npm.config.set('depth', 0); - return Promise.promisify(npm.commands.list)([], true); + .then(function(_npm) { + _npm.config.set('spin', false); + _npm.config.set('global', true); + _npm.config.set('depth', 0); + return Promise.promisify(_npm.commands.list)([], true); }) .then(function(data) { return data; }); }; diff --git a/lib/setup/profile.js b/lib/setup/profile.js index 667f7ef..6b280b4 100644 --- a/lib/setup/profile.js +++ b/lib/setup/profile.js @@ -16,9 +16,9 @@ var isNoEntry = require('../util/codes').isNoEntry; * @return {String} The string to be included in the init script. */ var script = function() { - var script = '$HOME/.avn/bin/avn.sh'; + var _script = '$HOME/.avn/bin/avn.sh'; return util.format('[[ -s "%s" ]] && source "%s" # load avn\n', - script, script); + _script, _script); }; /** From 3cde23a9aed58a66b28d2b75e1febf033fa83a57 Mon Sep 17 00:00:00 2001 From: Jon Duckworth Date: Tue, 21 Nov 2017 12:47:25 -0700 Subject: [PATCH 8/8] Use .eslintrc files instead of .yml for eslint configs --- .eslintrc | 70 ++++++++++++++++++++++++++++++++++++++++++ .eslintrc-es6 | 15 +++++++++ .eslintrc-es6.yml | 10 ------ .eslintrc.yml | 77 ----------------------------------------------- 4 files changed, 85 insertions(+), 87 deletions(-) create mode 100644 .eslintrc create mode 100644 .eslintrc-es6 delete mode 100644 .eslintrc-es6.yml delete mode 100644 .eslintrc.yml diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..068cae7 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,70 @@ +{ + "env": { + "node": true + }, + + "extends": [ + "airbnb-base", + "./.eslintrc-es6" + ], + + "parserOptions": { + "sourceType": "script" + }, + + "rules": { + "curly": ["error", "all"], + "no-undefined": "error", + "strict": ["error", "global"], + "comma-dangle": ["error", "always-multiline"], + "no-mixed-spaces-and-tabs": ["error", "smart-tabs"], + "no-empty": "off", + "func-style": ["error", "expression"], + "keyword-spacing": ["error", { + "overrides": { + "function": { + "after": false + } + } + }], + "no-multiple-empty-lines": "off", + "max-len": ["error", 80], + "max-lines": ["error", 1000], + "padding-line-between-statements": ["error", { + "blankLine": "always", + "prev": "*", + "next": "export" + }, { + "blankLine": "always", + "prev": "directive", + "next": "*" + }], + "consistent-this": ["error", "self"], + "space-before-function-paren": ["error", "never"], + "valid-jsdoc": "error", + "func-names": "off", + "consistent-return": "off", + "no-console": "off", + "indent": ["error", 2, { + "MemberExpression": 0, + "CallExpression": { + "arguments": "off" + }, + "FunctionExpression": { + "parameters": "off" + } + }], + "function-paren-newline": "off", + "one-var": "off", + "padded-blocks": "off", + "global-require": "off", + "no-underscore-dangle": "off", + "vars-on-top": "off", + "no-param-reassign": "off", + "one-var-declaration-per-line": "off", + "no-return-assign": "off", + "no-mixed-operators": "off", + "brace-style": "off", + "wrap-iife": ["error", "inside"] + } +} diff --git a/.eslintrc-es6 b/.eslintrc-es6 new file mode 100644 index 0000000..d6a8133 --- /dev/null +++ b/.eslintrc-es6 @@ -0,0 +1,15 @@ +{ + "env": { + "es6": "off" + }, + + "rules": { + "prefer-arrow-callback": "off", + "prefer-template": "off", + "prefer-destructuring": "off", + "import/no-unresolved": "off", + "no-var": "off", + "object-shorthand": "off", + "prefer-rest-params": "off" + } +} diff --git a/.eslintrc-es6.yml b/.eslintrc-es6.yml deleted file mode 100644 index 25cb990..0000000 --- a/.eslintrc-es6.yml +++ /dev/null @@ -1,10 +0,0 @@ -env: - es6: false -rules: - prefer-arrow-callback: off - prefer-template: off - prefer-destructuring: off - import/no-unresolved: off - no-var: off - object-shorthand: off - prefer-rest-params: off diff --git a/.eslintrc.yml b/.eslintrc.yml deleted file mode 100644 index 06e1e59..0000000 --- a/.eslintrc.yml +++ /dev/null @@ -1,77 +0,0 @@ -extends: - - airbnb-base - - ./.eslintrc-es6.yml -env: - node: true -parserOptions: - sourceType: script -rules: - curly: - - error - - all - no-undefined: error - strict: - - error - - global - comma-dangle: - - error - - always-multiline - no-mixed-spaces-and-tabs: - - error - - smart-tabs - no-empty: off - func-style: - - error - - expression - keyword-spacing: - - error - - overrides: - function: - after: false - no-multiple-empty-lines: off - max-len: - - error - - 80 - max-lines: - - error - - 1000 - padding-line-between-statements: - - error - - blankLine: always - prev: '*' - next: export - - blankLine: always - prev: directive - next: '*' - consistent-this: - - error - - self - space-before-function-paren: - - error - - never - valid-jsdoc: error - func-names: off - consistent-return: off - no-console: off - indent: - - error - - 2 - - MemberExpression: 0 - CallExpression: - arguments: off - FunctionExpression: - parameters: off - function-paren-newline: off - one-var: off - padded-blocks: off - global-require: off - no-underscore-dangle: off - vars-on-top: off - no-param-reassign: off - one-var-declaration-per-line: off - no-return-assign: off - no-mixed-operators: off - brace-style: off - wrap-iife: - - error - - inside