Skip to content

Commit

Permalink
feat: support ESLint 8.x
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Requires Node@^12.22.0 || ^14.17.0 || >=16.0.0
BREAKING CHANGE: Requires ESLint@^8.0.0
  • Loading branch information
MichaelDeBoey committed Oct 30, 2021
1 parent f9c4c6b commit 43cd406
Show file tree
Hide file tree
Showing 20 changed files with 84 additions and 105 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/CI.yml
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
eslint: [7]
eslint: [8]
node: [16]
include:
# On other platforms
Expand All @@ -26,10 +26,8 @@ jobs:
os: ubuntu-latest
- node: 12
os: ubuntu-latest
- node: 10
os: ubuntu-latest
# On the minimum supported ESLint/Node.js version
- node: 10.12.0
- node: 12.22.0
os: ubuntu-latest

runs-on: ${{ matrix.os }}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -16,8 +16,8 @@ npm install --save-dev eslint @mysticatea/eslint-plugin

### Requirements

- Node.js `^10.12.0 || >=12.0.0` or newer versions.
- ESLint `^7.0.0` or newer versions.
- Node.js `^12.22.0 || ^14.17.0 || >=16.0.0` or newer versions.
- ESLint `^8.0.0` or newer versions.

## 📖 Usage

Expand Down
5 changes: 1 addition & 4 deletions lib/configs/_override-vue.js
Expand Up @@ -77,10 +77,7 @@ module.exports = {
"error",
{
singleline: 3,
multiline: {
max: 1,
allowFirstLine: false,
},
multiline: 1,
},
],
"@mysticatea/vue/max-len": ["error", { tabWidth: 4 }],
Expand Down
2 changes: 1 addition & 1 deletion lib/processors/vue.js
Expand Up @@ -22,7 +22,7 @@ module.exports = {
}

// Filter messages which are in disabled area.
return messages[0].filter(message => {
return messages[0].filter((message) => {
if (message.ruleId === "@mysticatea/vue/comment-directive") {
const rules = message.message.split(" ")
const type = rules.shift()
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/arrow-parens.js
Expand Up @@ -30,8 +30,7 @@ module.exports = {
description: "enforce the parentheses style of arrow functions.",
category: "Stylistic Issues",
recommended: false,
url:
"https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/arrow-parens.md",
url: "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/arrow-parens.md",
},
fixable: "code",
schema: [],
Expand Down
9 changes: 5 additions & 4 deletions lib/rules/block-scoped-var.js
Expand Up @@ -9,8 +9,10 @@
// Helpers
//------------------------------------------------------------------------------

const scopeNodeType = /^(?:(?:Block|Switch|For(?:In|Of)?)Statement|CatchClause|Program)$/u
const containerNodeType = /^(?:For(?:In|Of)?Statement|(?:Arrow)?Function(?:Declaration|Expression))$/u
const scopeNodeType =
/^(?:(?:Block|Switch|For(?:In|Of)?)Statement|CatchClause|Program)$/u
const containerNodeType =
/^(?:For(?:In|Of)?Statement|(?:Arrow)?Function(?:Declaration|Expression))$/u

/**
* Checks whether or not a given definition should be skipped.
Expand Down Expand Up @@ -196,8 +198,7 @@ module.exports = {
description: "disallow illegal usage of variables as block-scoped.",
category: "Possible Errors",
recommended: false,
url:
"https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/block-scoped-var.md",
url: "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/block-scoped-var.md",
},
fixable: null,
schema: [],
Expand Down
5 changes: 2 additions & 3 deletions lib/rules/no-instanceof-array.js
Expand Up @@ -14,8 +14,7 @@ module.exports = {
docs: {
description: "disallow 'instanceof' for Array",
category: "Best Practices",
url:
"https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-instanceof-array.md",
url: "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-instanceof-array.md",
},
fixable: "code",
schema: [],
Expand Down Expand Up @@ -64,7 +63,7 @@ module.exports = {
loc: node.loc,
message:
"Unexpected 'instanceof' operator. Use 'Array.isArray' instead.",
fix: fixer =>
fix: (fixer) =>
fixer.replaceText(
node,
`Array.isArray(${sourceCode.getText(
Expand Down
5 changes: 2 additions & 3 deletions lib/rules/no-instanceof-wrapper.js
Expand Up @@ -14,8 +14,7 @@ module.exports = {
docs: {
description: "disallow 'instanceof' for wrapper objects",
category: "Best Practices",
url:
"https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-instanceof-wrapper.md",
url: "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-instanceof-wrapper.md",
},
fixable: "code",
schema: [],
Expand Down Expand Up @@ -76,7 +75,7 @@ module.exports = {
message:
"Unexpected 'instanceof' operator. Use 'typeof x === \"{{typeName}}\"' instead.",
data: { typeName },
fix: fixer =>
fix: (fixer) =>
fixer.replaceText(
node,
`typeof ${sourceCode.getText(
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/no-literal-call.js
Expand Up @@ -9,7 +9,8 @@
//------------------------------------------------------------------------------

const LITERAL_TYPE = /^(?:(?:Array|Object)Expression|(?:Template)?Literal)$/u
const LITERAL_AND_CLASS_TYPE = /^(?:(?:Array|Class|Object)Expression|(?:Template)?Literal)$/u
const LITERAL_AND_CLASS_TYPE =
/^(?:(?:Array|Class|Object)Expression|(?:Template)?Literal)$/u

//------------------------------------------------------------------------------
// Rule Definition
Expand All @@ -21,8 +22,7 @@ module.exports = {
description: "disallow a call of a literal.",
category: "Possible Errors",
recommended: false,
url:
"https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-literal-call.md",
url: "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-literal-call.md",
},
fixable: null,
schema: [],
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-this-in-static.js
Expand Up @@ -14,8 +14,7 @@ module.exports = {
docs: {
description: "disallow `this`/`super` in static methods",
category: "Best Practices",
url:
"https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-this-in-static.md",
url: "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-this-in-static.md",
},
fixable: null,
schema: [],
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-use-ignored-vars.js
Expand Up @@ -20,8 +20,7 @@ module.exports = {
description: "disallow a use of ignored variables.",
category: "Stylistic Issues",
recommended: false,
url:
"https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-use-ignored-vars.md",
url: "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-use-ignored-vars.md",
},
fixable: null,
schema: [{ type: "string" }],
Expand Down
10 changes: 5 additions & 5 deletions lib/rules/no-useless-rest-spread.js
Expand Up @@ -8,7 +8,8 @@
// Helpers
//------------------------------------------------------------------------------

const FUNC_TYPE = /^(?:FunctionDeclaration|(?:New|Call|(?:Arrow)?Function)Expression)$/u
const FUNC_TYPE =
/^(?:FunctionDeclaration|(?:New|Call|(?:Arrow)?Function)Expression)$/u
const PROPERTY_PATTERN = /^(?:Experimental)?(Rest|Spread)Property$/u

/**
Expand Down Expand Up @@ -56,7 +57,7 @@ function getLastElementToken(sourceCode, node) {
* @returns {function} A fixer function.
*/
function defineFixer(sourceCode, node) {
return fixer => {
return (fixer) => {
const child = node.argument

// If the inner array includes holes, do nothing.
Expand Down Expand Up @@ -97,8 +98,7 @@ module.exports = {
description: "disallow unnecessary spread operators.",
category: "Best Practices",
recommended: false,
url:
"https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-useless-rest-spread.md",
url: "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/no-useless-rest-spread.md",
},
fixable: "code",
schema: [],
Expand All @@ -116,7 +116,7 @@ module.exports = {
function verify(node) {
const nodeType = node.type.replace(
PROPERTY_PATTERN,
t => `${t}Element`
(t) => `${t}Element`
)
const parentType = node.parent.type
const argumentType = node.argument.type
Expand Down
10 changes: 5 additions & 5 deletions lib/rules/prefer-for-of.js
Expand Up @@ -243,7 +243,7 @@ function isIndexVarOnlyUsedToGetArrayElements(context, node) {
const arrayText = getArrayTextOfForStatement(sourceCode, node)
const indexVar = context.getDeclaredVariables(node.init)[0]

return indexVar.references.every(reference => {
return indexVar.references.every((reference) => {
const id = reference.identifier

return (
Expand Down Expand Up @@ -273,7 +273,8 @@ function isLengthVarOnlyUsedToTest(context, node) {
const lengthVar = context.getDeclaredVariables(node.init.declarations[1])[0]

return lengthVar.references.every(
reference => reference.init || contains(node.test, reference.identifier)
(reference) =>
reference.init || contains(node.test, reference.identifier)
)
}

Expand Down Expand Up @@ -497,8 +498,7 @@ module.exports = {
description: "requires for-of statements instead of Array#forEach",
category: "Best Practices",
recommended: false,
url:
"https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/prefer-for-of.md",
url: "https://github.com/mysticatea/eslint-plugin/blob/v13.0.0/docs/rules/prefer-for-of.md",
},
fixable: "code",
schema: [],
Expand Down Expand Up @@ -580,7 +580,7 @@ module.exports = {
if (
thisFuncInfo != null &&
thisFuncInfo.isTarget &&
!thisFuncInfo.returnNodes.some(returnNode =>
!thisFuncInfo.returnNodes.some((returnNode) =>
contains(returnNode, node)
)
) {
Expand Down
22 changes: 11 additions & 11 deletions package.json
Expand Up @@ -3,31 +3,31 @@
"version": "13.0.0",
"description": "Additional ESLint rules.",
"engines": {
"node": "^10.12.0 || >=12.0.0"
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
"main": "index.js",
"files": [
"lib"
],
"peerDependencies": {
"eslint": "^7.0.0"
"eslint": "^8.0.0"
},
"dependencies": {
"@eslint/eslintrc": "^0.4.3",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"@eslint/eslintrc": "^1.0.3",
"@typescript-eslint/eslint-plugin": "^5.2.0",
"@typescript-eslint/parser": "^5.2.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-eslint-plugin": "^3.6.1",
"eslint-plugin-eslint-plugin": "^4.0.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.1",
"eslint-plugin-vue": "^7.19.1",
"prettier": "^1.19.1",
"vue-eslint-parser": "^7.11.0"
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-vue": "^8.0.3",
"prettier": "^2.4.1",
"vue-eslint-parser": "^8.0.1"
},
"devDependencies": {
"@mysticatea/eslint-plugin": "file:.",
"codecov": "^3.6.1",
"eslint": "^7.32.0",
"eslint": "^8.1.0",
"fs-extra": "^8.1.0",
"globals": "^12.1.1",
"mocha": "^6.2.2",
Expand Down
7 changes: 3 additions & 4 deletions scripts/generate-browser-globals.js
Expand Up @@ -6,7 +6,7 @@

const fs = require("fs")
const path = require("path")
const { CLIEngine } = require("eslint")
const { ESLint } = require("eslint")
const { browser: originalGlobals } = require("globals")

const targetFile = path.resolve(__dirname, "../lib/configs/_browser-globals.js")
Expand All @@ -33,7 +33,7 @@ for (const key of Object.keys(originalGlobals).sort()) {
}
}

const linter = new CLIEngine({ fix: true })
const linter = new ESLint({ fix: true })
const rawCode = `/**
* DON'T EDIT THIS FILE WHICH WAS GENERATED BY './scripts/generate-browser-globals.js'.
*/
Expand All @@ -42,7 +42,6 @@ const rawCode = `/**
module.exports = ${JSON.stringify(globals, null, 4)}
`
const code =
linter.executeOnText(rawCode, "_browser-globals.js").results[0].output ||
rawCode
linter.lintText(rawCode, "_browser-globals.js").results[0].output || rawCode

fs.writeFileSync(targetFile, code)
14 changes: 7 additions & 7 deletions scripts/generate-configs.js
Expand Up @@ -6,7 +6,7 @@

const fs = require("fs")
const path = require("path")
const { CLIEngine } = require("eslint")
const { ESLint } = require("eslint")

const targetFile = path.resolve(__dirname, "../lib/configs.js")

Expand All @@ -20,14 +20,14 @@ fs.writeFileSync(
module.exports = {
${fs
.readdirSync(path.resolve(__dirname, "../lib/configs"))
.map(fileName => path.basename(fileName, ".js"))
.filter(id => !id.startsWith("_"))
.map(id => ` "${id}": require("./configs/${id}"),`)
.map((fileName) => path.basename(fileName, ".js"))
.filter((id) => !id.startsWith("_"))
.map((id) => ` "${id}": require("./configs/${id}"),`)
.join("\n")}
}
`
)

const linter = new CLIEngine({ fix: true })
const result = linter.executeOnFiles([targetFile])
CLIEngine.outputFixes(result)
const linter = new ESLint({ fix: true })
const result = linter.lintFiles([targetFile])
ESLint.outputFixes(result)
16 changes: 8 additions & 8 deletions scripts/generate-rules.js
Expand Up @@ -6,7 +6,7 @@

const fs = require("fs")
const path = require("path")
const { CLIEngine } = require("eslint")
const { ESLint } = require("eslint")

const targetFile = path.resolve(__dirname, "../lib/rules.js")

Expand All @@ -20,20 +20,20 @@ fs.writeFileSync(
module.exports = Object.assign(
${fs
.readdirSync(path.resolve(__dirname, "../lib/foreign-rules"))
.map(fileName => path.basename(fileName, ".js"))
.map(id => ` require("./foreign-rules/${id}"),`)
.map((fileName) => path.basename(fileName, ".js"))
.map((id) => ` require("./foreign-rules/${id}"),`)
.join("\n")}
{
${fs
.readdirSync(path.resolve(__dirname, "../lib/rules"))
.map(fileName => path.basename(fileName, ".js"))
.map(id => ` "${id}": require("./rules/${id}"),`)
.map((fileName) => path.basename(fileName, ".js"))
.map((id) => ` "${id}": require("./rules/${id}"),`)
.join("\n")}
}
)
`
)

const linter = new CLIEngine({ fix: true })
const result = linter.executeOnFiles([targetFile])
CLIEngine.outputFixes(result)
const linter = new ESLint({ fix: true })
const result = linter.lintFiles([targetFile])
ESLint.outputFixes(result)

0 comments on commit 43cd406

Please sign in to comment.