Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING: Bump ESLint to ^9.11.1, bump related ESLint dependencies, and rewrite configs to use flat configs #370

Merged
merged 29 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1d20817
Update main ESLint config to flat config format
Mrtenz Sep 22, 2024
bccb33c
Bump all related ESLint dependencies
Mrtenz Sep 22, 2024
0503af4
Convert base config to flat config format
Mrtenz Sep 22, 2024
83155c1
Convert browser config to flat config format
Mrtenz Sep 22, 2024
462fd6b
Convert CommonJS config to flat config format
Mrtenz Sep 22, 2024
c329998
Convert Jest config to flat config format
Mrtenz Sep 22, 2024
84cdc64
Convert Mocha config to flat config format
Mrtenz Sep 22, 2024
815177e
Convert Node.js config to flat config format
Mrtenz Sep 22, 2024
935cd51
Convert TypeScript config to flat config format
Mrtenz Sep 22, 2024
7d80761
Replace `jest/no-if` with `jest/no-conditional-in-test`
Mrtenz Sep 22, 2024
ec9cbd4
Add dependency on @metamask/eslint-config-jest to root package
Mrtenz Sep 22, 2024
6860331
Add name and files to all configs
Mrtenz Sep 22, 2024
58c2d1e
Update validate-config script
Mrtenz Sep 23, 2024
6753879
Update snapshots
Mrtenz Sep 23, 2024
c46cfd8
Normalize snapshots
Mrtenz Sep 23, 2024
69c38f9
Fix lint errors
Mrtenz Sep 23, 2024
5b8f52e
Update formatting of package.jsons
Mrtenz Sep 23, 2024
d7a0b66
Update configs to use helper
Mrtenz Sep 23, 2024
a66e4d7
Fix config validation script when using Node.js 18
Mrtenz Sep 23, 2024
dcb7bdd
Update all READMEs
Mrtenz Sep 23, 2024
fb2ad66
Set type to module for all packages
Mrtenz Sep 23, 2024
c2f759e
Use jsdoc error config for TypeScript
Mrtenz Sep 23, 2024
071cdd0
Set module and moduleResolution to Node16
Mrtenz Sep 23, 2024
34f7c67
Remove Jest types
Mrtenz Sep 24, 2024
d448f10
Remove import attributes in favour of `require`
Mrtenz Sep 24, 2024
4b8e926
Disable `@typescript-eslint/no-duplicate-type-constituents`
Mrtenz Sep 24, 2024
25045b4
Fix tests
Mrtenz Sep 25, 2024
80e8dfd
Disable `no-implicit-globals`
Mrtenz Sep 25, 2024
00ebecd
Disable `@typescript-eslint/no-redundant-type-constituents`
Mrtenz Sep 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this safe because consumers always use this package as a devDep? Are we sure this doesn't affect downstream CJS packages?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the eslint v9 migrate guide, looks like we only need to worry about CJS configurations importing from our repo, and that shouldn't be a problem for long since eslint is now set up to use ESM by default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consumers can add it and use it even if they use type: commonjs, as long as the config is a .mjs file. I figured we might as well update all places where we consume the libraries since we have to rewrite the majority of the configs anyway.

"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
Loading