Skip to content
This repository was archived by the owner on Dec 6, 2023. It is now read-only.

[WIP] Eslint integration #70

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -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"]
}
}
15 changes: 15 additions & 0 deletions .eslintrc-es6
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"env": {
"es6": "off"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is a file named "es6" turning off the es6 env?

also, why is this a separate file at all, instead of just being in the root eslintrc?

},

"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"
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
npm-debug.log
/node_modules
/coverage
8 changes: 4 additions & 4 deletions lib/fmt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') +
Expand All @@ -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',
Expand All @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions lib/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand All @@ -38,7 +38,7 @@ var match = function(version) {
});
};

/**
/*
* Hook for `chpwd` which is triggered after changing the current working
* directory.
*
Expand All @@ -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';
Expand Down
7 changes: 5 additions & 2 deletions lib/plugins.js
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -22,7 +25,7 @@ exports.all = (function() {
};
})();

/**
/*
* Helper for getting all installed plugins.
*
* This uses the `plugins` property from the configuration file, `~/.avnrc` to
Expand Down Expand Up @@ -99,7 +102,7 @@ exports.first = function(predicate) {
});
};

/**
/*
* Rethrow when the error is not for a failed `require`.
*
* @private
Expand Down
9 changes: 5 additions & 4 deletions lib/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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(', '));
Expand Down
2 changes: 1 addition & 1 deletion lib/setup/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions lib/setup/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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;
Expand Down Expand Up @@ -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, '../..')) + '/';
Expand All @@ -81,11 +83,12 @@ 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) {
return Promise.all(plugins.map(function(plugin) {
return installedPlugins().then(function(_plugins) {
return Promise.all(_plugins.map(function(plugin) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the no-underscore-dangle rule should be erroring here; can we pick a better name, like installedPlugins?

var src = plugin.path + '/';
var dst = path.join(process.env.HOME,
path.join('.avn/plugins', plugin.moduleName));
Expand All @@ -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() {
Expand Down
15 changes: 8 additions & 7 deletions lib/setup/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ 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()
.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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same throughout; let's please not add leading underscores to things :-)

_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; });
};
Expand All @@ -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()
Expand Down
14 changes: 8 additions & 6 deletions lib/setup/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ 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';
var _script = '$HOME/.avn/bin/avn.sh';
return util.format('[[ -s "%s" ]] && source "%s" # load avn\n',
script, script);
_script, _script);
};

/**
Expand All @@ -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 || {};
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion lib/util/codes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'; };
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 --",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd recommend adding this in "pretest": "eslint lib". Also, eslint should run on the entire project - ie, eslint . - and .eslintignore should be used if you need to ignore linting files.

"test-travis": "eslint lib && istanbul cover node_modules/.bin/_mocha --report lcovonly --"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -45,9 +45,10 @@
"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",
"jscs": "^3.0.4",
"jshint": "^2.8.0",
"mocha": "^2.0.1",
"sinon": "^1.10.2",
"sinon-chai": "^2.8.0",
Expand Down