Skip to content

Commit

Permalink
chore: update to @eslint-community/eslint-plugin-mysticatea (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDeBoey committed Jul 31, 2023
1 parent e006c94 commit ffb4682
Show file tree
Hide file tree
Showing 21 changed files with 99 additions and 86 deletions.
15 changes: 12 additions & 3 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extends:
- plugin:@mysticatea/es2015
- plugin:@mysticatea/+eslint-plugin
- plugin:@eslint-community/mysticatea/es2015
- plugin:@eslint-community/mysticatea/+eslint-plugin

overrides:
- files: "docs/.vuepress/components/*.vue"
Expand All @@ -9,6 +9,15 @@ overrides:

- files: "lib/rules/*.js"
rules:
"@mysticatea/eslint-plugin/require-meta-docs-url":
"@eslint-community/mysticatea/eslint-plugin/require-meta-docs-url":
- error
- pattern: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/{{name}}.html"

- files: ["lib/configs.js", "lib/rules.js", "lib/utils.js"]
rules:
"@eslint-community/mysticatea/node/global-require": off

- files: ["tests/**/*.js", "scripts/**/*.js"]
rules:
"@eslint-community/mysticatea/node/global-require": off
"@eslint-community/mysticatea/node/no-sync": off
5 changes: 3 additions & 2 deletions lib/internal/get-linters.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ const needle = `${path.sep}node_modules${path.sep}eslint${path.sep}`
module.exports = () => {
const eslintPaths = new Set(
Object.keys(require.cache)
.filter(id => id.includes(needle))
.map(id => id.slice(0, id.indexOf(needle) + needle.length))
.filter((id) => id.includes(needle))
.map((id) => id.slice(0, id.indexOf(needle) + needle.length))
)
const linters = []

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

if (linter) {
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
const escapeStringRegexp = require("escape-string-regexp")
const LINE_PATTERN = /[^\r\n\u2028\u2029]*(?:\r\n|[\r\n\u2028\u2029]|$)/gu

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

module.exports = {
Expand Down
14 changes: 9 additions & 5 deletions lib/rules/disable-enable-pair.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ module.exports = {
"require a `eslint-enable` comment for every `eslint-disable` comment",
category: "Best Practices",
recommended: true,
url:
"https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/disable-enable-pair.html",
url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/disable-enable-pair.html",
},
fixable: null,
messages: {
missingPair: "Requires 'eslint-enable' directive.",
missingRulePair:
"Requires 'eslint-enable' directive for '{{ruleId}}'.",
},
schema: [
{
type: "object",
Expand Down Expand Up @@ -57,9 +61,9 @@ module.exports = {

context.report({
loc: utils.toRuleIdLocation(area.comment, area.ruleId),
message: area.ruleId
? "Requires 'eslint-enable' directive for '{{ruleId}}'."
: "Requires 'eslint-enable' directive.",
messageId: area.ruleId
? "missingRulePair"
: "missingPair",
data: area,
})
}
Expand Down
10 changes: 6 additions & 4 deletions lib/rules/no-aggregating-enable.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ module.exports = {
"disallow a `eslint-enable` comment for multiple `eslint-disable` comments",
category: "Best Practices",
recommended: true,
url:
"https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-aggregating-enable.html",
url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-aggregating-enable.html",
},
fixable: null,
messages: {
aggregatingEnable:
"This `eslint-enable` comment affects {{count}} `eslint-disable` comments. An `eslint-enable` comment should be for an `eslint-disable` comment.",
},
schema: [],
type: "suggestion",
},
Expand All @@ -35,8 +38,7 @@ module.exports = {
if (count >= 2) {
context.report({
loc: utils.toForceLocation(comment.loc),
message:
"This `eslint-enable` comment affects {{count}} `eslint-disable` comments. An `eslint-enable` comment should be for an `eslint-disable` comment.",
messageId: "aggregatingEnable",
data: { count },
})
}
Expand Down
11 changes: 6 additions & 5 deletions lib/rules/no-duplicate-disable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ module.exports = {
description: "disallow duplicate `eslint-disable` comments",
category: "Best Practices",
recommended: true,
url:
"https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-duplicate-disable.html",
url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-duplicate-disable.html",
},
fixable: null,
messages: {
duplicate: "ESLint rules have been disabled already.",
duplicateRule: "'{{ruleId}}' rule has been disabled already.",
},
schema: [],
type: "problem",
},
Expand All @@ -30,9 +33,7 @@ module.exports = {
for (const item of disabledArea.duplicateDisableDirectives) {
context.report({
loc: utils.toRuleIdLocation(item.comment, item.ruleId),
message: item.ruleId
? "'{{ruleId}}' rule has been disabled already."
: "ESLint rules have been disabled already.",
messageId: item.ruleId ? "duplicateRule" : "duplicate",
data: item,
})
}
Expand Down
8 changes: 5 additions & 3 deletions lib/rules/no-restricted-disable.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ module.exports = {
"disallow `eslint-disable` comments about specific rules",
category: "Stylistic Issues",
recommended: false,
url:
"https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-restricted-disable.html",
url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-restricted-disable.html",
},
fixable: null,
messages: {
disallow: "Disabling '{{ruleId}}' is not allowed.",
},
schema: {
type: "array",
items: { type: "string" },
Expand Down Expand Up @@ -49,7 +51,7 @@ module.exports = {
area.comment,
area.ruleId
),
message: "Disabling '{{ruleId}}' is not allowed.",
messageId: "disallow",
data: {
ruleId: area.ruleId || String(context.options),
},
Expand Down
15 changes: 8 additions & 7 deletions lib/rules/no-unlimited-disable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ module.exports = {
"disallow `eslint-disable` comments without rule names",
category: "Best Practices",
recommended: true,
url:
"https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-unlimited-disable.html",
url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-unlimited-disable.html",
},
fixable: null,
messages: {
unexpected:
"Unexpected unlimited '{{kind}}' comment. Specify some rule names to disable.",
},
schema: [],
type: "suggestion",
},
Expand All @@ -27,9 +30,8 @@ module.exports = {
return {
Program() {
for (const comment of sourceCode.getAllComments()) {
const directiveComment = utils.parseDirectiveComment(
comment
)
const directiveComment =
utils.parseDirectiveComment(comment)
if (directiveComment == null) {
continue
}
Expand All @@ -45,8 +47,7 @@ module.exports = {
if (!directiveComment.value) {
context.report({
loc: utils.toForceLocation(comment.loc),
message:
"Unexpected unlimited '{{kind}}' comment. Specify some rule names to disable.",
messageId: "unexpected",
data: { kind: directiveComment.kind },
})
}
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/no-unused-disable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ module.exports = {
description: "disallow unused `eslint-disable` comments",
category: "Best Practices",
recommended: false,
url:
"https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-unused-disable.html",
url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-unused-disable.html",
},
fixable: null,
// eslint-disable-next-line @eslint-community/mysticatea/eslint-plugin/prefer-message-ids
messages: {},
schema: [],
type: "problem",
},
Expand Down
12 changes: 7 additions & 5 deletions lib/rules/no-unused-enable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ module.exports = {
description: "disallow unused `eslint-enable` comments",
category: "Best Practices",
recommended: true,
url:
"https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-unused-enable.html",
url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-unused-enable.html",
},
fixable: null,
messages: {
unused: "ESLint rules are re-enabled but those have not been disabled.",
unusedRule:
"'{{ruleId}}' rule is re-enabled but it has not been disabled.",
},
schema: [],
type: "problem",
},
Expand All @@ -30,9 +34,7 @@ module.exports = {
for (const item of disabledArea.unusedEnableDirectives) {
context.report({
loc: utils.toRuleIdLocation(item.comment, item.ruleId),
message: item.ruleId
? "'{{ruleId}}' rule is re-enabled but it has not been disabled."
: "ESLint rules are re-enabled but those have not been disabled.",
messageId: item.ruleId ? "unusedRule" : "unused",
data: item,
})
}
Expand Down
13 changes: 7 additions & 6 deletions lib/rules/no-use.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ module.exports = {
description: "disallow ESLint directive-comments",
category: "Stylistic Issues",
recommended: false,
url:
"https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-use.html",
url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-use.html",
},
fixable: null,
messages: {
disallow: "Unexpected ESLint directive comment.",
},
schema: [
{
type: "object",
Expand Down Expand Up @@ -54,17 +56,16 @@ module.exports = {
return {
Program() {
for (const comment of sourceCode.getAllComments()) {
const directiveComment = utils.parseDirectiveComment(
comment
)
const directiveComment =
utils.parseDirectiveComment(comment)
if (directiveComment == null) {
continue
}

if (!allowed.has(directiveComment.kind)) {
context.report({
loc: utils.toForceLocation(comment.loc),
message: "Unexpected ESLint directive comment.",
messageId: "disallow",
})
}
}
Expand Down
15 changes: 8 additions & 7 deletions lib/rules/require-description.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ module.exports = {
"require include descriptions in ESLint directive-comments",
category: "Stylistic Issues",
recommended: false,
url:
"https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/require-description.html",
url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/require-description.html",
},
fixable: null,
messages: {
missingDescription:
"Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.",
},
schema: [
{
type: "object",
Expand Down Expand Up @@ -55,9 +58,8 @@ module.exports = {
return {
Program() {
for (const comment of sourceCode.getAllComments()) {
const directiveComment = utils.parseDirectiveComment(
comment
)
const directiveComment =
utils.parseDirectiveComment(comment)
if (directiveComment == null) {
continue
}
Expand All @@ -67,8 +69,7 @@ module.exports = {
if (!directiveComment.description) {
context.report({
loc: utils.toForceLocation(comment.loc),
message:
"Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.",
messageId: "missingDescription",
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"ignore": "^5.2.4"
},
"devDependencies": {
"@mysticatea/eslint-plugin": "^13.0.0",
"@eslint-community/eslint-plugin-mysticatea": "^15.5.1",
"@types/node": "^14.18.36",
"@vuepress/plugin-pwa": "^1.9.8",
"babel-eslint": "^10.0.1",
Expand Down
8 changes: 4 additions & 4 deletions scripts/lib/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const path = require("path")
*/
const rules = fs
.readdirSync(path.resolve(__dirname, "../../lib/rules"))
.map(fileName => path.basename(fileName, ".js"))
.map(name => {
.map((fileName) => path.basename(fileName, ".js"))
.map((name) => {
const meta = require(`../../lib/rules/${name}`).meta
return {
id: `@eslint-community/eslint-comments/${name}`,
Expand All @@ -29,10 +29,10 @@ const rules = fs

module.exports = rules
module.exports.withCategories = ["Best Practices", "Stylistic Issues"].map(
category => ({
(category) => ({
category,
rules: rules.filter(
rule => rule.category === category && !rule.deprecated
(rule) => rule.category === category && !rule.deprecated
),
})
)
4 changes: 2 additions & 2 deletions scripts/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ function createIndex(dirPath) {
module.exports = {
${fs
.readdirSync(dirPath)
.map(file => path.basename(file, ".js"))
.map(id => `"${id}": require("./${dirName}/${id}"),`)
.map((file) => path.basename(file, ".js"))
.map((id) => `"${id}": require("./${dirName}/${id}"),`)
.join("\n ")}
}
`)
Expand Down
2 changes: 1 addition & 1 deletion scripts/update-docs-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ for (const rule of rules) {
if (rule.deprecated) {
headerLines.push(
`- ⚠️ This rule was **deprecated** and replaced by ${rule.replacedBy
.map(id => `[${id}](${id}.md) rule`)
.map((id) => `[${id}](${id}.md) rule`)
.join(", ")}.`
)
} else if (rule.recommended) {
Expand Down
4 changes: 2 additions & 2 deletions scripts/update-recommended-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ module.exports = {
plugins: ["@eslint-community/eslint-comments"],
rules: {
${rules
.filter(rule => rule.recommended)
.map(rule => `"${rule.id}": "error",`)
.filter((rule) => rule.recommended)
.map((rule) => `"${rule.id}": "error",`)
.join("\n ")}
},
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ for (const dirPath of [
path.resolve(__dirname, "../lib/rules"),
path.resolve(__dirname, "../lib/utils"),
]) {
createIndex(dirPath).then(content =>
createIndex(dirPath).then((content) =>
fs.writeFileSync(`${dirPath}.js`, content)
)
}
Loading

0 comments on commit ffb4682

Please sign in to comment.