Skip to content

Commit

Permalink
Run recommended config against source code (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored and sindresorhus committed Oct 12, 2019
1 parent 5eb9da9 commit d638e54
Show file tree
Hide file tree
Showing 51 changed files with 232 additions and 189 deletions.
12 changes: 9 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ node_js:
- '12'
- '10'
- '8'
cache:
npm: false
matrix:
include:
- node_js: '12'
env: INTEGRATION=true
env: INTEGRATION=true SKIP_TEST=true
- node_js: '12'
env: LINT=true SKIP_TEST=true
script:
- if [ $INTEGRATION == true ]; then npm run integration; else npm test; fi
- if [[ $INTEGRATION == true ]]; then npm run integration; fi
- if [[ $LINT == true ]]; then npm run lint; fi
- if [[ $SKIP_TEST != true ]]; then npm test; fi
after_success:
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'
- if [[ $LINT != true ]]; then ./node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls; fi
1 change: 1 addition & 0 deletions docs/new-rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ Use the [`astexplorer` site](https://astexplorer.net) with the `espree` parser a
*(The description should be the same as the heading of the documentation file).*
- Run `$ npm test` to ensure the tests pass.
- Run `$ npm run integration` to run the rules against real projects to ensure your rule does not fail on real-world code.
- Run `$ npm run lint` to run the rules against this repository to ensure code in the repository are following your rule.
- Open a pull request with a title in exactly the format `` Add `rule-name` rule ``, for example, `` Add `no-unused-properties` rule ``.
- The pull request description should include the issue it fixes, for example, `Fixes #123`.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"scripts": {
"test": "xo && nyc ava",
"lint": "./test/lint/lint.js",
"integration": "./test/integration/test.js"
},
"files": [
Expand Down
12 changes: 6 additions & 6 deletions rules/catch-error-name.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
const astUtils = require('eslint-ast-utils');
const avoidCapture = require('./utils/avoid-capture');
const getDocsUrl = require('./utils/get-docs-url');
const getDocumentationUrl = require('./utils/get-documentation-url');

// Matches `someObj.then([FunctionExpression | ArrowFunctionExpression])`
function isLintablePromiseCatch(node) {
Expand All @@ -21,9 +21,9 @@ function isLintablePromiseCatch(node) {
return false;
}

const [arg0] = node.arguments;
const [firstArgument] = node.arguments;

return arg0.type === 'FunctionExpression' || arg0.type === 'ArrowFunctionExpression';
return firstArgument.type === 'FunctionExpression' || firstArgument.type === 'ArrowFunctionExpression';
}

const create = context => {
Expand Down Expand Up @@ -118,8 +118,8 @@ const create = context => {
}

const scope = context.getScope();
const errName = avoidCapture(name, [scope.variableScope], ecmaVersion);
push(node.param.name === errName || errName);
const errorName = avoidCapture(name, [scope.variableScope], ecmaVersion);
push(node.param.name === errorName || errorName);
},
'CatchClause:exit': node => {
popAndReport(node.param, node);
Expand All @@ -144,7 +144,7 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
url: getDocsUrl(__filename)
url: getDocumentationUrl(__filename)
},
fixable: 'code',
schema
Expand Down
4 changes: 2 additions & 2 deletions rules/consistent-function-scoping.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const getDocsUrl = require('./utils/get-docs-url');
const getDocumentationUrl = require('./utils/get-documentation-url');

const MESSAGE_ID_ARROW = 'ArrowFunctionExpression';
const MESSAGE_ID_FUNCTION = 'FunctionDeclaration';
Expand Down Expand Up @@ -172,7 +172,7 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
url: getDocsUrl(__filename)
url: getDocumentationUrl(__filename)
},
messages: {
[MESSAGE_ID_ARROW]: 'Move arrow function to the outer scope.',
Expand Down
4 changes: 2 additions & 2 deletions rules/custom-error-definition.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const upperfirst = require('lodash.upperfirst');
const getDocsUrl = require('./utils/get-docs-url');
const getDocumentationUrl = require('./utils/get-documentation-url');

const MESSAGE_ID_INVALID_EXPORT = 'invalidExport';

Expand Down Expand Up @@ -178,7 +178,7 @@ module.exports = {
meta: {
type: 'problem',
docs: {
url: getDocsUrl(__filename)
url: getDocumentationUrl(__filename)
},
fixable: 'code',
messages: {
Expand Down
4 changes: 2 additions & 2 deletions rules/error-message.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const getDocsUrl = require('./utils/get-docs-url');
const getDocumentationUrl = require('./utils/get-documentation-url');

const errorConstructors = new Set([
'Error',
Expand Down Expand Up @@ -94,7 +94,7 @@ module.exports = {
meta: {
type: 'problem',
docs: {
url: getDocsUrl(__filename)
url: getDocumentationUrl(__filename)
}
}
};
4 changes: 2 additions & 2 deletions rules/escape-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {
parseRegExpLiteral
} = require('regexpp');

const getDocsUrl = require('./utils/get-docs-url');
const getDocumentationUrl = require('./utils/get-documentation-url');

const escapeWithLowercase = /((?:^|[^\\])(?:\\\\)*)\\(x[a-f\d]{2}|u[a-f\d]{4}|u{(?:[a-f\d]+)})/;
const escapePatternWithLowercase = /((?:^|[^\\])(?:\\\\)*)\\(x[a-f\d]{2}|u[a-f\d]{4}|u{(?:[a-f\d]+)}|c[a-z])/;
Expand Down Expand Up @@ -127,7 +127,7 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
url: getDocsUrl(__filename)
url: getDocumentationUrl(__filename)
},
fixable: 'code'
}
Expand Down
18 changes: 9 additions & 9 deletions rules/expiring-todo-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const readPkgUp = require('read-pkg-up');
const semver = require('semver');
const ci = require('ci-info');
const baseRule = require('eslint/lib/rules/no-warning-comments');
const getDocsUrl = require('./utils/get-docs-url');
const getDocumentationUrl = require('./utils/get-documentation-url');

const MESSAGE_ID_AVOID_MULTIPLE_DATES = 'avoidMultipleDates';
const MESSAGE_ID_EXPIRED_TODO = 'expiredTodo';
Expand All @@ -21,7 +21,7 @@ const packageResult = readPkgUp.sync();
const hasPackage = Boolean(packageResult);
const packageJson = hasPackage ? packageResult.packageJson : {};

const pkgDependencies = {
const packageDependencies = {
...packageJson.dependencies,
...packageJson.devDependencies
};
Expand Down Expand Up @@ -283,11 +283,11 @@ const create = context => {
uses++;
const [{condition, version}] = packageVersions;

const pkgVersion = tryToCoerceVersion(packageJson.version);
const desidedPkgVersion = tryToCoerceVersion(version);
const packageVersion = tryToCoerceVersion(packageJson.version);
const desidedPackageVersion = tryToCoerceVersion(version);

const compare = semverComparisonForOperator(condition);
if (compare(pkgVersion, desidedPkgVersion)) {
if (compare(packageVersion, desidedPackageVersion)) {
context.report({
node: null,
loc: comment.loc,
Expand All @@ -304,7 +304,7 @@ const create = context => {
// Comparison: '>', '>='
for (const dependency of dependencies) {
uses++;
const targetPackageRawVersion = pkgDependencies[dependency.name];
const targetPackageRawVersion = packageDependencies[dependency.name];
const hasTargetPackage = Boolean(targetPackageRawVersion);

const isInclusion = ['in', 'out'].includes(dependency.condition);
Expand Down Expand Up @@ -352,12 +352,12 @@ const create = context => {
}
}

const pkgEngines = packageJson.engines || {};
const packageEngines = packageJson.engines || {};

for (const engine of engines) {
uses++;

const targetPackageRawEngineVersion = pkgEngines.node;
const targetPackageRawEngineVersion = packageEngines.node;
const hasTargetEngine = Boolean(targetPackageRawEngineVersion);

if (!hasTargetEngine) {
Expand Down Expand Up @@ -467,7 +467,7 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
url: getDocsUrl(__filename)
url: getDocumentationUrl(__filename)
},
messages: {
[MESSAGE_ID_AVOID_MULTIPLE_DATES]:
Expand Down
4 changes: 2 additions & 2 deletions rules/explicit-length-check.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const getDocsUrl = require('./utils/get-docs-url');
const getDocumentationUrl = require('./utils/get-documentation-url');

const operatorTypes = {
gt: ['>'],
Expand Down Expand Up @@ -164,7 +164,7 @@ module.exports = {
meta: {
type: 'problem',
docs: {
url: getDocsUrl(__filename)
url: getDocumentationUrl(__filename)
},
fixable: 'code',
schema
Expand Down
10 changes: 5 additions & 5 deletions rules/filename-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const camelCase = require('lodash.camelcase');
const kebabCase = require('lodash.kebabcase');
const snakeCase = require('lodash.snakecase');
const upperfirst = require('lodash.upperfirst');
const getDocsUrl = require('./utils/get-docs-url');
const getDocumentationUrl = require('./utils/get-documentation-url');
const cartesianProductSamples = require('./utils/cartesian-product-samples');

const pascalCase = string => upperfirst(camelCase(string));
Expand Down Expand Up @@ -95,10 +95,10 @@ function fixFilename(words, caseFunctions, {leading, extension}) {

const leadingUnserscoresRegex = /^(_+)(.*)$/;
function splitFilename(filename) {
const res = leadingUnserscoresRegex.exec(filename);
const result = leadingUnserscoresRegex.exec(filename);

const leading = (res && res[1]) || '';
const tailing = (res && res[2]) || filename;
const leading = (result && result[1]) || '';
const tailing = (result && result[2]) || filename;

const words = [];

Expand Down Expand Up @@ -233,7 +233,7 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
url: getDocsUrl(__filename)
url: getDocumentationUrl(__filename)
},
schema,
messages: {
Expand Down
4 changes: 2 additions & 2 deletions rules/import-index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const getDocsUrl = require('./utils/get-docs-url');
const getDocumentationUrl = require('./utils/get-documentation-url');

const regexp = /^(@.*?\/.*?|[./]+?.*?)(?:\/(\.|(?:index(?:\.js)?))?)$/;
const isImportingIndex = value => regexp.test(value);
Expand Down Expand Up @@ -27,7 +27,7 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
url: getDocsUrl(__filename)
url: getDocumentationUrl(__filename)
},
fixable: 'code'
}
Expand Down
4 changes: 2 additions & 2 deletions rules/new-for-builtins.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const getDocsUrl = require('./utils/get-docs-url');
const getDocumentationUrl = require('./utils/get-documentation-url');

const enforceNew = new Set([
'Object',
Expand Down Expand Up @@ -71,7 +71,7 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
url: getDocsUrl(__filename)
url: getDocumentationUrl(__filename)
},
fixable: 'code'
}
Expand Down
10 changes: 5 additions & 5 deletions rules/no-abusive-eslint-disable.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use strict';
const getDocsUrl = require('./utils/get-docs-url');
const getDocumentationUrl = require('./utils/get-documentation-url');

const disableRegex = /^eslint-disable(-next-line|-line)?($|(\s+(@[\w-]+\/(?:[\w-]+\/)?)?[\w-]+)?)/;

const create = context => ({
Program: node => {
for (const comment of node.comments) {
const value = comment.value.trim();
const res = disableRegex.exec(value);
const result = disableRegex.exec(value);

if (
res && // It's a eslint-disable comment
!res[2] // But it did not specify any rules
result && // It's a eslint-disable comment
!result[2] // But it did not specify any rules
) {
context.report({
loc: {
Expand All @@ -33,7 +33,7 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
url: getDocsUrl(__filename)
url: getDocumentationUrl(__filename)
}
}
};
4 changes: 2 additions & 2 deletions rules/no-array-instanceof.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const getDocsUrl = require('./utils/get-docs-url');
const getDocumentationUrl = require('./utils/get-documentation-url');

const create = context => ({
BinaryExpression: node => {
Expand All @@ -21,7 +21,7 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
url: getDocsUrl(__filename)
url: getDocumentationUrl(__filename)
},
fixable: 'code'
}
Expand Down
14 changes: 7 additions & 7 deletions rules/no-console-spaces.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const getDocsUrl = require('./utils/get-docs-url');
const getDocumentationUrl = require('./utils/get-documentation-url');

const getConsoleMethod = node => {
const methods = [
Expand Down Expand Up @@ -70,12 +70,12 @@ const fixValue = (value, {

const getFixableArguments = (context, node) => {
const {
arguments: args
arguments: arguments_
} = node;

const fixables = args.map((nodeArgument, i) => {
const fixables = arguments_.map((nodeArgument, i) => {
const fixLeading = i !== 0;
const fixTrailing = i !== (args.length - 1);
const fixTrailing = i !== (arguments_.length - 1);

const value = getArgumentValue(context, nodeArgument);
const fixed = fixValue(value, {fixLeading, fixTrailing});
Expand All @@ -91,7 +91,7 @@ const getFixableArguments = (context, node) => {
return fixables.filter(fixable => fixable.fixable);
};

const fixArg = (context, fixable, fixer) => {
const fixArgument = (context, fixable, fixer) => {
const {
nodeArgument,
fixed
Expand Down Expand Up @@ -123,7 +123,7 @@ const create = context => {
context.report({
node: fixable.nodeArgument,
message: buildErrorMessage(method),
fix: fixer => fixArg(context, fixable, fixer)
fix: fixer => fixArgument(context, fixable, fixer)
});
}
}
Expand All @@ -135,7 +135,7 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
url: getDocsUrl(__filename)
url: getDocumentationUrl(__filename)
},
fixable: 'code'
}
Expand Down

0 comments on commit d638e54

Please sign in to comment.