From 455c00a3bee48b7741915ec1b739d1fa89aac170 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Fri, 21 Jun 2024 11:30:40 +0900 Subject: [PATCH] chore: use eslint v9 (#333) * chore: use eslint v9 * fix --- .devcontainer/devcontainer.json | 40 +-- .eslintignore | 15 - .eslintrc.js | 215 ------------ .github/workflows/NodeCI.yml | 22 +- .prettierrc.json | 2 +- .../components/EslintPluginEditor.vue | 84 +++-- .../components/components/RulesSettings.vue | 2 +- .../theme/components/playground-block.vue | 7 +- .../theme/components/rules/index.js | 7 +- eslint.config.mjs | 323 ++++++++++++++++++ package.json | 13 +- src/rules/no-invalid.ts | 7 +- src/utils/ast/js/index.ts | 2 +- src/utils/ast/js/utils.ts | 2 +- src/utils/validator-factory.ts | 2 - tests/fixtures/.eslintrc.js | 23 -- tests/src/rules/no-invalid.ts | 2 + tests/src/utils/ast/js.ts | 2 +- tests/utils/utils.ts | 2 +- tools/render-rules.ts | 6 +- tools/update-docs.ts | 6 +- 21 files changed, 427 insertions(+), 357 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc.js create mode 100644 eslint.config.mjs delete mode 100644 tests/fixtures/.eslintrc.js diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 64e2886b..5e941f28 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,31 +1,27 @@ // For format details, see https://aka.ms/devcontainer.json. For config options, see the // README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node { - "name": "Node.js & TypeScript", - // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/devcontainers/typescript-node:1-20-bullseye", + "name": "Node.js & TypeScript", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/typescript-node:1-20-bullseye", - // Features to add to the dev container. More info: https://containers.dev/features. - // "features": {}, + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], - // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "yarn install", + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "yarn install", - // Configure tool-specific properties. - "customizations": { - // Configure properties specific to VS Code. - "vscode": { - // Set *default* container specific settings.json values on container create. - "settings": {}, - "extensions": [ - "dbaeumer.vscode-eslint" - ] - } - } + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + "extensions": ["dbaeumer.vscode-eslint"] + } + } - // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. - // "remoteUser": "root" + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" } diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 1765974f..00000000 --- a/.eslintignore +++ /dev/null @@ -1,15 +0,0 @@ -/.cached_schemastore -/.nyc_output -/coverage -/dist -!/docs/.vitepress -/docs/.vitepress/dist -/docs/.vitepress/cache -/docs/.vitepress/build-system/shim -/lib -/node_modules -/schemastore -/tests/fixtures/integrations -/assets -!/.github -!/.vscode diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 3778c720..00000000 --- a/.eslintrc.js +++ /dev/null @@ -1,215 +0,0 @@ -"use strict"; - -// const version = require("./package.json").version - -module.exports = { - parserOptions: { - sourceType: "script", - ecmaVersion: "latest", - project: require.resolve("./tsconfig.json"), - }, - extends: [ - "plugin:@ota-meshi/recommended", - "plugin:@ota-meshi/+node", - "plugin:@ota-meshi/+typescript", - "plugin:@ota-meshi/+eslint-plugin", - "plugin:@ota-meshi/+vue3", - "plugin:@ota-meshi/+package-json", - "plugin:@ota-meshi/+json", - "plugin:@ota-meshi/+yaml", - "plugin:@ota-meshi/+toml", - "plugin:@ota-meshi/+md", - "plugin:@ota-meshi/+prettier", - ], - rules: { - "one-var": "off", - "eslint-comments/no-unused-disable": "error", - "require-jsdoc": "error", - "no-warning-comments": "warn", - "no-lonely-if": "off", - "new-cap": "off", - "no-shadow": "off", - - // Repo rule - "no-restricted-imports": [ - "error", - { - patterns: [ - { - group: ["/regexpp", "/regexpp/*"], - message: "Please use `@eslint-community/regexpp` instead.", - }, - { - group: ["/eslint-utils", "/eslint-utils/*"], - message: "Please use `@eslint-community/eslint-utils` instead.", - }, - ], - }, - ], - "no-restricted-properties": [ - "error", - { - object: "context", - property: "getSourceCode", - message: - "Please use `eslint-compat-utils` module's `getSourceCode(context).getScope()` instead.", - }, - { - object: "context", - property: "sourceCode", - message: - "Please use `eslint-compat-utils` module's `getSourceCode(context).getScope()` instead.", - }, - { - object: "context", - property: "getFilename", - message: - "Please use `eslint-compat-utils` module's `getFilename(context)` instead.", - }, - { - object: "context", - property: "filename", - message: - "Please use `eslint-compat-utils` module's `getFilename(context)` instead.", - }, - { - object: "context", - property: "getCwd", - message: - "Please use `eslint-compat-utils` module's `getCwd(context)` instead.", - }, - { - object: "context", - property: "cwd", - message: - "Please use `eslint-compat-utils` module's `getCwd(context)` instead.", - }, - { - object: "context", - property: "getScope", - message: - "Please use `eslint-compat-utils` module's `getSourceCode(context).getScope()` instead.", - }, - { - object: "context", - property: "parserServices", - message: - "Please use `eslint-compat-utils` module's `getSourceCode(context).parserServices` instead.", - }, - ], - }, - overrides: [ - { - files: ["*.ts", "*.mts"], - parser: "@typescript-eslint/parser", - parserOptions: { - sourceType: "module", - project: require.resolve("./tsconfig.json"), - }, - rules: { - "@typescript-eslint/naming-convention": [ - "error", - { - selector: "default", - format: ["camelCase"], - leadingUnderscore: "allow", - trailingUnderscore: "allow", - }, - { - selector: "variable", - format: ["camelCase", "UPPER_CASE"], - leadingUnderscore: "allow", - trailingUnderscore: "allow", - }, - { - selector: "typeLike", - format: ["PascalCase"], - }, - { - selector: "property", - format: null, - }, - { - selector: "method", - format: null, - }, - { - selector: "import", - format: null, - }, - ], - "@typescript-eslint/no-non-null-assertion": "off", - }, - }, - { - files: ["tests/fixtures/**"], - rules: { - "json-schema-validator/no-invalid": "off", - }, - }, - { - files: ["scripts/**/*.ts", "tests/**/*.ts"], - parser: "@typescript-eslint/parser", - parserOptions: { - sourceType: "module", - project: require.resolve("./tsconfig.json"), - }, - rules: { - "require-jsdoc": "off", - "no-console": "off", - "@typescript-eslint/no-misused-promises": "off", - }, - }, - { - files: ["*.vue"], - parserOptions: { - sourceType: "module", - }, - globals: { - require: true, - }, - }, - { - files: ["docs/.vitepress/**/*.*", "docs/.vitepress/*.*"], - extends: ["plugin:@typescript-eslint/disable-type-checked"], - parserOptions: { - sourceType: "module", - ecmaVersion: 2020, - }, - globals: { - window: true, - }, - rules: { - "require-jsdoc": "off", - "eslint-plugin/require-meta-docs-description": "off", - "eslint-plugin/require-meta-docs-url": "off", - "eslint-plugin/require-meta-type": "off", - "eslint-plugin/prefer-message-ids": "off", - "eslint-plugin/prefer-object-rule": "off", - "eslint-plugin/require-meta-schema": "off", - "n/no-extraneous-import": "off", - }, - }, - { - files: ["docs/.vitepress/**/*.ts", "docs/.vitepress/**/*.mts"], - parserOptions: { - project: null, - }, - }, - { - files: ["*.mjs"], - parserOptions: { - sourceType: "module", - }, - }, - { - files: ["*.md/**", "**/*.md/**"], - parserOptions: { - sourceType: "module", - }, - rules: { - "n/no-missing-import": "off", - }, - }, - ], -}; diff --git a/.github/workflows/NodeCI.yml b/.github/workflows/NodeCI.yml index 842f74b4..97dc6529 100644 --- a/.github/workflows/NodeCI.yml +++ b/.github/workflows/NodeCI.yml @@ -21,16 +21,12 @@ jobs: test: strategy: matrix: - node-version: [14.x, 16.x, 18.x, 19.x] + node-version: [18.x, 20.x] os: [ubuntu-latest] include: - - node: 18.x + - node: 22.x os: windows-latest - - node: 18.x - os: macos-latest - - node: 14.x - os: windows-latest - - node: 14.x + - node: 22.x os: macos-latest runs-on: ${{ matrix.os }} steps: @@ -43,14 +39,20 @@ jobs: run: yarn install --ignore-engines - name: Test run: yarn test - test-with-eslint9: + test-with-eslint8: runs-on: ubuntu-latest + strategy: + matrix: + node-version: [14.x, 16.x] steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} - name: Install Target Packages run: |+ - yarn add -D eslint@^9.0.0-0 --ignore-engines + yarn add -D eslint@8 --ignore-engines yarn --ignore-engines - name: Test run: yarn test diff --git a/.prettierrc.json b/.prettierrc.json index 9e26dfee..0967ef42 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1 +1 @@ -{} \ No newline at end of file +{} diff --git a/docs/.vitepress/theme/components/components/EslintPluginEditor.vue b/docs/.vitepress/theme/components/components/EslintPluginEditor.vue index 383ed346..aa1850a6 100644 --- a/docs/.vitepress/theme/components/components/EslintPluginEditor.vue +++ b/docs/.vitepress/theme/components/components/EslintPluginEditor.vue @@ -97,42 +97,49 @@ export default { : "espree"; }, config() { - return { - globals: { - // Node - module: false, - // ES2015 globals - ArrayBuffer: false, - DataView: false, - Float32Array: false, - Float64Array: false, - Int16Array: false, - Int32Array: false, - Int8Array: false, - Map: false, - Promise: false, - Proxy: false, - Reflect: false, - Set: false, - Symbol: false, - Uint16Array: false, - Uint32Array: false, - Uint8Array: false, - Uint8ClampedArray: false, - WeakMap: false, - WeakSet: false, - // ES2017 globals - Atomics: false, - SharedArrayBuffer: false, + return [ + { + files: ["*.*"], + plugins: { + "json-schema-validator": { + rules: Object.fromEntries( + rules.map((r) => [r.meta.docs.ruleName, r]), + ), + }, + }, + languageOptions: { + globals: { + // Node + module: false, + }, + }, + rules: this.rules, }, - rules: this.rules, - parser: this.parser, - parserOptions: { - parser: this.espree, - sourceType: "module", - ecmaVersion: "latest", + { + files: ["*.json", "*.jsonc", "*.json5"], + languageOptions: { + parser: this.jsoncESLintParser, + }, }, - }; + { + files: ["*.yml", "*.yaml"], + languageOptions: { + parser: this.yamlESLintParser, + }, + }, + { + files: ["*.toml"], + languageOptions: { + parser: this.tomlESLintParser, + }, + }, + { + files: ["*.vue"], + languageOptions: { + parser: this.vueESLintParser, + }, + }, + ]; }, linter() { if ( @@ -144,15 +151,6 @@ export default { return null; } const linter = new Linter(); - linter.defineParser("jsonc-eslint-parser", this.jsoncESLintParser); - linter.defineParser("yaml-eslint-parser", this.yamlESLintParser); - linter.defineParser("toml-eslint-parser", this.tomlESLintParser); - linter.defineParser("vue-eslint-parser", this.vueESLintParser); - - for (const k of Object.keys(rules)) { - const rule = rules[k]; - linter.defineRule(rule.meta.docs.ruleId, rule); - } return linter; }, diff --git a/docs/.vitepress/theme/components/components/RulesSettings.vue b/docs/.vitepress/theme/components/components/RulesSettings.vue index c36635a4..1e2abc38 100644 --- a/docs/.vitepress/theme/components/components/RulesSettings.vue +++ b/docs/.vitepress/theme/components/components/RulesSettings.vue @@ -119,7 +119,7 @@