Skip to content

Commit

Permalink
BREAKING: Bump ESLint to ^9.11.1, bump related ESLint dependencies,…
Browse files Browse the repository at this point in the history
… and rewrite configs to use flat configs (#370)

* Update main ESLint config to flat config format

* Bump all related ESLint dependencies

* Convert base config to flat config format

* Convert browser config to flat config format

* Convert CommonJS config to flat config format

* Convert Jest config to flat config format

* Convert Mocha config to flat config format

* Convert Node.js config to flat config format

* Convert TypeScript config to flat config format

* Replace `jest/no-if` with `jest/no-conditional-in-test`

* Add dependency on @metamask/eslint-config-jest to root package

* Add name and files to all configs

* Update validate-config script

* Update snapshots

* Normalize snapshots

* Fix lint errors

* Update formatting of package.jsons

* Update configs to use helper

* Fix config validation script when using Node.js 18

* Update all READMEs

* Set type to module for all packages

* Use jsdoc error config for TypeScript

* Set module and moduleResolution to Node16

* Remove Jest types

* Remove import attributes in favour of `require`

* Disable `@typescript-eslint/no-duplicate-type-constituents`

* Fix tests

* Disable `no-implicit-globals`

* Disable `@typescript-eslint/no-redundant-type-constituents`
  • Loading branch information
Mrtenz authored Sep 25, 2024
1 parent cce1f4b commit ff9780d
Show file tree
Hide file tree
Showing 57 changed files with 2,606 additions and 2,407 deletions.
38 changes: 0 additions & 38 deletions .eslintrc.js

This file was deleted.

9 changes: 6 additions & 3 deletions .prettierrc.js → .prettierrc.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// All of these are defaults except singleQuote and endOfLine, but we specify them
// for explicitness
module.exports = {
// All of these are defaults except singleQuote and endOfLine, but we specify
// them for explicitness
const config = {
endOfLine: 'auto',
quoteProps: 'as-needed',
singleQuote: true,
tabWidth: 2,
trailingComma: 'all',
plugins: ['prettier-plugin-packagejson'],
};

export default config;
64 changes: 64 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// @ts-check

import base from '@metamask/eslint-config';
import jest from '@metamask/eslint-config-jest';
import nodejs from '@metamask/eslint-config-nodejs';
import typescript from '@metamask/eslint-config-typescript';
// eslint-disable-next-line import-x/no-unresolved
import tseslint from 'typescript-eslint';

const config = tseslint.config(
{
ignores: ['.yarn/'],
},

...base,
...nodejs,

{
files: [
'**/*.ts',
'**/*.tsx',
'**/*.mts',
'**/*.cts',
'**/*.mtsx',
'**/*.ctsx',
],
extends: typescript,
},

{
files: ['**/*.test.mjs'],
extends: jest,
rules: {
'no-shadow': [
'error',
{
allow: ['describe', 'it', 'expect'],
},
],
},
},

{
name: 'main',
files: ['**/*.js', '**/*.mjs'],

languageOptions: {
sourceType: 'module',
},

rules: {
'import-x/no-dynamic-require': 'off',
'import-x/no-nodejs-modules': 'off',
'jsdoc/check-tag-names': 'off',
'jsdoc/no-types': 'off',
'n/global-require': 'off',
'n/no-process-exit': 'off',
'n/no-sync': 'off',
'n/no-unpublished-require': 'off',
},
},
);

export default config;
37 changes: 22 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,45 @@
"type": "git",
"url": "https://github.com/MetaMask/eslint-config.git"
},
"type": "module",
"workspaces": [
"packages/*"
],
"scripts": {
"generate": "node ./scripts/generate-configs.js",
"generate": "node scripts/generate-configs.mjs",
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:config-validation",
"lint:changelogs": "yarn workspaces foreach --parallel --verbose run lint:changelog",
"lint:config-validation": "node ./scripts/validate-configs.js",
"lint:eslint": "yarn eslint . --ext ts,js",
"lint:config-validation": "node scripts/validate-configs.mjs",
"lint:eslint": "eslint",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write && yarn lint:config-validation --write",
"lint:misc": "prettier '**/*.json' '!**/rules-snapshot.json' '**/*.md' '!**/CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore",
"test": "vitest"
},
"devDependencies": {
"@eslint/eslintrc": "^3.0.2",
"@eslint/js": "^8.57.0",
"@eslint/config-array": "^0.18.0",
"@eslint/js": "^9.11.0",
"@lavamoat/allow-scripts": "^3.0.4",
"@metamask/auto-changelog": "^3.4.4",
"@metamask/eslint-config": "^13.0.0",
"@metamask/eslint-config-jest": "workspace:^",
"@metamask/eslint-config-nodejs": "^13.0.0",
"@metamask/eslint-config-typescript": "workspace:^",
"@metamask/utils": "^9.1.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import-x": "^0.5.1",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-jsdoc": "^47.0.2",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-prettier": "^4.2.1",
"@types/eslint__js": "^8.42.3",
"@types/node": "^22.5.5",
"eslint": "^9.11.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import-x": "^4.3.0",
"eslint-plugin-jest": "^28.8.3",
"eslint-plugin-jsdoc": "^50.2.4",
"eslint-plugin-n": "^17.10.3",
"eslint-plugin-prettier": "^5.2.1",
"fast-deep-equal": "^3.1.3",
"globals": "^15.0.0",
"prettier": "^2.7.1",
"prettier-plugin-packagejson": "^2.2.18",
"globals": "^15.9.0",
"prettier": "^3.3.3",
"prettier-plugin-packagejson": "^2.5.2",
"typescript": "~5.5.4",
"typescript-eslint": "^8.6.0",
"vite": "^5.4.7",
"vitest": "^2.1.1"
},
Expand Down
35 changes: 21 additions & 14 deletions packages/base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,33 @@ Our default export contains a base set of ESLint rules for ES6+:

```bash
yarn add --dev \
@metamask/eslint-config@^12.2.0 \
eslint@^8.57.0 \
eslint-config-prettier@^8.5.0 \
eslint-plugin-import-x@^0.5.1 \
eslint-plugin-jsdoc@^47.0.2 \
eslint-plugin-prettier@^4.2.1 \
eslint-plugin-promise@^6.1.1 \
prettier@^2.7.1
@metamask/eslint-config@^13.0.0 \
eslint@^9.11.0 \
eslint-config-prettier@^9.1.0 \
eslint-plugin-import-x@^4.3.0 \
eslint-plugin-jsdoc@^50.2.4 \
eslint-plugin-prettier@^5.2.1 \
eslint-plugin-promise@^7.1.0 \
prettier@^3.3.3
```

The order in which you extend ESLint rules matters.
The `@metamask/*` eslint configs should be added to the `extends` array _last_,
The `@metamask/*` eslint configs should be added to the config array _last_,
with `@metamask/eslint-config` first, and `@metamask/eslint-config-*` in any
order thereafter.

```js
module.exports = {
extends: [
// This should be added last unless you know what you're doing.
'@metamask/eslint-config',
],
import base from '@metamask/eslint-config';

const config = {
// Any custom shared config should be added here.
// ...

// This should be added last unless you know what you're doing.
...base,

{
// Your overrides here.
}
};
```
47 changes: 31 additions & 16 deletions packages/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,50 @@
"url": "https://github.com/MetaMask/eslint-config.git"
},
"license": "MIT",
"main": "src/index.js",
"type": "module",
"exports": {
".": {
"import": {
"types": "./src/index.d.mts",
"default": "./src/index.mjs"
}
}
},
"main": "./src/index.mjs",
"types": "./src/index.d.mts",
"files": [
"src/",
"!src/**/*.test.js"
"!src/**/*.test.mjs"
],
"scripts": {
"lint:changelog": "auto-changelog validate",
"publish": "npm publish",
"test": "eslint ."
},
"dependencies": {
"@eslint/js": "^9.11.0",
"globals": "^15.9.0"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@metamask/auto-changelog": "^3.4.4",
"eslint": "^8.57.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import-x": "^0.5.1",
"eslint-plugin-jsdoc": "^47.0.2",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.1.1",
"prettier": "^2.7.1",
"eslint": "^9.11.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import-x": "^4.3.0",
"eslint-plugin-jsdoc": "^50.2.4",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-promise": "^7.1.0",
"prettier": "^3.3.3",
"vitest": "^2.1.1"
},
"peerDependencies": {
"eslint": "^8.57.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import-x": "^0.5.1",
"eslint-plugin-jsdoc": ">=43.0.7 <48",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.1.1",
"prettier": "^2.7.1"
"eslint": "^9.11.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import-x": "^4.3.0",
"eslint-plugin-jsdoc": "^50.2.4",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-promise": "^7.1.0",
"prettier": "^3.3.3"
},
"engines": {
"node": "^18.18 || >=20"
Expand Down
Loading

0 comments on commit ff9780d

Please sign in to comment.