Skip to content

Commit b2466c7

Browse files
authored
Merge pull request #41 from grafana/jackw/support-eslint-9
Feat: Add flat config for Eslint 9 support
2 parents 3dbafad + 1efee16 commit b2466c7

File tree

10 files changed

+1335
-1474
lines changed

10 files changed

+1335
-1474
lines changed

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1+
.yarn/
2+
!.yarn/patches
3+
!.yarn/releases
4+
!.yarn/plugins
5+
!.yarn/sdks
6+
!.yarn/versions
7+
18
node_modules
2-
.idea/
9+
.idea/

.yarn/install-state.gz

-219 KB
Binary file not shown.

CHANGELOG.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Grafana Eslint config changelog
2+
3+
## 8.0.0
4+
5+
- **Breaking**: Migrate dependencies to peerDependencies. Please make sure to install peerDependencies when using this package.
6+
- Add flat config for Eslint 9 support.
7+
8+
## 7.0.0
9+
10+
- Bump dependencies.
11+
12+
## 6.0.1
13+
14+
- Remove @typescript-eslint/explicit-member-accessibility rule.
15+
16+
## 6.0.0
17+
18+
- Bump dependencies.
19+
20+
## 5.1.0
21+
22+
- Bump dependencies to support Node 18.
23+
24+
## 5.0.0
25+
26+
- Add no-var rule.
27+
28+
## 4.0.0
29+
30+
- Bump dependencies.
31+
32+
## 3.0.0
33+
34+
- Remove eslint-plugin-prettier.
35+
36+
## 2.5.2
37+
38+
- Bump dependencies.
39+
40+
## 2.5.1
41+
42+
- Update eslint-config-prettier and eslint-plugin-jsdoc.
43+
- Report react-hooks/exhaustive-deps as error.
44+
45+
## 2.5.0
46+
47+
- Update typescript to 4.3.4.
48+
- Update @typescript-eslint/eslint-plugin and @typescript-eslint/parser.
49+
50+
## 2.4.0
51+
52+
- Update typescript to 4.2.4.
53+
- Update @typescript-eslint/eslint-plugin and @typescript-eslint/parser.
54+
55+
## 2.3.0
56+
57+
- Update Eslint dependency.
58+
59+
## 2.2.1
60+
61+
- Bump dependencies.
62+
63+
## 2.2.0
64+
65+
- Add no-duplicate-imports.
66+
67+
## 2.1.1
68+
69+
- Update eslint-plugin-prettier.
70+
71+
## 2.1.0
72+
73+
- Update Prettier and eslint-config-prettier.
74+
75+
## 2.0.6
76+
77+
- Adds eslint-plugin-react with recommended setings enabled.
78+
79+
## 2.0.5
80+
81+
- Allow console info statements.
82+
83+
## 2.0.4
84+
85+
- Bump eslint-plugin-react-hooks to 4.1.2.
86+
87+
## 2.0.3
88+
89+
- Pin dependencies to specific versions.
90+
91+
## 2.0.2
92+
93+
- Migrate peerDependencies to dependencies.
94+
95+
## 2.0.1
96+
97+
- Bump dependencies.
98+
99+
## 2.0.0
100+
101+
- Bump dependencies.
102+
103+
## 1.0.0-rc1
104+
105+
Initial release candidate.

CONTRIBUTING.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## Contributing
2+
3+
To contribute to this project, begin by cloning or forking the repository.
4+
5+
Ensure you have all dependencies installed by navigating to the project folder and running:
6+
7+
```shell
8+
yarn install
9+
```
10+
11+
### Creating a Feature Branch
12+
13+
Before making changes, create a new feature branch. This helps keep your work isolated and makes it easier to review.
14+
15+
```shell
16+
git checkout master
17+
git pull master
18+
git checkout -b <feature-branch-name>
19+
```
20+
21+
### Checking Issues First
22+
23+
Before working on a new feature or bug fix, please check the open issues in the repository. If there's an issue related to what you're working on, comment on it to let others know you'd like to work on it. This helps avoid duplicated efforts.
24+
25+
If there isn't an existing issue, consider creating one to provide visibility and context for your contribution.
26+
27+
### Updating the Changelog
28+
29+
When making changes that warrant a version update, please append to the changelog. The changelog helps others understand what has changed between releases.
30+
31+
Add a new entry to the changelog with a summary of your changes and the relevant version. Be sure to do this when updating the version number.
32+
33+
### Publishing
34+
35+
Publishing is handled by a GitHub workflow, which is triggered whenever there is a merge to `master` that contains a change to the version property in the `package.json` file. You can either update the version manually or use the command below to version bump, commit, and tag.
36+
37+
```shell
38+
npm version [<newversion> | major | minor | patch ]
39+
```
40+
41+
### Versioning
42+
43+
It's probable that _any_ change will be a breaking one, so it's best to stick to major version releases whenever possible.
44+
45+
### Submitting a Pull Request
46+
47+
When your changes are ready, push your feature branch to the remote repository and open a pull request (PR) against the `master` branch. In your PR description, provide a clear summary of the changes, including any relevant issue numbers. Request a review, and address any feedback provided by reviewers.
48+
49+
Thanks for your contribution!

README.md

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ Don't forget to install peerDependencies.
2222
npm info "@grafana/eslint-config@latest" peerDependencies
2323
```
2424

25-
If using **npm 5+**, use this shortcut
25+
If using **npm 5+**, use this command:
2626

2727
```sh
2828
npx install-peerdeps --dev @grafana/eslint-config
2929
```
3030

31-
If using **yarn**, you can also use the shortcut described above if you have npm 5+ installed on your machine, as the command will detect that you are using yarn and will act accordingly.
32-
Otherwise, run `npm info "@grafana/eslint-config@latest" peerDependencies` to list the peer dependencies and versions, then run `yarn add --dev <dependency>@<version>` for each listed peer dependency.
31+
If using a different package manager, run `npm info "@grafana/eslint-config@latest" peerDependencies` to list the peer dependencies and versions. Then run `yarn add --dev <dependency1>@<version> <dependency2>@<version> <dependency3>@<version>` for the listed peer dependencies.
3332

34-
## Usage
33+
## Configuration (legacy: .eslintrc\*)
34+
35+
Extend our configuration to get reasonable defaults:
3536

3637
```json
3738
{
@@ -41,16 +42,54 @@ Otherwise, run `npm info "@grafana/eslint-config@latest" peerDependencies` to li
4142

4243
It will automatically handle `*.(js|ts|tsx)` files.
4344

44-
## Publishing
45+
## Configuration (new: eslint.config.js)
4546

46-
Publishing is handled by github actions which is triggered by a merge to master that contains a change to the version property in the `package.json` file. You can either do that manually or use the command below to version bump, commit and tag.
47+
From v8.21.0, Eslint introduced a new flat config system where `eslint.config.js` replaces `.eslintrc*` as the default config file name. [email protected] supports both systems, while [email protected] only supports the new flat config.
4748

48-
```shell
49-
npm version [<newversion> | major | minor | patch ]
50-
```
49+
A guide on how to migrate to a flat config can be found [here](https://eslint.org/docs/latest/extend/plugin-migration-flat-config).
50+
51+
The following official blog posts are available for interested parties:
5152

52-
Also be sure to update any official packages that depend on this with fixes and version increases.
53+
- https://eslint.org/blog/2022/08/new-config-system-part-1/
54+
- https://eslint.org/blog/2022/08/new-config-system-part-2/
55+
- https://eslint.org/blog/2022/08/new-config-system-part-3/
5356

54-
## Versioning
57+
This package contains a single flat config object which can be imported like so:
5558

56-
It's probable that _any_ change will be a breaking one, so it's best to stick to major version releases.
59+
```js
60+
const grafanaConfig = require("@grafana/eslint-config/flat");
61+
62+
/**
63+
* @type {Array<import('eslint').Linter.Config>}
64+
*/
65+
module.exports = [
66+
{
67+
grafanaConfig,
68+
},
69+
];
70+
```
71+
72+
You are then free to add/override properties.
73+
74+
Note: Our shareable configs does not preconfigure `files`, `ignore`, or `languageOptions.globals`. For most of the cases, you probably want to configure some properties for your project.
75+
76+
```js
77+
const grafanaConfig = require("@grafana/eslint-config/flat");
78+
79+
/**
80+
* @type {Array<import('eslint').Linter.Config>}
81+
*/
82+
module.exports = [
83+
{
84+
ignores: [".github", ".yarn", "**/build/", "**/compiled/", "**/dist/"],
85+
},
86+
grafanaConfig,
87+
{
88+
name: "myproject/defaults",
89+
files: ["**/*.{ts,tsx,js,jsx}"],
90+
rules: {
91+
// add custom rules here.
92+
},
93+
},
94+
];
95+
```

base.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Note: Base config used for building both the legacy and flat configs.
2+
// It is not a valid ESLint config.
3+
4+
const baseConfig = {
5+
ecmaVersion: 2019,
6+
sourceType: "module",
7+
parserOptions: {
8+
ecmaFeatures: {
9+
jsx: true,
10+
},
11+
},
12+
rules: {
13+
curly: "error",
14+
"dot-notation": "off",
15+
"eol-last": "error",
16+
eqeqeq: ["error", "always", { null: "ignore" }],
17+
"guard-for-in": "off",
18+
"jsdoc/check-alignment": "error",
19+
"new-parens": "error",
20+
"no-array-constructor": "error",
21+
"no-bitwise": "off",
22+
"no-caller": "error",
23+
"no-cond-assign": "error",
24+
"no-console": ["error", { allow: ["error", "log", "warn", "info"] }],
25+
"no-debugger": "error",
26+
"no-empty": "off",
27+
"no-eval": "error",
28+
"no-fallthrough": "off",
29+
"no-new-wrappers": "error",
30+
"no-redeclare": "error",
31+
"no-restricted-imports": ["error", "moment"],
32+
"no-shadow": "off",
33+
"no-unused-expressions": "off",
34+
"no-unused-labels": "error",
35+
"no-var": "error",
36+
radix: "error",
37+
"sort-keys": "off",
38+
"spaced-comment": ["off", "always"],
39+
"use-isnan": "error",
40+
"no-duplicate-imports": "error",
41+
"@typescript-eslint/no-unused-expressions": [
42+
"error",
43+
{ allowShortCircuit: true, allowTernary: true },
44+
],
45+
"@typescript-eslint/array-type": ["error", { default: "array-simple" }],
46+
"@typescript-eslint/naming-convention": [
47+
"error",
48+
{
49+
selector: "interface",
50+
format: ["PascalCase"],
51+
custom: {
52+
regex: "^I[A-Z]",
53+
match: false,
54+
},
55+
},
56+
],
57+
"@typescript-eslint/consistent-type-assertions": "error",
58+
"@typescript-eslint/no-inferrable-types": "error",
59+
"@typescript-eslint/no-namespace": ["error", { allowDeclarations: false }],
60+
"@typescript-eslint/no-unused-vars": "off",
61+
"@typescript-eslint/no-use-before-define": "off",
62+
"@typescript-eslint/triple-slash-reference": "error",
63+
"@stylistic/ts/type-annotation-spacing": [
64+
"error",
65+
{
66+
after: true,
67+
before: false,
68+
overrides: {
69+
arrow: { after: true, before: true },
70+
},
71+
},
72+
],
73+
"react-hooks/exhaustive-deps": "error",
74+
},
75+
settings: {
76+
react: {
77+
version: "detect",
78+
},
79+
},
80+
};
81+
82+
module.exports = baseConfig;

flat.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const jsdoc = require("eslint-plugin-jsdoc");
2+
const reactHooksPlugin = require("eslint-plugin-react-hooks");
3+
const reactPlugin = require("eslint-plugin-react");
4+
const tsPlugin = require("@typescript-eslint/eslint-plugin");
5+
const typescriptParser = require("@typescript-eslint/parser");
6+
const prettierConfig = require("eslint-config-prettier");
7+
const stylisticTs = require("@stylistic/eslint-plugin-ts");
8+
9+
const baseConfig = require("./base");
10+
11+
/**
12+
* @type {Array<import('eslint').Linter.Config>}
13+
*/
14+
module.exports = {
15+
name: "@grafana/eslint-config/flat",
16+
...reactHooksPlugin.configs.recommended,
17+
...reactPlugin.configs.flat.recommended,
18+
...prettierConfig,
19+
settings: baseConfig.settings,
20+
plugins: {
21+
jsdoc,
22+
"@typescript-eslint": tsPlugin,
23+
"react-hooks": reactHooksPlugin,
24+
"@stylistic/ts": stylisticTs,
25+
},
26+
languageOptions: {
27+
parser: typescriptParser,
28+
ecmaVersion: baseConfig.ecmaVersion,
29+
sourceType: baseConfig.sourceType,
30+
parserOptions: baseConfig.parserOptions,
31+
},
32+
rules: baseConfig.rules,
33+
};

0 commit comments

Comments
 (0)