From 78c8b80f514719ad59a6e20fe2aa5318108f8c6d Mon Sep 17 00:00:00 2001 From: Ben Scott <227292+BPScott@users.noreply.github.com> Date: Sat, 2 Dec 2023 22:16:12 -0800 Subject: [PATCH] Use flat config for the project's eslint configuration (#615) * chore: use flat config for the project's eslint configuration This shall let us dogfood the recommended eslint config when we add it * chore: skip perf step in node 14 as eslint plugin isn't compatible with v14 --- .eslintignore | 2 - .eslintrc | 22 ------ .github/workflows/ci.yml | 3 + eslint.config.js | 52 +++++++++++++ package.json | 5 +- pnpm-lock.yaml | 156 ++++++++++++++++++++++++--------------- 6 files changed, 154 insertions(+), 86 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc create mode 100644 eslint.config.js diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 11d0ef62..00000000 --- a/.eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -CHANGELOG.md -test/fixtures diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 8f8fbb89..00000000 --- a/.eslintrc +++ /dev/null @@ -1,22 +0,0 @@ -{ - "root": true, - "parserOptions": { - "ecmaVersion": "latest", - "sourceType": "module" - }, - "env": { - "mocha": true, - "node": true - }, - "extends": [ - "eslint:recommended", - "plugin:@eslint-community/eslint-comments/recommended", - "plugin:eslint-plugin/recommended", - "plugin:n/recommended", - "plugin:mdx/recommended", - "plugin:prettier/recommended" - ], - "rules": { - "eslint-plugin/report-message-format": ["error", "^[^a-z].*\\.$"] - } -} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 14e91e17..c78ada63 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,4 +36,7 @@ jobs: run: pnpm mocha - name: Perf + # Skip on node 14, as eslint-plugin-n contains syntax that doesn't work + # with node 14 + if: ${{ matrix.node-version != 14 }} run: TIMING=1 pnpm lint diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 00000000..9bd6543c --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,52 @@ +const { configs: eslintConfigs } = require('@eslint/js'); +const eslintPluginN = require('eslint-plugin-n'); +const eslintPluginEslintComments = require('@eslint-community/eslint-plugin-eslint-comments'); +const eslintPluginEslintPluginRecommended = require('eslint-plugin-eslint-plugin/configs/recommended'); +const eslintPluginMdx = require('eslint-plugin-mdx'); +const eslintConfigPrettier = require('eslint-config-prettier'); +const eslintPluginPrettier = require('./eslint-plugin-prettier'); + +module.exports = [ + eslintConfigs.recommended, + eslintPluginN.configs['flat/recommended'], + // eslint-community/eslint-comments does not expose a reusable flat config, + // so create one from its legacy config + { + plugins: { + '@eslint-community/eslint-comments': eslintPluginEslintComments, + }, + rules: eslintPluginEslintComments.configs.recommended.rules, + }, + eslintPluginEslintPluginRecommended, + eslintPluginMdx.flat, + eslintPluginMdx.flatCodeBlocks, + eslintConfigPrettier, + // No built-in flat recommended config yet + { + plugins: { prettier: eslintPluginPrettier }, + rules: eslintPluginPrettier.configs.recommended.rules, + }, + { + rules: { + 'eslint-plugin/report-message-format': ['error', '^[^a-z].*\\.$'], + }, + }, + { + files: ['**/*.md'], + rules: { 'prettier/prettier': ['error', { parser: 'markdown' }] }, + }, + { + files: ['**/*.mdx'], + rules: { 'prettier/prettier': ['error', { parser: 'mdx' }] }, + }, + // Global ignores + // If a config block only contains an `ignores` key, then the globs are + // ignored globally + { + ignores: [ + 'CHANGELOG.md', + '.github/ISSUE_TEMPLATE.md', + 'test/fixtures/**/*', + ], + }, +]; diff --git a/package.json b/package.json index b0042d1e..2d92bc23 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "@changesets/cli": "^2.26.2", "@commitlint/config-conventional": "^18.4.3", "@eslint-community/eslint-plugin-eslint-comments": "^4.1.0", + "@eslint/js": "^8.55.0", "@graphql-eslint/eslint-plugin": "^3.20.0", "@types/eslint": "^8.44.7", "@types/prettier-linter-helpers": "^1.0.1", @@ -68,8 +69,8 @@ "eslint-formatter-friendly": "^7.0.0", "eslint-mdx": "^2.1.0", "eslint-plugin-eslint-plugin": "^5.1.0", - "eslint-plugin-mdx": "^2.1.0", - "eslint-plugin-n": "^16.0.1", + "eslint-plugin-mdx": "^2.2.0", + "eslint-plugin-n": "^16.3.1", "eslint-plugin-prettier": "link:.", "eslint-plugin-svelte": "^2.32.2", "eslint-plugin-svelte3": "^4.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 55a67626..5dabaeb6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -33,6 +33,9 @@ devDependencies: '@eslint-community/eslint-plugin-eslint-comments': specifier: ^4.1.0 version: 4.1.0(eslint@8.44.0) + '@eslint/js': + specifier: ^8.55.0 + version: 8.55.0 '@graphql-eslint/eslint-plugin': specifier: ^3.20.0 version: 3.20.0(patch_hash=e3c7i33vtfs4mivhjwqctijsoe)(graphql@16.8.1) @@ -61,11 +64,11 @@ devDependencies: specifier: ^5.1.0 version: 5.1.0(eslint@8.44.0) eslint-plugin-mdx: - specifier: ^2.1.0 - version: 2.1.0(eslint@8.44.0) + specifier: ^2.2.0 + version: 2.2.0(eslint@8.44.0) eslint-plugin-n: - specifier: ^16.0.1 - version: 16.0.1(eslint@8.44.0) + specifier: ^16.3.1 + version: 16.3.1(eslint@8.44.0) eslint-plugin-prettier: specifier: link:. version: 'link:' @@ -278,7 +281,7 @@ packages: '@babel/helper-split-export-declaration': 7.22.6 '@babel/parser': 7.23.0 '@babel/types': 7.23.0 - debug: 4.3.4 + debug: 4.3.4(supports-color@8.1.1) globals: 11.12.0 transitivePeerDependencies: - supports-color @@ -699,7 +702,7 @@ packages: engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: ajv: 6.12.6 - debug: 4.3.4 + debug: 4.3.4(supports-color@8.1.1) espree: 9.6.0 globals: 13.20.0 ignore: 5.3.0 @@ -716,6 +719,11 @@ packages: engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: true + /@eslint/js@8.55.0: + resolution: {integrity: sha512-qQfo2mxH5yVom1kacMtZZJFVdW+E70mqHMJvVg6WTLo+VBuQJ4TojZlfWBjK0ve5BdEeNAVxOsl/nvNMpJOaJA==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dev: true + /@graphql-eslint/eslint-plugin@3.20.0(patch_hash=e3c7i33vtfs4mivhjwqctijsoe)(graphql@16.8.1): resolution: {integrity: sha512-zvGJf7sNkh4QTRGHogwS/A9Ob5ZFC2A7U9ASIJ1RWkSex3wd5P0Fcwt98eagICnDguMWBIzsSko4vWoRgovbvg==} engines: {node: '>=12'} @@ -727,7 +735,7 @@ packages: '@graphql-tools/graphql-tag-pluck': 7.5.2(graphql@16.8.1) '@graphql-tools/utils': 9.2.1(graphql@16.8.1) chalk: 4.1.2 - debug: 4.3.4 + debug: 4.3.4(supports-color@8.1.1) fast-glob: 3.3.0 graphql: 16.8.1 graphql-config: 4.5.0(graphql@16.8.1) @@ -1002,7 +1010,7 @@ packages: engines: {node: '>=10.10.0'} dependencies: '@humanwhocodes/object-schema': 1.2.1 - debug: 4.3.4 + debug: 4.3.4(supports-color@8.1.1) minimatch: 3.1.2 transitivePeerDependencies: - supports-color @@ -1572,6 +1580,11 @@ packages: resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==} dev: true + /builtin-modules@3.3.0: + resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==} + engines: {node: '>=6'} + dev: true + /builtins@5.0.1: resolution: {integrity: sha512-qwVpFEHNfhYJIzNRBvd2C1kyo6jz3ZSMPyyuR47OPdiKWlbYnZNyDWuyR175qDnAJLiCo5fBBqPb3RiXgWlkOQ==} dependencies: @@ -1805,7 +1818,7 @@ packages: dev: true /concat-map@0.0.1: - resolution: {integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=} + resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} dev: true /concat-stream@2.0.0: @@ -1946,18 +1959,6 @@ packages: resolution: {integrity: sha512-8YnDaaf7N3k/q5HnTJVuzSyLETjoZjVmHc4AeKAzOvKHEFQKcn64OKBfzHYtE9zGjctNM7V9I0MfnUVLpi7M5g==} dev: true - /debug@4.3.4: - resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} - engines: {node: '>=6.0'} - peerDependencies: - supports-color: '*' - peerDependenciesMeta: - supports-color: - optional: true - dependencies: - ms: 2.1.2 - dev: true - /debug@4.3.4(supports-color@8.1.1): resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} engines: {node: '>=6.0'} @@ -2254,6 +2255,31 @@ packages: - supports-color dev: true + /eslint-mdx@2.2.0(eslint@8.44.0): + resolution: {integrity: sha512-AriN6lCW6KhWQ9GEiXapR1DokKHefOUqKvCmHxnE9puCWYhWiycU2SNKH8jmrasDBreZ+RtJDLi+RcUNLJatjg==} + engines: {node: ^12.20.0 || ^14.18.0 || >=16.0.0} + peerDependencies: + eslint: '>=8.0.0' + dependencies: + acorn: 8.11.2 + acorn-jsx: 5.3.2(acorn@8.11.2) + eslint: 8.44.0 + espree: 9.6.1 + estree-util-visit: 1.2.1 + remark-mdx: 2.3.0 + remark-parse: 10.0.2 + remark-stringify: 10.0.3 + synckit: 0.8.5 + tslib: 2.6.2 + unified: 10.1.2 + unified-engine: 10.1.0 + unist-util-visit: 4.1.2 + uvu: 0.5.6 + vfile: 5.3.7 + transitivePeerDependencies: + - supports-color + dev: true + /eslint-plugin-es-x@7.1.0(eslint@8.44.0): resolution: {integrity: sha512-AhiaF31syh4CCQ+C5ccJA0VG6+kJK8+5mXKKE7Qs1xcPRg02CDPOj3mWlQxuWS/AYtg7kxrDNgW9YW3vc0Q+Mw==} engines: {node: ^14.18.0 || >=16.0.0} @@ -2276,8 +2302,8 @@ packages: estraverse: 5.3.0 dev: true - /eslint-plugin-markdown@3.0.0(eslint@8.44.0): - resolution: {integrity: sha512-hRs5RUJGbeHDLfS7ELanT0e29Ocyssf/7kBM+p7KluY5AwngGkDf8Oyu4658/NZSGTTq05FZeWbkxXtbVyHPwg==} + /eslint-plugin-markdown@3.0.1(eslint@8.44.0): + resolution: {integrity: sha512-8rqoc148DWdGdmYF6WSQFT3uQ6PO7zXYgeBpHAOAakX/zpq+NvFYbDA/H7PYzHajwtmaOzAwfxyl++x0g1/N9A==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 @@ -2288,27 +2314,27 @@ packages: - supports-color dev: true - /eslint-plugin-mdx@2.1.0(eslint@8.44.0): - resolution: {integrity: sha512-Q8P1JXv+OrD+xhWT95ZyV30MMdnqJ1voKtXfxWrJJ2XihJRI15gPmXbIWY9t8CjA8C//isfzNOmnVY9e3GTL0g==} + /eslint-plugin-mdx@2.2.0(eslint@8.44.0): + resolution: {integrity: sha512-OseoMXUIr8iy3E0me+wJLVAxuB0kxHP1plxuYAJDynzorzOj2OKv8Fhr+rIOJ32zfl3bnEWsqFnUiCnyznr1JQ==} engines: {node: ^12.20.0 || ^14.18.0 || >=16.0.0} peerDependencies: eslint: '>=8.0.0' dependencies: eslint: 8.44.0 - eslint-mdx: 2.1.0(eslint@8.44.0) - eslint-plugin-markdown: 3.0.0(eslint@8.44.0) + eslint-mdx: 2.2.0(eslint@8.44.0) + eslint-plugin-markdown: 3.0.1(eslint@8.44.0) remark-mdx: 2.3.0 remark-parse: 10.0.2 remark-stringify: 10.0.3 - tslib: 2.6.0 + tslib: 2.6.2 unified: 10.1.2 vfile: 5.3.7 transitivePeerDependencies: - supports-color dev: true - /eslint-plugin-n@16.0.1(eslint@8.44.0): - resolution: {integrity: sha512-CDmHegJN0OF3L5cz5tATH84RPQm9kG+Yx39wIqIwPR2C0uhBGMWfbbOtetR83PQjjidA5aXMu+LEFw1jaSwvTA==} + /eslint-plugin-n@16.3.1(eslint@8.44.0): + resolution: {integrity: sha512-w46eDIkxQ2FaTHcey7G40eD+FhTXOdKudDXPUO2n9WNcslze/i/HT2qJ3GXjHngYSGDISIgPNhwGtgoix4zeOw==} engines: {node: '>=16.0.0'} peerDependencies: eslint: '>=7.0.0' @@ -2317,10 +2343,12 @@ packages: builtins: 5.0.1 eslint: 8.44.0 eslint-plugin-es-x: 7.1.0(eslint@8.44.0) - ignore: 5.2.4 - is-core-module: 2.12.1 + get-tsconfig: 4.7.2 + ignore: 5.3.0 + is-builtin-module: 3.2.1 + is-core-module: 2.13.1 minimatch: 3.1.2 - resolve: 1.22.2 + resolve: 1.22.8 semver: 7.5.4 dev: true @@ -2346,7 +2374,7 @@ packages: dependencies: '@eslint-community/eslint-utils': 4.4.0(eslint@8.44.0) '@jridgewell/sourcemap-codec': 1.4.15 - debug: 4.3.4 + debug: 4.3.4(supports-color@8.1.1) eslint: 8.44.0 esutils: 2.0.3 known-css-properties: 0.27.0 @@ -2405,7 +2433,7 @@ packages: ajv: 6.12.6 chalk: 4.1.2 cross-spawn: 7.0.3 - debug: 4.3.4 + debug: 4.3.4(supports-color@8.1.1) doctrine: 3.0.0 escape-string-regexp: 4.0.0 eslint-scope: 7.2.0 @@ -2447,6 +2475,15 @@ packages: eslint-visitor-keys: 3.4.1 dev: true + /espree@9.6.1: + resolution: {integrity: sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dependencies: + acorn: 8.11.2 + acorn-jsx: 5.3.2(acorn@8.11.2) + eslint-visitor-keys: 3.4.1 + dev: true + /esprima@4.0.1: resolution: {integrity: sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==} engines: {node: '>=4'} @@ -2787,6 +2824,12 @@ packages: get-intrinsic: 1.2.2 dev: true + /get-tsconfig@4.7.2: + resolution: {integrity: sha512-wuMsz4leaj5hbGgg4IvDU0bqJagpftG5l5cXIAvo8uZrqn0NJqwtfupTN00VnkQJPcIRrxYrm1Ue24btpCha2A==} + dependencies: + resolve-pkg-maps: 1.0.0 + dev: true + /git-raw-commits@2.0.11: resolution: {integrity: sha512-VnctFhw+xfj8Va1xtfEqCUD2XDrbAPSJx+hSrE5K7fGdjZruW7XV+QOrN7LF/RJyvspRiD2I0asWsxFp0ya26A==} engines: {node: '>=10'} @@ -3012,13 +3055,6 @@ packages: has-symbols: 1.0.3 dev: true - /has@1.0.3: - resolution: {integrity: sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==} - engines: {node: '>= 0.4.0'} - dependencies: - function-bind: 1.1.2 - dev: true - /hasown@2.0.0: resolution: {integrity: sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA==} engines: {node: '>= 0.4'} @@ -3194,17 +3230,18 @@ packages: engines: {node: '>=4'} dev: true + /is-builtin-module@3.2.1: + resolution: {integrity: sha512-BSLE3HnV2syZ0FK0iMA/yUGplUeMmNz4AW5fnTunbCIqZi4vG3WjJT9FHMy5D69xmAYBHXQhJdALdpwVxV501A==} + engines: {node: '>=6'} + dependencies: + builtin-modules: 3.3.0 + dev: true + /is-callable@1.2.7: resolution: {integrity: sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==} engines: {node: '>= 0.4'} dev: true - /is-core-module@2.12.1: - resolution: {integrity: sha512-Q4ZuBAe2FUsKtyQJoQHlvP8OvBERxO3jEmy1I7hcRXcJBGGHFh/aJBswbXuS9sgrDH2QUO8ilkwNPHvHMd8clg==} - dependencies: - has: 1.0.3 - dev: true - /is-core-module@2.13.1: resolution: {integrity: sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==} dependencies: @@ -3548,7 +3585,7 @@ packages: dependencies: chalk: 5.3.0 commander: 11.1.0 - debug: 4.3.4 + debug: 4.3.4(supports-color@8.1.1) execa: 8.0.1 lilconfig: 2.1.0 listr2: 7.0.2 @@ -4309,7 +4346,7 @@ packages: /micromark@2.11.4: resolution: {integrity: sha512-+WoovN/ppKolQOFIAajxi7Lu9kInbPxFuTBVEavFcL8eAfVstoc5MocPmqBeAdBOJV00uaVjegzH4+MA0DN/uA==} dependencies: - debug: 4.3.4 + debug: 4.3.4(supports-color@8.1.1) parse-entities: 2.0.0 transitivePeerDependencies: - supports-color @@ -4319,7 +4356,7 @@ packages: resolution: {integrity: sha512-uD66tJj54JLYq0De10AhWycZWGQNUvDI55xPgk2sQM5kn1JYlhbCMTtEeT27+vAhW2FBQxLlOmS3pmA7/2z4aA==} dependencies: '@types/debug': 4.1.8 - debug: 4.3.4 + debug: 4.3.4(supports-color@8.1.1) decode-named-character-reference: 1.0.2 micromark-core-commonmark: 1.1.0 micromark-factory-space: 1.1.0 @@ -5765,13 +5802,8 @@ packages: global-dirs: 0.1.1 dev: true - /resolve@1.22.2: - resolution: {integrity: sha512-Sb+mjNHOULsBv818T40qSPeRiuWLyaGMa5ewydRLFimneixmVy2zdivRl+AF6jaYPC8ERxGDmFSiqui6SfPd+g==} - hasBin: true - dependencies: - is-core-module: 2.12.1 - path-parse: 1.0.7 - supports-preserve-symlinks-flag: 1.0.0 + /resolve-pkg-maps@1.0.0: + resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==} dev: true /resolve@1.22.8: @@ -6276,6 +6308,10 @@ packages: /tslib@2.6.0: resolution: {integrity: sha512-7At1WUettjcSRHXCyYtTselblcHl9PJFFVKiCAy/bY97+BPZXSQ2wbq0P9s8tK2G7dFQfNnlJnPAiArVBVBsfA==} + /tslib@2.6.2: + resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} + dev: true + /tty-table@4.2.3: resolution: {integrity: sha512-Fs15mu0vGzCrj8fmJNP7Ynxt5J7praPXqFN0leZeZBXJwkMxv9cb2D454k1ltrtUSJbZ4yH4e0CynsHLxmUfFA==} engines: {node: '>=8.0.0'} @@ -6391,7 +6427,7 @@ packages: '@types/node': 18.19.0 '@types/unist': 2.0.6 concat-stream: 2.0.0 - debug: 4.3.4 + debug: 4.3.4(supports-color@8.1.1) fault: 2.0.1 glob: 8.1.0 ignore: 5.3.0 @@ -6634,7 +6670,7 @@ packages: peerDependencies: eslint: '>=6.0.0' dependencies: - debug: 4.3.4 + debug: 4.3.4(supports-color@8.1.1) eslint: 8.44.0 eslint-scope: 7.2.0 eslint-visitor-keys: 3.4.1