Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run recommended config against source code #387

Merged
merged 38 commits into from
Oct 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8f64eea
Test on our own source code
fisker Sep 22, 2019
eb36482
fix deps
fisker Sep 22, 2019
295a6bb
Update recommended.js
sindresorhus Sep 22, 2019
3cdc078
Update recommended.js
sindresorhus Sep 22, 2019
02c4424
Merge remote-tracking branch 'remotes/origin/master' into run-on-self
fisker Sep 23, 2019
4562327
add lint
fisker Sep 23, 2019
eefa70f
Add missing file
fisker Sep 23, 2019
f6e2945
style
fisker Sep 23, 2019
5da159d
+x
fisker Sep 23, 2019
2aadfa9
fix
fisker Sep 23, 2019
aa0461f
fix
fisker Sep 23, 2019
1ef1769
fix `unicorn/prevent-abbreviations`
fisker Sep 23, 2019
3284bad
update ci
fisker Sep 23, 2019
4eab221
fix ci
fisker Sep 23, 2019
9a7dc89
separate lint and integration test
fisker Sep 23, 2019
e70cd09
separate lint and integration test
fisker Sep 23, 2019
7a9d54c
Merge branch 'run-on-self' of github.com:fisker/eslint-plugin-unicorn…
fisker Sep 23, 2019
26f6f2a
fix
fisker Sep 23, 2019
d404d2a
style
fisker Sep 23, 2019
2166254
+x
fisker Sep 23, 2019
8f8de4c
rename arguments0
fisker Sep 23, 2019
ac741b5
Make lint accept argument
fisker Sep 24, 2019
fab696a
Merge branch 'master' into run-on-self
fisker Oct 3, 2019
033a4a0
disable `consistent-function-scoping`
fisker Oct 3, 2019
cb2673b
disable `consistent-function-scoping`
fisker Oct 3, 2019
2671809
fix `prevent-abbreviations`
fisker Oct 3, 2019
90362e4
rename `get-docs-url.js` -> `get-documents-url.js`
fisker Oct 3, 2019
95c0a0d
rename `get-docs-url.js` -> `get-documents-url.js` in `/test`
fisker Oct 3, 2019
5e5a97a
update new rule docs
fisker Oct 3, 2019
de026e9
skip coveralls report on lint
fisker Oct 3, 2019
0512ed5
code style
fisker Oct 3, 2019
80fa35e
Merge github.com:fisker/eslint-plugin-unicorn into run-on-self
fisker Oct 8, 2019
5be519f
Merge remote-tracking branch 'remotes/upstream/master' into run-on-self
fisker Oct 8, 2019
80a934b
test
fisker Oct 8, 2019
462fa3f
remove `prevent-abbreviations` overrides
fisker Oct 8, 2019
a3ae40e
rename `docs` to `documentation`
fisker Oct 8, 2019
d49a17b
Merge remote-tracking branch 'remotes/upstream/master' into run-on-self
fisker Oct 12, 2019
5a92a53
try disable cache
fisker Oct 12, 2019
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
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
Comment on lines +6 to +7
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

CI finally passed, should I keep this?

Copy link
Owner

Choose a reason for hiding this comment

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

Sure, for now.

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.
sindresorhus marked this conversation as resolved.
Show resolved Hide resolved
- 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
Loading