Skip to content

Commit

Permalink
chore(lint): update lint dependencies (#948)
Browse files Browse the repository at this point in the history
This updates `eslint-config-airbnb-base` and `eslint-plugin-import`.
This also addresses lint errors these updates raise, and excludes
several rules.

This also adds a minor simplification to the gendocs script.

Test: npm run lint
Test: npm run gendocs
  • Loading branch information
nfischer committed Jul 12, 2019
1 parent 7aa8ce4 commit 57df38c
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 48 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.json
Expand Up @@ -12,17 +12,21 @@
"indent": "off",
"max-len": "off",
"newline-per-chained-call": "off",
"no-bitwise": "off",
"no-console": "off",
"no-continue": "off",
"no-else-return": "off",
"no-empty": "off",
"no-mixed-operators": "off",
"no-multi-spaces": "off",
"no-multiple-empty-lines": ["error", { "max": 2, "maxBOF": 0, "maxEOF": 0 } ],
"no-param-reassign": "off",
"no-plusplus": "off",
"no-prototype-builtins": "off",
"no-throw-literal": "off",
"no-underscore-dangle": "off",
"no-use-before-define": "off",
"operator-linebreak": "off",
"quote-props": "off",
"spaced-comment": ["error", "always", { "markers": ["@", "@include"], "exceptions": ["@", "@commands"] }],
"vars-on-top": "off",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -64,8 +64,8 @@
"codecov": "^3.0.2",
"coffee-script": "^1.10.0",
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^3.0.0",
"eslint-plugin-import": "^1.11.1",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.17.3",
"js-yaml": "^3.12.0",
"nyc": "^11.3.0",
"shelljs-changelog": "^0.2.0",
Expand Down
3 changes: 2 additions & 1 deletion scripts/check-node-support.js
Expand Up @@ -16,7 +16,8 @@ function checkReadme(minNodeVersion) {
var stop = '<!-- stop minVersion -->';
var formattedMinVersion = '`v' + minNodeVersion + '`';
var expectedReadmeRegex = new RegExp(
start + '\\s*' + formattedMinVersion + '\\s*' + stop, '');
start + '\\s*' + formattedMinVersion + '\\s*' + stop, ''
);
var readme = path.join(__dirname, '..', 'README.md');
var match = shell.grep(expectedReadmeRegex, readme);
if (!match.toString()) {
Expand Down
9 changes: 5 additions & 4 deletions scripts/generate-docs.js
Expand Up @@ -2,9 +2,11 @@
/* globals cat, cd, echo, grep, sed, ShellString */
require('../global');

var path = require('path');

echo('Appending docs to README.md');

cd(__dirname + '/..');
cd(path.join(__dirname, '..'));

// Extract docs from shell.js
var docs = grep('^//@', 'shell.js');
Expand All @@ -18,9 +20,8 @@ docs = docs.replace(/\/\/@commands\n/g, function () {
});

// Now extract docs from the remaining src/*.js files
docs = docs.replace(/\/\/@include (.+)/g, function (match, path) {
var file = path.match('.js$') ? path : path + '.js';
return grep('^//@', file);
docs = docs.replace(/\/\/@include (.+)/g, function (match, filename) {
return grep('^//@', filename);
});

// Remove '//@'
Expand Down
4 changes: 2 additions & 2 deletions shell.js
Expand Up @@ -31,10 +31,10 @@ require('./commands').forEach(function (command) {
//@ Exits the current process with the given exit `code`.
exports.exit = process.exit;

//@include ./src/error
//@include ./src/error.js
exports.error = require('./src/error');

//@include ./src/common
//@include ./src/common.js
exports.ShellString = common.ShellString;

//@
Expand Down
2 changes: 1 addition & 1 deletion src/chmod.js
Expand Up @@ -121,7 +121,7 @@ function _chmod(options, mode, filePattern) {

var newPerms = perms;

if (isNaN(parseInt(mode, 8))) {
if (Number.isNaN(parseInt(mode, 8))) {
// parse options
mode.split(',').forEach(function (symbolicMode) {
var pattern = /([ugoa]*)([=+-])([rwxXst]*)/i;
Expand Down
19 changes: 10 additions & 9 deletions src/common.js
@@ -1,5 +1,7 @@
// Ignore warning about 'new String()'
/* eslint no-new-wrappers: 0 */
// Ignore warning about 'new String()' and use of the Buffer constructor
/* eslint no-new-wrappers: "off",
no-buffer-constructor: "off" */

'use strict';

var os = require('os');
Expand Down Expand Up @@ -181,7 +183,8 @@ function parseOptions(opt, map, errorOptions) {
throw new TypeError('parseOptions() internal error: map must be an object');
} else if (!isObject(errorOptions)) {
throw new TypeError(
'parseOptions() internal error: errorOptions must be object');
'parseOptions() internal error: errorOptions must be object'
);
}

if (opt === '--') {
Expand Down Expand Up @@ -231,13 +234,11 @@ function parseOptions(opt, map, errorOptions) {
} else {
error('option not recognized: ' + c, errorOptions);
}
} else if (key in options) {
// key is a "long option", so it should be the same
options[key] = opt[key];
} else {
if (key in options) {
// key is a "long option", so it should be the same
options[key] = opt[key];
} else {
error('option not recognized: {' + key + ':...}', errorOptions);
}
error('option not recognized: {' + key + ':...}', errorOptions);
}
});
}
Expand Down
9 changes: 3 additions & 6 deletions src/cp.js
Expand Up @@ -141,13 +141,10 @@ function cpdirSyncRecursive(sourceDir, destDir, currentDepth, opts) {
} else {
copyFileSync(srcFile, destFile, opts);
}
} else if (fs.existsSync(destFile) && opts.no_force) {
common.log('skipping existing file: ' + files[i]);
} else {
/* At this point, we've hit a file actually worth copying... so copy it on over. */
if (fs.existsSync(destFile) && opts.no_force) {
common.log('skipping existing file: ' + files[i]);
} else {
copyFileSync(srcFile, destFile, opts);
}
copyFileSync(srcFile, destFile, opts);
}
} // for files

Expand Down
8 changes: 3 additions & 5 deletions src/dirs.js
Expand Up @@ -81,12 +81,10 @@ function _pushd(options, dir) {
} else if (_isStackIndex(dir)) {
var n = _parseStackIndex(dir);
dirs = dirs.slice(n).concat(dirs.slice(0, n));
} else if (options['no-cd']) {
dirs.splice(1, 0, dir);
} else {
if (options['no-cd']) {
dirs.splice(1, 0, dir);
} else {
dirs.unshift(dir);
}
dirs.unshift(dir);
}

if (options['no-cd']) {
Expand Down
19 changes: 9 additions & 10 deletions src/rm.js
Expand Up @@ -29,16 +29,15 @@ function rmdirSyncRecursive(dir, force, fromSymlink) {

if (currFile.isDirectory()) { // Recursive function back to the beginning
rmdirSyncRecursive(file, force);
} else { // Assume it's a file - perhaps a try/catch belongs here?
if (force || isWriteable(file)) {
try {
common.unlinkSync(file);
} catch (e) {
/* istanbul ignore next */
common.error('could not remove file (code ' + e.code + '): ' + file, {
continue: true,
});
}
} else if (force || isWriteable(file)) {
// Assume it's a file - perhaps a try/catch belongs here?
try {
common.unlinkSync(file);
} catch (e) {
/* istanbul ignore next */
common.error('could not remove file (code ' + e.code + '): ' + file, {
continue: true,
});
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/set.js
Expand Up @@ -51,6 +51,5 @@ function _set(options) {
common.config[key] = options[key];
}
});
return;
}
module.exports = _set;
6 changes: 3 additions & 3 deletions src/uniq.js
Expand Up @@ -55,9 +55,9 @@ function _uniq(options, input, output) {
common.error(output + ': Is a directory');
}

var lines = (input ? fs.readFileSync(input, 'utf8') : pipe).
trimRight().
split('\n');
var lines = (input ? fs.readFileSync(input, 'utf8') : pipe)
.trimRight()
.split('\n');

var compare = function (a, b) {
return options.ignoreCase ?
Expand Down
8 changes: 8 additions & 0 deletions test/.eslintrc.json
Expand Up @@ -4,17 +4,25 @@
},
"extends": "airbnb-base",
"rules": {
"arrow-parens": "off",
"comma-dangle": "off",
"curly": "off",
"global-require": "off",
"import/no-dynamic-require": "off",
"import/no-mutable-exports": "off",
"indent": "off",
"max-len": "off",
"no-bitwise": "off",
"no-console": "off",
"no-param-reassign": "off",
"no-plusplus": "off",
"no-underscore-dangle": "off",
"no-var": "error",
"operator-linebreak": "off",
"prefer-arrow-callback": "off",
"prefer-const": "error",
"prefer-destructuring": "off",
"prefer-numeric-literals": "off",
"prefer-template": "off",
"spaced-comment": ["error", "always", { "markers": ["@", "@include"], "exceptions": ["@"] }],
"vars-on-top": "off",
Expand Down
3 changes: 1 addition & 2 deletions test/cp.js
Expand Up @@ -292,8 +292,7 @@ test('recursive, copying one regular file', t => {
t.is(result.code, 0);
t.truthy(fs.existsSync(`${t.context.tmp}/file1.txt`));
t.falsy(common.statFollowLinks(`${t.context.tmp}/file1.txt`).isDirectory()); // don't let it be a dir
}
);
});

test('recursive, everything exists, no force flag', t => {
const result = shell.cp('-R', 'test/resources/cp', t.context.tmp);
Expand Down
1 change: 0 additions & 1 deletion test/global.js
Expand Up @@ -47,4 +47,3 @@ test('String.prototype is modified for global require', t => {
'bar'.toEnd(`${t.context.tmp}/testfile.txt`);
t.is('foobar', cat(`${t.context.tmp}/testfile.txt`).toString());
});

1 change: 0 additions & 1 deletion test/set.js
Expand Up @@ -75,4 +75,3 @@ test('set -f', t => {
shell.rm(`${t.context.tmp}/*.txt`);
t.falsy(shell.error()); // globbing works, so rm succeeds
});

0 comments on commit 57df38c

Please sign in to comment.