Skip to content

Commit

Permalink
chore: upgrade eslint-config-eslint v10
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed May 2, 2024
1 parent 500e50b commit 325f91a
Show file tree
Hide file tree
Showing 17 changed files with 1,444 additions and 1,438 deletions.
6 changes: 5 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ export default [
{ files: ["packages/*/tests/**/*"], languageOptions: { globals: globals.mocha } },
{
plugins: { autofix: autofixPlugin, "no-autofix": noAutofixPlugin },
rules: { "eslint-comments/require-description": 0, "no-autofix/eslint-plugin/test-case-shorthand-strings": "error" }
rules: {
"eslint-comments/require-description": 0,
"no-autofix/eslint-plugin/test-case-shorthand-strings": 2,
"@eslint-community/eslint-comments/require-description": 0
}
},
...nPlugin.configs["flat/mixed-esm-and-cjs"]
];
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"description": "some eslint plugins",
"devDependencies": {
"eslint": "^9.1.1",
"eslint-config-eslint": "^9.0.0",
"eslint-config-eslint": "^10.0.0",
"eslint-plugin-autofix": "file:./packages/autofix",
"eslint-plugin-eslint-plugin": "^6.0.0",
"eslint-plugin-eslint-plugin": "^6.1.0",
"eslint-plugin-no-autofix": "file:./packages/no-autofix",
"globals": "^15.0.0"
"globals": "^15.1.0"
},
"scripts": {
"lint": "eslint packages/",
Expand All @@ -21,7 +21,7 @@
"homepage": "https://github.com/aladdin-add/eslint-plugin",
"bugs": "https://github.com/aladdin-add/eslint-plugin/issues/",
"engines": {
"node": ">=8"
"node": ">=18"
},
"workspaces": [
"packages/*"
Expand Down
1 change: 0 additions & 1 deletion packages/autofix/lib/configs/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ Object.keys(allRules)
.reduce((rules, ruleName) => Object.assign(rules, { [`${PLUGIN_NAME}/${ruleName}`]: "error" }), all.rules);

module.exports = all;

4 changes: 2 additions & 2 deletions packages/autofix/lib/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

const fs = require("fs");
const path = require("path");
const {eslintVersion} = require("./utils.js")
const { eslintVersion } = require("./utils.js");


/**
Expand Down Expand Up @@ -41,7 +41,7 @@ if (eslintVersion >= 8) {
}
}
} else if (eslintVersion >= 6) {
const builtin = require("eslint/lib/rules");
const builtin = require("eslint/lib/rules"); // eslint-disable-line n/no-missing-require

for (const [ruleId, rule] of builtin) {
if (rule.meta.fixable) {
Expand Down
6 changes: 3 additions & 3 deletions packages/autofix/lib/rules/no-unused-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ module.exports = ruleComposer.mapReports(
return fixer.remove(grand);
}

if (parent !== grand.specifiers[grand.specifiers.length - 1]) {
if (parent !== grand.specifiers.at(-1)) {
const comma = sourceCode.getTokenAfter(parent, commaFilter);

return [fixer.remove(parent), fixer.remove(comma)];
Expand Down Expand Up @@ -189,7 +189,7 @@ module.exports = ruleComposer.mapReports(
return fixer.remove(grand);
}

if (parent !== grand.declarations[grand.declarations.length - 1]) {
if (parent !== grand.declarations.at(-1)) {
const comma = sourceCode.getTokenAfter(parent, commaFilter);

return [fixer.remove(parent), fixer.remove(comma)];
Expand Down Expand Up @@ -219,7 +219,7 @@ module.exports = ruleComposer.mapReports(
return comma ? [identifierRemoval, fixer.remove(comma)] : identifierRemoval;
}

if (parent === grand.properties[grand.properties.length - 1]) {
if (parent === grand.properties.at(-1)) {
const comma = sourceCode.getTokenBefore(parent, commaFilter);

return [fixer.remove(parent), fixer.remove(comma)];
Expand Down
4 changes: 4 additions & 0 deletions packages/autofix/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ exports.eslintVersion = Number.parseInt(require("eslint/package.json").version,
// TODO: this might be unreliable
if (exports.eslintVersion >= 8) {
const { builtinRules } = require("eslint/use-at-your-own-risk");

exports.builtinRules = builtinRules;
} else if (exports.eslintVersion >= 6) {
// eslint-disable-next-line n/no-missing-require
const builtin = require("eslint/lib/rules");

exports.builtinRules = builtin;
} else {
const builtin = require("eslint/lib/built-in-rules-index"); // eslint-disable-line n/no-missing-require

exports.builtinRules = builtin;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/autofix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@
"homepage": "https://github.com/aladdin-add/eslint-plugin/tree/master/packages/autofix",
"bugs": "https://github.com/aladdin-add/eslint-plugin/issues/new?assignees=aladdin-add&labels=bug&template=bug-report--eslint-plugin-autofix.md&title=eslint-plugin-autofix+bug",
"engines": {
"node": ">=8"
"node": ">=18"
}
}
14 changes: 6 additions & 8 deletions packages/autofix/tests/lib/rules/no-unused-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ const ruleTester = new RuleTester();

ruleTester.run("no-unused-vars", rule, {
valid: [
{
code: "import 'm'",
},
"import 'm'",

// https://github.com/aladdin-add/eslint-plugin/issues/58
`const { _ } = require('lib/locale.js');
Expand Down Expand Up @@ -186,7 +184,7 @@ ruleTester.run("no-unused-vars", rule, {
{
code: "function foo(a, b, c){console.log(b);}; foo(1, 2, 3);",
output: "function foo(a, b ){console.log(b);}; foo(1, 2, 3);",
errors:1,
errors: 1,
options: [{
args: "after-used",
argsIgnorePattern: "^_"
Expand All @@ -195,7 +193,7 @@ ruleTester.run("no-unused-vars", rule, {
{
code: "const foo = function(a, b, c) {console.log(b);}; foo(1, 2, 3);",
output: "const foo = function(a, b ) {console.log(b);}; foo(1, 2, 3);",
errors:1,
errors: 1,
options: [{
args: "after-used",
argsIgnorePattern: "^_"
Expand All @@ -204,7 +202,7 @@ ruleTester.run("no-unused-vars", rule, {
{
code: "const foo = (a, b, c) => {console.log(b);}; foo(1, 2, 3);",
output: "const foo = (a, b ) => {console.log(b);}; foo(1, 2, 3);",
errors:1,
errors: 1,
options: [{
args: "after-used",
argsIgnorePattern: "^_"
Expand All @@ -213,7 +211,7 @@ ruleTester.run("no-unused-vars", rule, {
{
code: "const foo = (a) => {}; foo();",
output: "const foo = () => {}; foo();",
errors:1,
errors: 1,
options: [{
args: "after-used",
argsIgnorePattern: "^_"
Expand All @@ -222,7 +220,7 @@ ruleTester.run("no-unused-vars", rule, {
{
code: "const foo = a => {}; foo();",
output: "const foo = () => {}; foo();",
errors:1,
errors: 1,
options: [{
args: "after-used",
argsIgnorePattern: "^_"
Expand Down
2 changes: 1 addition & 1 deletion packages/autofix/tests/lib/rules/no-useless-catch.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ruleTester.run("no-useless-catch", rule, {
{
code: "try {} catch (e) { throw e } finally {}",
output: "try {} finally {}",
errors:1
errors: 1
}
]
});
3 changes: 1 addition & 2 deletions packages/autofix/tools/new-rule.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable node/no-process-exit */
/* eslint no-console: 0, no-process-exit: 0*/
/* eslint no-console: 0, n/no-process-exit: 0*/
"use strict";

const fs = require("fs");
Expand Down
6 changes: 2 additions & 4 deletions packages/no-autofix/lib/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@
const fs = require("fs");
const path = require("path");
const findUp = require("find-up");
const eslint = require("eslint");
const eslintVersion = Number.parseInt(require("eslint/package.json").version, 10);
const linter = new eslint.Linter();
const { getNonFixableRule } = require("./utils");
const pkg = require(path.join(__dirname, "../package.json"));
const allRules = {};
const builtinRules = {};

if (eslintVersion >= 8) {
const { builtinRules: rules } = require("eslint/use-at-your-own-risk"); // eslint-disable-line node/no-missing-require
const { builtinRules: rules } = require("eslint/use-at-your-own-risk");

for (const [ruleId, rule] of rules) {
builtinRules[ruleId] = rule;
}
} else if (eslintVersion >= 6) {
const builtin = require("eslint/lib/rules"); // eslint-disable-line node/no-missing-require
const builtin = require("eslint/lib/rules"); // eslint-disable-line n/no-missing-require

for (const [ruleId, rule] of builtin) {
builtinRules[ruleId] = rule;
Expand Down
3 changes: 2 additions & 1 deletion packages/no-autofix/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const ruleComposer = require("eslint-rule-composer");
exports.getNonFixableRule = function(rule) {
return ruleComposer.mapReports(
Object.create(rule),
problem => (problem.fix = null, problem) // eslint-disable-line
// eslint-disable-next-line no-return-assign, no-sequences
problem => (problem.fix = null, problem)
);
};
2 changes: 1 addition & 1 deletion packages/no-autofix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"homepage": "https://github.com/aladdin-add/eslint-plugin/tree/master/packages/no-autofix",
"bugs": "https://github.com/aladdin-add/eslint-plugin/issues/new?assignees=aladdin-add&labels=bug&template=bug-report--eslint-plugin-no-autofix.md&title=bug+report%3A+eslint-plugin-no-autofix",
"engines": {
"node": ">=8"
"node": ">=18"
}
}
72 changes: 36 additions & 36 deletions packages/no-autofix/tests/lib/rules/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,57 @@ ruleTester.run("quotes", rule, {
{ code: "var foo = 1;", options: ["double"] },
{ code: "var foo = \"'\";", options: ["single", { avoidEscape: true }] },
{ code: "var foo = '\"';", options: ["double", { avoidEscape: true }] },
{ code: "var foo = <>Hello world</>;", options: ["single"], },
{ code: "var foo = <>Hello world</>;", options: ["double"], },
{ code: "var foo = <>Hello world</>;", options: ["double", { avoidEscape: true }], },
{ code: "var foo = <>Hello world</>;", options: ["backtick"], },
{ code: "var foo = <div>Hello world</div>;", options: ["single"], },
{ code: "var foo = <div id=\"foo\"></div>;", options: ["single"], },
{ code: "var foo = <div>Hello world</div>;", options: ["double"], },
{ code: "var foo = <div>Hello world</div>;", options: ["double", { avoidEscape: true }], },
{ code: "var foo = `bar`;", options: ["backtick"], },
{ code: "var foo = `bar 'baz'`;", options: ["backtick"], },
{ code: "var foo = `bar \"baz\"`;", options: ["backtick"], },
{ code: "var foo = <>Hello world</>;", options: ["single"] },
{ code: "var foo = <>Hello world</>;", options: ["double"] },
{ code: "var foo = <>Hello world</>;", options: ["double", { avoidEscape: true }] },
{ code: "var foo = <>Hello world</>;", options: ["backtick"] },
{ code: "var foo = <div>Hello world</div>;", options: ["single"] },
{ code: "var foo = <div id=\"foo\"></div>;", options: ["single"] },
{ code: "var foo = <div>Hello world</div>;", options: ["double"] },
{ code: "var foo = <div>Hello world</div>;", options: ["double", { avoidEscape: true }] },
{ code: "var foo = `bar`;", options: ["backtick"] },
{ code: "var foo = `bar 'baz'`;", options: ["backtick"] },
{ code: "var foo = `bar \"baz\"`;", options: ["backtick"] },
{ code: "var foo = 1;", options: ["backtick"] },
{ code: "var foo = \"a string containing `backtick` quotes\";", options: ["backtick", { avoidEscape: true }] },
{ code: "var foo = <div id=\"foo\"></div>;", options: ["backtick"], },
{ code: "var foo = <div>Hello world</div>;", options: ["backtick"], },
{ code: "var foo = <div id=\"foo\"></div>;", options: ["backtick"] },
{ code: "var foo = <div>Hello world</div>;", options: ["backtick"] },

// Backticks are only okay if they have substitutions, contain a line break, or are tagged
{ code: "var foo = `back\ntick`;", options: ["single"], },
{ code: "var foo = `back\rtick`;", options: ["single"], },
{ code: "var foo = `back\u2028tick`;", options: ["single"], },
{ code: "var foo = `back\u2029tick`;", options: ["single"], },
{ code: "var foo = `back\ntick`;", options: ["single"] },
{ code: "var foo = `back\rtick`;", options: ["single"] },
{ code: "var foo = `back\u2028tick`;", options: ["single"] },
{ code: "var foo = `back\u2029tick`;", options: ["single"] },
{
code: "var foo = `back\\\\\ntick`;", // 2 backslashes followed by a newline
options: ["single"],
options: ["single"]
},
{ code: "var foo = `back\\\\\\\\\ntick`;", options: ["single"], },
{ code: "var foo = `\n`;", options: ["single"], },
{ code: "var foo = `back${x}tick`;", options: ["double"], },
{ code: "var foo = tag`backtick`;", options: ["double"], },
{ code: "var foo = `back\\\\\\\\\ntick`;", options: ["single"] },
{ code: "var foo = `\n`;", options: ["single"] },
{ code: "var foo = `back${x}tick`;", options: ["double"] },
{ code: "var foo = tag`backtick`;", options: ["double"] },

// Backticks are also okay if allowTemplateLiterals
{ code: "var foo = `bar 'foo' baz` + 'bar';", options: ["single", { allowTemplateLiterals: true }], },
{ code: "var foo = `bar 'foo' baz` + \"bar\";", options: ["double", { allowTemplateLiterals: true }], },
{ code: "var foo = `bar 'foo' baz` + `bar`;", options: ["backtick", { allowTemplateLiterals: true }], },
{ code: "var foo = `bar 'foo' baz` + 'bar';", options: ["single", { allowTemplateLiterals: true }] },
{ code: "var foo = `bar 'foo' baz` + \"bar\";", options: ["double", { allowTemplateLiterals: true }] },
{ code: "var foo = `bar 'foo' baz` + `bar`;", options: ["backtick", { allowTemplateLiterals: true }] },

// `backtick` should not warn the directive prologues.
{ code: "\"use strict\"; var foo = `backtick`;", options: ["backtick"], },
{ code: "\"use strict\"; 'use strong'; \"use asm\"; var foo = `backtick`;", options: ["backtick"], },
{ code: "function foo() { \"use strict\"; \"use strong\"; \"use asm\"; var foo = `backtick`; }", options: ["backtick"], },
{ code: "(function() { 'use strict'; 'use strong'; 'use asm'; var foo = `backtick`; })();", options: ["backtick"], },
{ code: "(() => { \"use strict\"; \"use strong\"; \"use asm\"; var foo = `backtick`; })();", options: ["backtick"], },
{ code: "\"use strict\"; var foo = `backtick`;", options: ["backtick"] },
{ code: "\"use strict\"; 'use strong'; \"use asm\"; var foo = `backtick`;", options: ["backtick"] },
{ code: "function foo() { \"use strict\"; \"use strong\"; \"use asm\"; var foo = `backtick`; }", options: ["backtick"] },
{ code: "(function() { 'use strict'; 'use strong'; 'use asm'; var foo = `backtick`; })();", options: ["backtick"] },
{ code: "(() => { \"use strict\"; \"use strong\"; \"use asm\"; var foo = `backtick`; })();", options: ["backtick"] },

// `backtick` should not warn import/export sources.
{ code: "import \"a\"; import 'b';", options: ["backtick"], },
{ code: "import a from \"a\"; import b from 'b';", options: ["backtick"], },
{ code: "export * from \"a\"; export * from 'b';", options: ["backtick"], },
{ code: "import \"a\"; import 'b';", options: ["backtick"] },
{ code: "import a from \"a\"; import b from 'b';", options: ["backtick"] },
{ code: "export * from \"a\"; export * from 'b';", options: ["backtick"] },

// `backtick` should not warn property/method names (not computed).
{ code: "var obj = {\"key0\": 0, 'key1': 1};", options: ["backtick"], },
{ code: "class Foo { 'bar'(){} }", options: ["backtick"], },
{ code: "class Foo { static ''(){} }", options: ["backtick"], }
{ code: "var obj = {\"key0\": 0, 'key1': 1};", options: ["backtick"] },
{ code: "class Foo { 'bar'(){} }", options: ["backtick"] },
{ code: "class Foo { static ''(){} }", options: ["backtick"] }
],
invalid: [
{
Expand Down

0 comments on commit 325f91a

Please sign in to comment.