Skip to content

Commit

Permalink
Update ESLint to v7 (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored May 9, 2020
1 parent 83bbabc commit e4f44f3
Show file tree
Hide file tree
Showing 37 changed files with 57 additions and 101 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"ava": "^3.8.1",
"babel-eslint": "^10.1.0",
"chalk": "^4.0.0",
"eslint": "^6.8.0",
"eslint": "^7.0.0",
"eslint-ava-rule-tester": "^4.0.0",
"eslint-plugin-eslint-plugin": "^2.2.1",
"execa": "^4.0.0",
Expand All @@ -66,7 +66,7 @@
"xo": "^0.30.0"
},
"peerDependencies": {
"eslint": ">=6.8.0"
"eslint": ">=7.0.0"
},
"ava": {
"babel": true,
Expand Down
1 change: 0 additions & 1 deletion test/better-regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const ruleTester = avaRuleTester(test, {

const createError = (original, optimized) => [
{
ruleId: 'better-regex',
message: `${original} can be optimized to ${optimized}`
}
];
Expand Down
2 changes: 0 additions & 2 deletions test/consistent-function-scoping.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ const typescriptRuleTester = avaRuleTester(test, {
parser: require.resolve('@typescript-eslint/parser')
});

const ruleId = 'consistent-function-scoping';
const MESSAGE_ID_NAMED = 'named';
const MESSAGE_ID_ANONYMOUS = 'anonymous';

const createError = ({name, arrow}) => ({
ruleId,
messageId: name ? MESSAGE_ID_NAMED : MESSAGE_ID_ANONYMOUS,
data: {
functionType: arrow ? 'arrow function' : 'function',
Expand Down
11 changes: 5 additions & 6 deletions test/custom-error-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ const typescriptRuleTester = avaRuleTester(test, {
parser: require.resolve('@typescript-eslint/parser')
});

const invalidClassNameError = {ruleId: 'custom-error-definition', message: 'Invalid class name, use `FooError`.'};
const constructorError = {ruleId: 'custom-error-definition', message: 'Add a constructor to your error.'};
const noSuperCallError = {ruleId: 'custom-error-definition', message: 'Missing call to `super()` in constructor.'};
const invalidNameError = name => ({ruleId: 'custom-error-definition', message: `The \`name\` property should be set to \`${name}\`.`});
const passMessageToSuperError = {ruleId: 'custom-error-definition', message: 'Pass the error message to `super()` instead of setting `this.message`.'};
const invalidClassNameError = {message: 'Invalid class name, use `FooError`.'};
const constructorError = {message: 'Add a constructor to your error.'};
const noSuperCallError = {message: 'Missing call to `super()` in constructor.'};
const invalidNameError = name => ({message: `The \`name\` property should be set to \`${name}\`.`});
const passMessageToSuperError = {message: 'Pass the error message to `super()` instead of setting `this.message`.'};
const invalidExportError = {
ruleId: 'custom-error-definition',
messageId: 'invalidExport'
};

Expand Down
2 changes: 0 additions & 2 deletions test/error-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ const ruleTester = avaRuleTester(test, {
});

const emptyStringError = {
ruleId: 'error-message',
message: 'Error message should not be an empty string.'
};

const noMessageError = {
ruleId: 'error-message',
message: 'Pass a message to the error constructor.'
};

Expand Down
1 change: 0 additions & 1 deletion test/escape-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const ruleTester = avaRuleTester(test, {

const errors = [
{
ruleId: 'escape-case',
message: 'Use uppercase characters for the value of the escape sequence.'
}
];
Expand Down
11 changes: 0 additions & 11 deletions test/expiring-todo-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,46 @@ const ruleTester = avaRuleTester(test, {
});

const expiredTodoError = (expirationDate, message) => ({
ruleId: 'expiring-todo-comments',
message: `There is a TODO that is past due date: ${expirationDate}. ${message}`
});

const avoidMultipleDatesError = (expirationDates, message) => ({
ruleId: 'expiring-todo-comments',
message: `Avoid using multiple expiration dates in TODO: ${expirationDates}. ${message}`
});

const havePackageError = (package_, message) => ({
ruleId: 'expiring-todo-comments',
message: `There is a TODO that is deprecated since you installed: ${package_}. ${message}`
});

const dontHavePackageError = (package_, message) => ({
ruleId: 'expiring-todo-comments',
message: `There is a TODO that is deprecated since you uninstalled: ${package_}. ${message}`
});

const versionMatchesError = (comparison, message) => ({
ruleId: 'expiring-todo-comments',
message: `There is a TODO match for package version: ${comparison}. ${message}`
});

const engineMatchesError = (comparison, message) => ({
ruleId: 'expiring-todo-comments',
message: `There is a TODO match for Node.js version: ${comparison}. ${message}`
});

const reachedPackageVersionError = (version, message) => ({
ruleId: 'expiring-todo-comments',
message: `There is a TODO that is past due package version: ${version}. ${message}`
});

const avoidMultiplePackageVersionsError = (versions, message) => ({
ruleId: 'expiring-todo-comments',
message: `Avoid using multiple package versions in TODO: ${versions}. ${message}`
});

const removeWhitespacesError = (argument, message) => ({
ruleId: 'expiring-todo-comments',
message: `Avoid using whitespaces on TODO argument. On '${argument}' use '${argument.replace(/ /g, '')}'. ${message}`
});

const missingAtSymbolError = (bad, good, message) => ({
ruleId: 'expiring-todo-comments',
message: `Missing '@' on TODO argument. On '${bad}' use '${good}'. ${message}`
});

const noWarningCommentError = () => ({
ruleId: 'expiring-todo-comments',
message: 'Unexpected \'todo\' comment.'
});

Expand Down
1 change: 0 additions & 1 deletion test/explicit-length-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const ruleTester = avaRuleTester(test, {

const error = message => {
return {
ruleId: 'explicit-length-check',
message
};
};
Expand Down
1 change: 0 additions & 1 deletion test/filename-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ function testCaseWithOptions(filename, errorMessage, options = []) {
options,
errors: errorMessage && [
{
ruleId: 'filename-case',
message: errorMessage
}
]
Expand Down
1 change: 0 additions & 1 deletion test/import-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const ruleTester = avaRuleTester(test, {
});

const error = {
ruleId: 'import-index',
message: 'Do not reference the index file directly.'
};

Expand Down
77 changes: 38 additions & 39 deletions test/lint/lint.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,61 @@
#!/usr/bin/env node
'use strict';
const {CLIEngine} = require('eslint');
const {ESLint} = require('eslint');
const unicorn = require('../..');

const {recommended} = unicorn.configs;
const files = [process.argv[2] || '.'];
const fix = process.argv.includes('--fix');
const ruleIds = Object.keys(unicorn.rules);
const unicornRules = new Map(Object.entries(unicorn.rules));

const cli = new CLIEngine({
const eslint = new ESLint({
baseConfig: recommended,
useEslintrc: false,
plugins: {
unicorn
},
fix,
ignorePattern: [
]
overrideConfig: {
ignorePatterns: [
'coverage',
'test/integration/fixtures'
]
}
});

cli.addPlugin('eslint-plugin-unicorn', unicorn);

// Make sure rules are loaded from codebase
const loadedRules = cli.getRules();
if (!ruleIds.every(ruleId => unicornRules.get(ruleId) === loadedRules.get(`unicorn/${ruleId}`))) {
console.error('`eslint-plugin-unicorn` rules are not loaded from codebase.');
process.exit(1);
}
(async function () {
const results = await eslint.lintFiles(files);

const report = cli.executeOnFiles(files);
if (fix) {
await ESLint.outputFixes(results);
}

const {
errorCount,
warningCount,
fixableErrorCount,
fixableWarningCount
} = report;
const errorCount = results.reduce((total, {errorCount}) => total + errorCount, 0);
const warningCount = results.reduce((total, {warningCount}) => total + warningCount, 0);
const fixableErrorCount = results.reduce((total, {fixableErrorCount}) => total + fixableErrorCount, 0);
const fixableWarningCount = results.reduce((total, {fixableWarningCount}) => total + fixableWarningCount, 0);

const hasFixable = fixableErrorCount || fixableWarningCount;
const hasFixable = fixableErrorCount || fixableWarningCount;

if (fix) {
CLIEngine.outputFixes(report);
}
if (errorCount || warningCount) {
const {format} = await eslint.loadFormatter();
console.log(format(results));

if (errorCount || warningCount) {
const formatter = cli.getFormatter();
console.log(formatter(report.results));
console.log();
console.log(`You need to fix the failed test${errorCount + warningCount > 1 ? 's' : ''} above and run \`npm run lint <file>\` to check again.`);

console.log();
console.log(`You need to fix the failed test${errorCount + warningCount > 1 ? 's' : ''} above and run \`npm run lint <file>\` to check again.`);
if (hasFixable) {
console.log();
console.log('You may also want run `npm run lint <file> --fix` to fix fixable problems.');
}

if (hasFixable) {
console.log();
console.log('You may also want run `npm run lint <file> --fix` to fix fixable problems.');
console.log('* If you\'re making a new rule, you can fix this later. *');
} else {
console.log('All tests have passed.');
}

console.log();
console.log('* If you\'re making a new rule, you can fix this later. *');
} else {
console.log('All tests have passed.');
}

process.exit(errorCount);
process.exit(errorCount);
})().catch(error => {
process.exitCode = 1;
console.error(error);
});
2 changes: 0 additions & 2 deletions test/new-for-builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ const ruleTester = avaRuleTester(test, {
});

const enforceNewError = builtin => ({
ruleId: 'new-for-builtins',
message: `Use \`new ${builtin}()\` instead of \`${builtin}()\`.`
});

const disallowNewError = builtin => ({
ruleId: 'new-for-builtins',
message: `Use \`${builtin}()\` instead of \`new ${builtin}()\`.`
});

Expand Down
1 change: 0 additions & 1 deletion test/no-abusive-eslint-disable.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const ruleTester = avaRuleTester(test, {

const error = [
{
ruleId: 'no-abusive-eslint-disable',
message: 'Specify the rules you want to disable.'
}
];
Expand Down
1 change: 0 additions & 1 deletion test/no-array-instanceof.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const ruleTester = avaRuleTester(test, {

const errors = [
{
ruleId: 'no-array-instanceof',
message: 'Use `Array.isArray()` instead of `instanceof Array`.'
}
];
Expand Down
1 change: 0 additions & 1 deletion test/no-console-spaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const ruleTester = avaRuleTester(test, {

function buildError({method, column, line}) {
const error = {
ruleId: 'no-console-spaces',
message: `Do not use leading/trailing space between \`console.${method}\` parameters.`
};

Expand Down
2 changes: 1 addition & 1 deletion test/no-for-loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function testCase(code, output) {
return {
code,
output: output || code,
errors: [{ruleId: 'no-for-loop'}]
errors: [{}]
};
}

Expand Down
1 change: 0 additions & 1 deletion test/no-hex-escape.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const typescriptRuleTester = avaRuleTester(test, {
});

const error = {
ruleId: 'no-hex-escape',
message: 'Use Unicode escapes instead of hexadecimal escapes.'
};

Expand Down
3 changes: 0 additions & 3 deletions test/no-nested-ternary.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const typescriptRuleTester = avaRuleTester(test, {

const errors = [
{
ruleId: 'no-nested-ternary',
message: 'Do not nest ternary expressions.'
}
];
Expand Down Expand Up @@ -49,11 +48,9 @@ ruleTester.run('new-error', rule, {
output: 'const foo = i > 5 ? (i < 100 ? true : false) : (i < 100 ? true : false);',
errors: [
{
ruleId: 'no-nested-ternary',
column: 21
},
{
ruleId: 'no-nested-ternary',
column: 46
}
]
Expand Down
2 changes: 0 additions & 2 deletions test/no-new-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ const typescriptRuleTester = avaRuleTester(test, {
});

const allocError = {
ruleId: 'no-new-buffer',
message: '`new Buffer()` is deprecated, use `Buffer.alloc()` instead.'
};

const fromError = {
ruleId: 'no-new-buffer',
message: '`new Buffer()` is deprecated, use `Buffer.from()` instead.'
};

Expand Down
1 change: 0 additions & 1 deletion test/no-process-exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const ruleTester = avaRuleTester(test, {

const errors = [
{
ruleId: 'no-process-exit',
message: 'Only use `process.exit()` in CLI apps. Throw an error instead.'
}
];
Expand Down
1 change: 0 additions & 1 deletion test/no-unsafe-regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const ruleTester = avaRuleTester(test, {
});

const error = {
ruleId: 'no-unsafe-regex',
message: 'Unsafe regular expression.'
};

Expand Down
1 change: 0 additions & 1 deletion test/no-unused-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const babelEslintRuleTester = avaRuleTester(test, {
});

const error = {
ruleId: 'no-unused-properties',
message: 'Property `u` is defined but never used.'
};

Expand Down
2 changes: 0 additions & 2 deletions test/no-zero-fractions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ const ruleTester = avaRuleTester(test, {
});

const errorZeroFraction = {
ruleId: 'no-zero-fractions',
message: 'Don\'t use a zero fraction in the number.'
};
const errorDanglingDot = {
ruleId: 'no-zero-fractions',
message: 'Don\'t use a dangling dot in the number.'
};

Expand Down
1 change: 0 additions & 1 deletion test/number-literal-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const ruleTester = avaRuleTester(test, {
});

const error = {
ruleId: 'number-literal-case',
message: 'Invalid number literal casing.'
};

Expand Down
Loading

0 comments on commit e4f44f3

Please sign in to comment.