Skip to content

Commit 1d5a51b

Browse files
committed
chore: use eslint v8 & @eslint-community/eslint-plugin-mysticatea
1 parent be85170 commit 1d5a51b

27 files changed

+298
-206
lines changed

.eslintrc.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
extends:
2-
- plugin:@mysticatea/es2015
3-
- plugin:@mysticatea/+eslint-plugin
2+
- plugin:@eslint-community/mysticatea/es2015
3+
- plugin:@eslint-community/mysticatea/+eslint-plugin
44

55
overrides:
6-
- files: "docs/.vuepress/components/*.vue"
7-
parserOptions:
8-
parser: babel-eslint
9-
106
- files: "lib/rules/*.js"
117
rules:
12-
"@mysticatea/eslint-plugin/require-meta-docs-url":
8+
"@eslint-community/mysticatea/eslint-plugin/require-meta-docs-url":
139
- error
1410
- pattern: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/{{name}}.html"
11+
- files: ["lib/configs.js", "lib/rules.js", "lib/utils.js"]
12+
rules:
13+
"@eslint-community/mysticatea/node/global-require": off
14+
- files: ["tests/**/*.js", "scripts/**/*.js"]
15+
rules:
16+
"@eslint-community/mysticatea/node/global-require": off
17+
"@eslint-community/mysticatea/node/no-sync": off

.github/workflows/CI.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,21 @@ jobs:
4141
matrix.os }})
4242
strategy:
4343
matrix:
44-
eslint: [7]
44+
eslint: [8]
4545
node: [12.22.0, 12, 14.17.0, 14, 16.0.0, 16, 18.0.0, 18]
4646
os: [ubuntu-latest]
4747
include:
4848
# On other platforms
4949
- os: windows-latest
50-
eslint: 7
50+
eslint: 8
5151
node: 18
5252
- os: macos-latest
53-
eslint: 7
53+
eslint: 8
5454
node: 18
5555
# On old ESLint versions
56+
- eslint: 7
57+
node: 18
58+
os: ubuntu-latest
5659
- eslint: 6
5760
node: 18
5861
os: ubuntu-latest

lib/internal/get-linters.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ const needle = `${path.sep}node_modules${path.sep}eslint${path.sep}`
1010
module.exports = () => {
1111
const eslintPaths = new Set(
1212
Object.keys(require.cache)
13-
.filter(id => id.includes(needle))
14-
.map(id => id.slice(0, id.indexOf(needle) + needle.length))
13+
.filter((id) => id.includes(needle))
14+
.map((id) => id.slice(0, id.indexOf(needle) + needle.length))
1515
)
1616
const linters = []
1717

1818
for (const eslintPath of eslintPaths) {
1919
try {
20+
// eslint-disable-next-line @eslint-community/mysticatea/node/global-require
2021
const linter = require(eslintPath).Linter
2122

2223
if (linter) {

lib/internal/utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
const escapeStringRegexp = require("escape-string-regexp")
88
const LINE_PATTERN = /[^\r\n\u2028\u2029]*(?:\r\n|[\r\n\u2028\u2029]|$)/gu
99

10-
const DIRECTIVE_PATTERN = /^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u
10+
const DIRECTIVE_PATTERN =
11+
/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u
1112
const LINE_COMMENT_PATTERN = /^eslint-disable-(next-)?line$/u
1213

1314
module.exports = {

lib/rules/disable-enable-pair.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ module.exports = {
1414
"require a `eslint-enable` comment for every `eslint-disable` comment",
1515
category: "Best Practices",
1616
recommended: true,
17-
url:
18-
"https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/disable-enable-pair.html",
17+
url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/disable-enable-pair.html",
1918
},
2019
fixable: null,
20+
messages: {
21+
missingRulePair:
22+
"Requires 'eslint-enable' directive for '{{ruleId}}'.",
23+
missingPair: "Requires 'eslint-enable' directive.",
24+
},
2125
schema: [
2226
{
2327
type: "object",
@@ -57,9 +61,9 @@ module.exports = {
5761

5862
context.report({
5963
loc: utils.toRuleIdLocation(area.comment, area.ruleId),
60-
message: area.ruleId
61-
? "Requires 'eslint-enable' directive for '{{ruleId}}'."
62-
: "Requires 'eslint-enable' directive.",
64+
messageId: area.ruleId
65+
? "missingRulePair"
66+
: "missingPair",
6367
data: area,
6468
})
6569
}

lib/rules/no-aggregating-enable.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ module.exports = {
1414
"disallow a `eslint-enable` comment for multiple `eslint-disable` comments",
1515
category: "Best Practices",
1616
recommended: true,
17-
url:
18-
"https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-aggregating-enable.html",
17+
url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-aggregating-enable.html",
1918
},
2019
fixable: null,
20+
messages: {
21+
aggregatingEnable:
22+
"This `eslint-enable` comment affects {{count}} `eslint-disable` comments. An `eslint-enable` comment should be for an `eslint-disable` comment.",
23+
},
2124
schema: [],
2225
type: "suggestion",
2326
},
@@ -35,8 +38,7 @@ module.exports = {
3538
if (count >= 2) {
3639
context.report({
3740
loc: utils.toForceLocation(comment.loc),
38-
message:
39-
"This `eslint-enable` comment affects {{count}} `eslint-disable` comments. An `eslint-enable` comment should be for an `eslint-disable` comment.",
41+
messageId: "aggregatingEnable",
4042
data: { count },
4143
})
4244
}

lib/rules/no-duplicate-disable.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ module.exports = {
1313
description: "disallow duplicate `eslint-disable` comments",
1414
category: "Best Practices",
1515
recommended: true,
16-
url:
17-
"https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-duplicate-disable.html",
16+
url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-duplicate-disable.html",
1817
},
1918
fixable: null,
19+
messages: {
20+
duplicateRule: "'{{ruleId}}' rule has been disabled already.",
21+
duplicate: "ESLint rules have been disabled already.",
22+
},
2023
schema: [],
2124
type: "problem",
2225
},
@@ -30,9 +33,7 @@ module.exports = {
3033
for (const item of disabledArea.duplicateDisableDirectives) {
3134
context.report({
3235
loc: utils.toRuleIdLocation(item.comment, item.ruleId),
33-
message: item.ruleId
34-
? "'{{ruleId}}' rule has been disabled already."
35-
: "ESLint rules have been disabled already.",
36+
messageId: item.ruleId ? "duplicateRule" : "duplicate",
3637
data: item,
3738
})
3839
}

lib/rules/no-restricted-disable.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ module.exports = {
1515
"disallow `eslint-disable` comments about specific rules",
1616
category: "Stylistic Issues",
1717
recommended: false,
18-
url:
19-
"https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-restricted-disable.html",
18+
url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-restricted-disable.html",
2019
},
2120
fixable: null,
21+
messages: {
22+
disallow: "Disabling '{{ruleId}}' is not allowed.",
23+
},
2224
schema: {
2325
type: "array",
2426
items: { type: "string" },
@@ -49,7 +51,7 @@ module.exports = {
4951
area.comment,
5052
area.ruleId
5153
),
52-
message: "Disabling '{{ruleId}}' is not allowed.",
54+
messageId: "disallow",
5355
data: {
5456
ruleId: area.ruleId || String(context.options),
5557
},

lib/rules/no-unlimited-disable.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ module.exports = {
1313
"disallow `eslint-disable` comments without rule names",
1414
category: "Best Practices",
1515
recommended: true,
16-
url:
17-
"https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-unlimited-disable.html",
16+
url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-unlimited-disable.html",
1817
},
1918
fixable: null,
19+
messages: {
20+
unexpected:
21+
"Unexpected unlimited '{{kind}}' comment. Specify some rule names to disable.",
22+
},
2023
schema: [],
2124
type: "suggestion",
2225
},
@@ -27,9 +30,8 @@ module.exports = {
2730
return {
2831
Program() {
2932
for (const comment of sourceCode.getAllComments()) {
30-
const directiveComment = utils.parseDirectiveComment(
31-
comment
32-
)
33+
const directiveComment =
34+
utils.parseDirectiveComment(comment)
3335
if (directiveComment == null) {
3436
continue
3537
}
@@ -45,8 +47,7 @@ module.exports = {
4547
if (!directiveComment.value) {
4648
context.report({
4749
loc: utils.toForceLocation(comment.loc),
48-
message:
49-
"Unexpected unlimited '{{kind}}' comment. Specify some rule names to disable.",
50+
messageId: "unexpected",
5051
data: { kind: directiveComment.kind },
5152
})
5253
}

lib/rules/no-unused-disable.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ module.exports = {
1313
description: "disallow unused `eslint-disable` comments",
1414
category: "Best Practices",
1515
recommended: false,
16-
url:
17-
"https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-unused-disable.html",
16+
url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-unused-disable.html",
1817
},
1918
fixable: null,
19+
// eslint-disable-next-line @eslint-community/mysticatea/eslint-plugin/prefer-message-ids
20+
messages: {},
2021
schema: [],
2122
type: "problem",
2223
},

lib/rules/no-unused-enable.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ module.exports = {
1313
description: "disallow unused `eslint-enable` comments",
1414
category: "Best Practices",
1515
recommended: true,
16-
url:
17-
"https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-unused-enable.html",
16+
url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-unused-enable.html",
1817
},
1918
fixable: null,
19+
messages: {
20+
unusedRule:
21+
"'{{ruleId}}' rule is re-enabled but it has not been disabled.",
22+
unused: "ESLint rules are re-enabled but those have not been disabled.",
23+
},
2024
schema: [],
2125
type: "problem",
2226
},
@@ -30,9 +34,7 @@ module.exports = {
3034
for (const item of disabledArea.unusedEnableDirectives) {
3135
context.report({
3236
loc: utils.toRuleIdLocation(item.comment, item.ruleId),
33-
message: item.ruleId
34-
? "'{{ruleId}}' rule is re-enabled but it has not been disabled."
35-
: "ESLint rules are re-enabled but those have not been disabled.",
37+
messageId: item.ruleId ? "unusedRule" : "unused",
3638
data: item,
3739
})
3840
}

lib/rules/no-use.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ module.exports = {
1212
description: "disallow ESLint directive-comments",
1313
category: "Stylistic Issues",
1414
recommended: false,
15-
url:
16-
"https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-use.html",
15+
url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-use.html",
1716
},
1817
fixable: null,
18+
messages: {
19+
disallow: "Unexpected ESLint directive comment.",
20+
},
1921
schema: [
2022
{
2123
type: "object",
@@ -54,17 +56,16 @@ module.exports = {
5456
return {
5557
Program() {
5658
for (const comment of sourceCode.getAllComments()) {
57-
const directiveComment = utils.parseDirectiveComment(
58-
comment
59-
)
59+
const directiveComment =
60+
utils.parseDirectiveComment(comment)
6061
if (directiveComment == null) {
6162
continue
6263
}
6364

6465
if (!allowed.has(directiveComment.kind)) {
6566
context.report({
6667
loc: utils.toForceLocation(comment.loc),
67-
message: "Unexpected ESLint directive comment.",
68+
messageId: "disallow",
6869
})
6970
}
7071
}

lib/rules/require-description.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ module.exports = {
1313
"require include descriptions in ESLint directive-comments",
1414
category: "Stylistic Issues",
1515
recommended: false,
16-
url:
17-
"https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/require-description.html",
16+
url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/require-description.html",
1817
},
1918
fixable: null,
19+
messages: {
20+
missingDescription:
21+
"Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.",
22+
},
2023
schema: [
2124
{
2225
type: "object",
@@ -55,9 +58,8 @@ module.exports = {
5558
return {
5659
Program() {
5760
for (const comment of sourceCode.getAllComments()) {
58-
const directiveComment = utils.parseDirectiveComment(
59-
comment
60-
)
61+
const directiveComment =
62+
utils.parseDirectiveComment(comment)
6163
if (directiveComment == null) {
6264
continue
6365
}
@@ -67,8 +69,7 @@ module.exports = {
6769
if (!directiveComment.description) {
6870
context.report({
6971
loc: utils.toForceLocation(comment.loc),
70-
message:
71-
"Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.",
72+
messageId: "missingDescription",
7273
})
7374
}
7475
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
"ignore": "^5.2.4"
1818
},
1919
"devDependencies": {
20-
"@mysticatea/eslint-plugin": "^13.0.0",
20+
"@eslint-community/eslint-plugin-mysticatea": "^15.3.0",
2121
"@types/node": "^14.18.36",
2222
"@vuepress/plugin-pwa": "^1.9.8",
2323
"babel-eslint": "^10.0.1",
2424
"cross-spawn": "^6.0.5",
25-
"eslint": "^7.32.0",
25+
"eslint": "^8.33.0",
2626
"eslint4b": "^7.32.0",
2727
"fs-extra": "^8.1.0",
2828
"mocha": "^6.2.3",

scripts/lib/rules.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ const path = require("path")
1212
*/
1313
const rules = fs
1414
.readdirSync(path.resolve(__dirname, "../../lib/rules"))
15-
.map(fileName => path.basename(fileName, ".js"))
16-
.map(name => {
15+
.map((fileName) => path.basename(fileName, ".js"))
16+
.map((name) => {
1717
const meta = require(`../../lib/rules/${name}`).meta
1818
return {
1919
id: `@eslint-community/eslint-comments/${name}`,
@@ -29,10 +29,10 @@ const rules = fs
2929

3030
module.exports = rules
3131
module.exports.withCategories = ["Best Practices", "Stylistic Issues"].map(
32-
category => ({
32+
(category) => ({
3333
category,
3434
rules: rules.filter(
35-
rule => rule.category === category && !rule.deprecated
35+
(rule) => rule.category === category && !rule.deprecated
3636
),
3737
})
3838
)

scripts/lib/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ function createIndex(dirPath) {
3232
module.exports = {
3333
${fs
3434
.readdirSync(dirPath)
35-
.map(file => path.basename(file, ".js"))
36-
.map(id => `"${id}": require("./${dirName}/${id}"),`)
35+
.map((file) => path.basename(file, ".js"))
36+
.map((id) => `"${id}": require("./${dirName}/${id}"),`)
3737
.join("\n ")}
3838
}
3939
`)

scripts/update-docs-headers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ for (const rule of rules) {
1919
if (rule.deprecated) {
2020
headerLines.push(
2121
`- ⚠️ This rule was **deprecated** and replaced by ${rule.replacedBy
22-
.map(id => `[${id}](${id}.md) rule`)
22+
.map((id) => `[${id}](${id}.md) rule`)
2323
.join(", ")}.`
2424
)
2525
} else if (rule.recommended) {

0 commit comments

Comments
 (0)