Skip to content

Commit 7a974ab

Browse files
authored
Update for ESLint v9 compatibility (#52)
### Changelog Updates the package for ESLint v9 compatibility. Most of the peerDeps are now actual deps. ### Docs None ### Description Downstream: - foxglove/crc#212
1 parent 1cd3d68 commit 7a974ab

26 files changed

+1634
-1314
lines changed

.eslintrc.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ jobs:
1111
test:
1212
runs-on: ubuntu-latest
1313

14+
permissions:
15+
# https://docs.npmjs.com/generating-provenance-statements#publishing-packages-with-provenance-via-github-actions
16+
id-token: write
17+
1418
steps:
1519
- uses: actions/checkout@v2
1620

1721
- uses: actions/setup-node@v2
1822
with:
19-
node-version: 16.x
23+
node-version: 22.x
2024
registry-url: https://registry.npmjs.org
2125

2226
- uses: actions/cache@v2
@@ -25,14 +29,18 @@ jobs:
2529
key: v1-${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
2630
restore-keys: v1-${{ runner.os }}-node-
2731

28-
- run: npm install
29-
- run: npm run tsc
32+
- run: npm ci
33+
- run: npm run build
3034
- run: npm run lint
3135
- run: npm run test
3236

3337
# publish version tags
38+
- name: npm publish (dry run)
39+
run: npm publish --provenance --access public --dry-run
40+
env:
41+
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
3442
- name: npm publish
35-
run: npm publish --access public
43+
run: npm publish --provenance --access public
3644
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
3745
env:
3846
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
*.log
33
*.tsbuildinfo
44
node_modules/
5+
dist

.vscode/settings.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
"editor.codeActionsOnSave": {
44
"source.fixAll.eslint": "explicit"
55
},
6-
"eslint.options": {
7-
"reportUnusedDisableDirectives": "error"
8-
},
96
"editor.formatOnSave": true,
107
"editor.defaultFormatter": "esbenp.prettier-vscode",
118
"prettier.prettierPath": "./node_modules/prettier",
12-
"files.eol": "\n"
9+
"files.eol": "\n",
10+
"typescript.tsdk": "node_modules/typescript/lib"
1311
}

README.md

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,34 @@
44

55
Foxglove default eslint configuration & rules.
66

7-
Please err on the side of conservative changes to this repo - multiple Foxglove projects should adopt a change before making it a default.
8-
97
## Rules
108

119
See [rules/README.md](rules/README.md) for details on each rule.
1210

1311
## Installation
1412

15-
The following configurations are available:
16-
17-
- `plugin:@foxglove/base`
18-
- `plugin:@foxglove/jest`
19-
- `plugin:@foxglove/react`
20-
- `plugin:@foxglove/typescript`
21-
22-
**Typescript + React Example**
23-
2413
```sh
2514
yarn add -D \
2615
@foxglove/eslint-plugin \
27-
@typescript-eslint/eslint-plugin \
28-
@typescript-eslint/parser \
16+
typescript-eslint \
2917
eslint \
30-
eslint-config-prettier \
31-
eslint-plugin-es \
32-
eslint-plugin-filenames \
33-
eslint-plugin-import \
34-
eslint-plugin-jest \
35-
eslint-plugin-prettier \
36-
eslint-plugin-react \
37-
eslint-plugin-react-hooks \
3818
prettier
3919
```
4020

41-
In your `.eslintrc.js`:
21+
In your `eslint.config.cjs`:
4222

4323
```js
44-
module.exports = {
45-
extends: [
46-
"plugin:@foxglove/base",
47-
"plugin:@foxglove/jest",
48-
"plugin:@foxglove/react",
49-
],
50-
overrides: [
51-
{
52-
files: ["*.ts", "*.tsx"],
53-
extends: ["plugin:@foxglove/typescript"],
54-
parserOptions: {
55-
project: "tsconfig.json",
56-
},
57-
},
58-
],
59-
};
24+
const foxglove = require("@foxglove/eslint-plugin");
25+
const tseslint = require("typescript-eslint");
26+
27+
module.exports = tseslint.config(
28+
...foxglove.configs.base,
29+
...foxglove.configs.react,
30+
...foxglove.configs.jest,
31+
...foxglove.configs.typescript
32+
);
6033
```
6134

62-
You can add `"plugin:@foxglove/typescript"` to the top level `extends` instead of using `overrides` if your project contains no `.js` files.
63-
6435
## License
6536

6637
@foxglove/eslint-plugin is released under the [MIT License](/LICENSE.md).

configs/base.js

Lines changed: 111 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,122 @@
1-
module.exports = {
2-
extends: ["eslint:recommended", "plugin:prettier/recommended"],
3-
plugins: ["@foxglove", "import", "filenames", "es"],
4-
parserOptions: {
5-
ecmaVersion: 2020,
6-
sourceType: "module",
7-
},
8-
rules: {
9-
// even new Safari versions do not support regexp lookbehinds
10-
"es/no-regexp-lookbehind-assertions": "error",
1+
const { fixupPluginRules } = require("@eslint/compat");
2+
const js = require("@eslint/js");
3+
// @ts-expect-error Missing type definitions
4+
const es = require("eslint-plugin-es");
5+
// @ts-expect-error Missing type definitions
6+
const filenames = require("eslint-plugin-filenames");
7+
// @ts-expect-error Missing type definitions
8+
const importPlugin = require("eslint-plugin-import");
9+
const eslintPluginPrettierRecommended = require("eslint-plugin-prettier/recommended");
1110

12-
// import plugin is slow, only enable the critical stuff
13-
"import/export": "error",
14-
"import/first": "error",
15-
"import/named": "error",
16-
"import/newline-after-import": "error",
17-
"import/no-duplicates": "error",
18-
"import/no-mutable-exports": "error",
19-
"import/no-useless-path-segments": "error",
20-
"import/order": [
21-
"error",
22-
{
23-
alphabetize: {
24-
order: "asc",
25-
},
26-
"newlines-between": "always",
27-
groups: [
28-
["builtin", "external"],
29-
["internal"],
30-
["parent", "sibling", "index"],
31-
],
11+
const foxglove = require("../plugin");
12+
13+
const fixedFilenames = fixupPluginRules(filenames);
14+
15+
/** @type {import("eslint").Linter.Config[]} */
16+
module.exports = [
17+
js.configs.recommended,
18+
eslintPluginPrettierRecommended,
19+
{
20+
linterOptions: {
21+
reportUnusedDisableDirectives: "error",
22+
},
23+
plugins: {
24+
"@foxglove": foxglove,
25+
import: importPlugin,
26+
es: fixupPluginRules(es),
27+
28+
// eslint-plugin-filenames allows rules to have options, but fixupPluginRules defaults to a
29+
// schema that does not allow passing any options. We replace this with `false` to disable
30+
// validation so that options can be passed in.
31+
filenames: {
32+
...fixedFilenames,
33+
rules: Object.fromEntries(
34+
Object.entries(fixedFilenames.rules ?? {}).map(([ruleId, rule]) => [
35+
ruleId,
36+
{
37+
...rule,
38+
meta: {
39+
...rule.meta,
40+
schema: rule.meta?.schema ?? false,
41+
},
42+
},
43+
])
44+
),
3245
},
33-
],
46+
},
47+
rules: {
48+
// even new Safari versions do not support regexp lookbehinds
49+
"es/no-regexp-lookbehind-assertions": "error",
3450

35-
"filenames/match-exported": "error",
51+
// import plugin is slow, only enable the critical stuff
52+
"import/export": "error",
53+
"import/first": "error",
54+
"import/named": "error",
55+
"import/newline-after-import": "error",
56+
"import/no-duplicates": "error",
57+
"import/no-mutable-exports": "error",
58+
"import/no-useless-path-segments": "error",
59+
"import/order": [
60+
"error",
61+
{
62+
alphabetize: {
63+
order: "asc",
64+
},
65+
"newlines-between": "always",
66+
groups: [
67+
["builtin", "external"],
68+
["internal"],
69+
["parent", "sibling", "index"],
70+
],
71+
},
72+
],
3673

37-
// require double equal for null and undefined, triple equal everywhere else
38-
"@foxglove/strict-equality": "error",
39-
"@foxglove/no-return-promise-resolve": "error",
40-
"@foxglove/prefer-hash-private": "error",
74+
"filenames/match-exported": "error",
4175

42-
// require curly braces everywhere
43-
curly: "error",
76+
// require double equal for null and undefined, triple equal everywhere else
77+
"@foxglove/strict-equality": "error",
78+
"@foxglove/no-return-promise-resolve": "error",
79+
"@foxglove/prefer-hash-private": "error",
4480

45-
// avoid eval
46-
"no-eval": "error",
47-
"no-implied-eval": "error",
48-
"no-new-func": "error",
81+
// require curly braces everywhere
82+
curly: "error",
4983

50-
// unused vars must have `_` prefix
51-
"no-unused-vars": [
52-
"error",
53-
{
54-
vars: "all",
55-
args: "after-used",
56-
varsIgnorePattern: "^_",
57-
argsIgnorePattern: "^_",
58-
},
59-
],
84+
// avoid eval
85+
"no-eval": "error",
86+
"no-implied-eval": "error",
87+
"no-new-func": "error",
6088

61-
"no-underscore-dangle": [
62-
"error",
63-
{
64-
allowAfterThis: true,
65-
},
66-
],
89+
// unused vars must have `_` prefix
90+
"no-unused-vars": [
91+
"error",
92+
{
93+
vars: "all",
94+
args: "after-used",
95+
varsIgnorePattern: "^_",
96+
argsIgnorePattern: "^_",
97+
},
98+
],
6799

68-
// avoid TO.DO and FIX.ME comments, create a ticket to track future work
69-
"no-warning-comments": [
70-
"error",
71-
{
72-
location: "anywhere",
73-
},
74-
],
100+
"no-underscore-dangle": [
101+
"error",
102+
{
103+
allowAfterThis: true,
104+
},
105+
],
106+
107+
// avoid TO.DO and FIX.ME comments, create a ticket to track future work
108+
"no-warning-comments": [
109+
"error",
110+
{
111+
location: "anywhere",
112+
},
113+
],
75114

76-
"no-unused-expressions": ["error", { enforceForJSX: true }],
77-
"no-param-reassign": "error",
78-
"no-useless-rename": "error",
79-
"object-shorthand": "error",
80-
"prefer-arrow-callback": ["error", { allowNamedFunctions: true }],
115+
"no-unused-expressions": ["error", { enforceForJSX: true }],
116+
"no-param-reassign": "error",
117+
"no-useless-rename": "error",
118+
"object-shorthand": "error",
119+
"prefer-arrow-callback": ["error", { allowNamedFunctions: true }],
120+
},
81121
},
82-
};
122+
];

configs/jest.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
module.exports = {
2-
extends: ["plugin:jest/recommended"],
3-
rules: {
4-
"jest/consistent-test-it": ["error", { fn: "it" }],
1+
// @ts-ignore
2+
const jest = require("eslint-plugin-jest");
3+
4+
/** @type {import("eslint").Linter.Config[]} */
5+
module.exports = [
6+
jest.configs["flat/recommended"],
7+
{
8+
rules: {
9+
"jest/consistent-test-it": ["error", { fn: "it" }],
10+
},
511
},
6-
};
12+
];

0 commit comments

Comments
 (0)