diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index ae220e46..00000000 --- a/.eslintignore +++ /dev/null @@ -1,7 +0,0 @@ -bin -coverage -dist -lib -node_modules -tmp -types diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index a52d8002..00000000 --- a/.eslintrc.js +++ /dev/null @@ -1,47 +0,0 @@ -module.exports = { - root: true, - env: { - browser: true, - es6: true, - node: true, - }, - extends: ['eslint:recommended', 'plugin:import-x/recommended', 'prettier'], - parserOptions: { - ecmaVersion: 'latest', - ecmaFeatures: { jsx: true }, - }, - plugins: ['unicorn'], - rules: { - 'import-x/no-unresolved': ['error', { ignore: ['ts-key-enum'] }], - 'import-x/order': ['error', { alphabetize: { order: 'asc' } }], - 'unicorn/prefer-node-protocol': 'error', - }, - settings: { - 'import-x/resolver': { - node: { extensions: ['.mjs', '.js', '.jsx', '.json', '.ts', '.tsx'] }, - }, - 'import-x/ignore': ['@rollup/plugin-node-resolve'], - }, - overrides: [ - { - files: ['**/*.ts', '**/*.tsx'], - parser: '@typescript-eslint/parser', - plugins: ['@typescript-eslint'], - extends: [ - 'plugin:@typescript-eslint/recommended', - 'plugin:@typescript-eslint/stylistic', - 'plugin:import-x/typescript', - 'prettier', - ], - rules: { - '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/explicit-function-return-type': 'off', - '@typescript-eslint/explicit-module-boundary-types': 'off', - '@typescript-eslint/consistent-type-assertions': [ - 'error', - { assertionStyle: 'as' }, - ], - }, - }, - ], -} diff --git a/CHANGELOG.md b/CHANGELOG.md index 048fb6c2..db732cee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - Support for CSS nesting - Upgrade development Node.js LTS to v20.17.0 ([#591](https://github.com/marp-team/marp-cli/pull/591)) - Upgrade dependent packages to the latest versions ([#591](https://github.com/marp-team/marp-cli/pull/591), [#598](https://github.com/marp-team/marp-cli/pull/598)) +- Migrate ESLint config to flat config ([#606](https://github.com/marp-team/marp-cli/pull/606)) ### Fixed diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 00000000..ba0a5309 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,88 @@ +import js from '@eslint/js' +import eslintConfigPrettier from 'eslint-config-prettier' +import eslintPluginImportX from 'eslint-plugin-import-x' +import eslintPluginJest from 'eslint-plugin-jest' +import eslintPluginUnicorn from 'eslint-plugin-unicorn' +import globals from 'globals' +import tseslint from 'typescript-eslint' + +const tsFiles = ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts'] +const testFiles = ['test/**', 'jest.setup.js'] +const forFiles = (files, confs) => confs.map((conf) => ({ ...conf, files })) + +export default tseslint.config( + js.configs.recommended, + eslintPluginImportX.flatConfigs.recommended, + { + plugins: { + unicorn: eslintPluginUnicorn, + }, + rules: { + 'unicorn/prefer-node-protocol': 'error', + }, + }, + ...forFiles(tsFiles, [ + ...tseslint.configs.recommended, + ...tseslint.configs.stylistic, + eslintPluginImportX.flatConfigs.typescript, + { + rules: { + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/explicit-function-return-type': 'off', + '@typescript-eslint/explicit-module-boundary-types': 'off', + '@typescript-eslint/consistent-type-assertions': [ + 'error', + { assertionStyle: 'as' }, + ], + }, + }, + ]), + ...forFiles(testFiles, [ + eslintPluginJest.configs['flat/recommended'], + eslintPluginJest.configs['flat/style'], + { + languageOptions: { + globals: { ...globals.jest }, + }, + rules: { + 'jest/no-standalone-expect': [ + 'error', + { additionalTestBlockFunctions: ['itExceptWin', 'itOnlyWin'] }, + ], + }, + }, + ]), + eslintConfigPrettier, + { + linterOptions: { + reportUnusedDisableDirectives: 'error', + }, + languageOptions: { + ecmaVersion: 'latest', + parserOptions: { + ecmaFeatures: { jsx: true }, + }, + globals: { + ...globals.node, + ...globals.browser, + }, + }, + rules: { + 'import-x/order': ['error', { alphabetize: { order: 'asc' } }], + }, + settings: { + 'import-x/resolver': 'typescript', + }, + }, + { + ignores: [ + 'bin/**/*', + 'coverage/**/*', + 'dist/**/*', + 'lib/**/*', + 'node_modules/**/*', + 'tmp/**/*', + 'types/**/*', + ], + } +) diff --git a/jest.setup.js b/jest.setup.js index 90f41733..29e7d628 100644 --- a/jest.setup.js +++ b/jest.setup.js @@ -1,4 +1,3 @@ -/* eslint-env jest */ jest.mock('wrap-ansi') require('css.escape') // Polyfill for CSS.escape diff --git a/package.json b/package.json index 1fa51c20..615f381e 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "clean": "node -e \"fs.rmSync('lib',{recursive:true,force:true})\"", "format": "prettier \"**/*.{css,js,jsx,json,md,mjs,scss,ts,tsx,yaml,yml}\"", "format:write": "yarn -s format --write", - "lint:js": "ESLINT_USE_FLAT_CONFIG=false eslint --ext .js,.mjs,.jsx,.ts,.tsx --report-unused-disable-directives --cache .", + "lint:js": "eslint --cache", "lint:css": "stylelint \"src/**/*.{css,scss}\"", "prepack": "npm-run-all --parallel check:* lint:* test:coverage --parallel build types", "preversion": "run-p check:* lint:* test:coverage", @@ -86,6 +86,7 @@ "@types/cheerio": "^0.22.35", "@types/debug": "^4.1.12", "@types/dom-view-transitions": "^1.0.5", + "@types/eslint__js": "^8.42.3", "@types/express": "^4.17.21", "@types/jest": "^29.5.13", "@types/markdown-it": "^14.1.2", @@ -95,8 +96,6 @@ "@types/which": "^3.0.4", "@types/ws": "^8.5.12", "@types/yargs": "^17.0.33", - "@typescript-eslint/eslint-plugin": "^8.8.0", - "@typescript-eslint/parser": "^8.8.0", "@yao-pkg/pkg": "^5.15.0", "autoprefixer": "^10.4.20", "bespoke": "bespokejs/bespoke", @@ -108,7 +107,6 @@ "debug": "^4.3.7", "eslint": "^9.12.0", "eslint-config-prettier": "^9.1.0", - "eslint-import-resolver-exports": "^1.0.0-beta.5", "eslint-import-resolver-typescript": "^3.6.3", "eslint-plugin-import-x": "^4.3.1", "eslint-plugin-jest": "^28.8.3", @@ -116,6 +114,7 @@ "express": "^4.21.0", "fast-plist": "^0.1.3", "get-stdin": "^9.0.0", + "globals": "^15.10.0", "globby": "^14.0.2", "image-size": "^1.1.1", "import-from": "^4.0.0", @@ -152,6 +151,7 @@ "tslib": "^2.7.0", "typed-emitter": "^2.1.0", "typescript": "^5.6.2", + "typescript-eslint": "^8.8.0", "vhtml": "^2.2.0", "which": "4.0.0", "wrap-ansi": "^9.0.0", diff --git a/test/.eslintrc.js b/test/.eslintrc.js deleted file mode 100644 index 9b1655c4..00000000 --- a/test/.eslintrc.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - plugins: ['jest'], - extends: ['plugin:jest/recommended', 'plugin:jest/style'], - rules: { - 'jest/no-standalone-expect': [ - 'error', - { additionalTestBlockFunctions: ['itOnlyWin', 'itExceptWin'] }, - ], - }, -} diff --git a/yarn.lock b/yarn.lock index 951d132d..8da8e4a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1879,6 +1879,21 @@ resolved "https://registry.yarnpkg.com/@types/dom-view-transitions/-/dom-view-transitions-1.0.5.tgz#06070954f1ebc2f94bbea5a64618574772eb4c1d" integrity sha512-N2sILR7fxSMnaFaAPwGj4DtHCXjIyQTHt+xJyf9jATpzUsTkMNM0DWtqZB6W7f501B/Y0tq3uqat/VlbjuTpMA== +"@types/eslint@*": + version "9.6.1" + resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-9.6.1.tgz#d5795ad732ce81715f27f75da913004a56751584" + integrity sha512-FXx2pKgId/WyYo2jXw63kk7/+TY7u7AziEJxJAnSFzHlqTAS3Ync6SvgYAN/k4/PQpnnVuzoMuVnByKK2qp0ag== + dependencies: + "@types/estree" "*" + "@types/json-schema" "*" + +"@types/eslint__js@^8.42.3": + version "8.42.3" + resolved "https://registry.yarnpkg.com/@types/eslint__js/-/eslint__js-8.42.3.tgz#d1fa13e5c1be63a10b4e3afe992779f81c1179a0" + integrity sha512-alfG737uhmPdnvkrLdZLcEKJ/B8s9Y4hrZ+YAdzUeoArBlSUERA2E87ROfOaS4jd/C45fzOoZzidLc1IPwLqOw== + dependencies: + "@types/eslint" "*" + "@types/estree@*", "@types/estree@1.0.6", "@types/estree@^1.0.0", "@types/estree@^1.0.6": version "1.0.6" resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.6.tgz#628effeeae2064a1b4e79f78e81d87b7e5fc7b50" @@ -1952,7 +1967,7 @@ "@types/tough-cookie" "*" parse5 "^7.0.0" -"@types/json-schema@^7.0.15": +"@types/json-schema@*", "@types/json-schema@^7.0.15": version "7.0.15" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841" integrity sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA== @@ -2105,7 +2120,7 @@ dependencies: "@types/node" "*" -"@typescript-eslint/eslint-plugin@^8.8.0": +"@typescript-eslint/eslint-plugin@8.8.0": version "8.8.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.8.0.tgz#b2b02a5447cdc885950eb256b3b8a97b92031bd3" integrity sha512-wORFWjU30B2WJ/aXBfOm1LX9v9nyt9D3jsSOxC3cCaTQGCW5k4jNpmjFv3U7p/7s4yvdjHzwtv2Sd2dOyhjS0A== @@ -2120,7 +2135,7 @@ natural-compare "^1.4.0" ts-api-utils "^1.3.0" -"@typescript-eslint/parser@^8.8.0": +"@typescript-eslint/parser@8.8.0": version "8.8.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-8.8.0.tgz#ee4397c70230c4eee030456924c0fba480072f5e" integrity sha512-uEFUsgR+tl8GmzmLjRqz+VrDv4eoaMqMXW7ruXfgThaAShO9JTciKpEsB+TvnfFfbg5IpujgMXVV36gOJRLtZg== @@ -3701,13 +3716,6 @@ eslint-config-prettier@^9.1.0: resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz#31af3d94578645966c082fcb71a5846d3c94867f" integrity sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw== -eslint-import-resolver-exports@^1.0.0-beta.5: - version "1.0.0-beta.5" - resolved "https://registry.yarnpkg.com/eslint-import-resolver-exports/-/eslint-import-resolver-exports-1.0.0-beta.5.tgz#d603056ee168b3e84848cceef12824e470f47b31" - integrity sha512-o6t0w7muUpXr7MkUVzD5igQoDfAQvTmcPp8HEAJdNF8eOuAO+yn6I/TTyMxz9ecCwzX7e02vzlkHURoScUuidg== - dependencies: - resolve.exports "^2.0.0" - eslint-import-resolver-node@^0.3.9: version "0.3.9" resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.9.tgz#d4eaac52b8a2e7c3cd1903eb00f7e053356118ac" @@ -4410,7 +4418,7 @@ globals@^14.0.0: resolved "https://registry.yarnpkg.com/globals/-/globals-14.0.0.tgz#898d7413c29babcf6bafe56fcadded858ada724e" integrity sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ== -globals@^15.9.0: +globals@^15.10.0, globals@^15.9.0: version "15.10.0" resolved "https://registry.yarnpkg.com/globals/-/globals-15.10.0.tgz#a7eab3886802da248ad8b6a9ccca6573ff899c9b" integrity sha512-tqFIbz83w4Y5TCbtgjZjApohbuh7K9BxGYFm7ifwDR240tvdb7P9x+/9VvUKlmkPoiknoJtanI8UOrqxS3a7lQ== @@ -8538,6 +8546,15 @@ typed-query-selector@^2.12.0: resolved "https://registry.yarnpkg.com/typed-query-selector/-/typed-query-selector-2.12.0.tgz#92b65dbc0a42655fccf4aeb1a08b1dddce8af5f2" integrity sha512-SbklCd1F0EiZOyPiW192rrHZzZ5sBijB6xM+cpmrwDqObvdtunOHHIk9fCGsoK5JVIYXoyEp4iEdE3upFH3PAg== +typescript-eslint@^8.8.0: + version "8.8.0" + resolved "https://registry.yarnpkg.com/typescript-eslint/-/typescript-eslint-8.8.0.tgz#93762a4cbd9d586dec0d9ab18e07dea13f497a27" + integrity sha512-BjIT/VwJ8+0rVO01ZQ2ZVnjE1svFBiRczcpr1t1Yxt7sT25VSbPfrJtDsQ8uQTy2pilX5nI9gwxhUyLULNentw== + dependencies: + "@typescript-eslint/eslint-plugin" "8.8.0" + "@typescript-eslint/parser" "8.8.0" + "@typescript-eslint/utils" "8.8.0" + typescript@^5.6.2: version "5.6.2" resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.2.tgz#d1de67b6bef77c41823f822df8f0b3bcff60a5a0"