Skip to content

Commit 4fa0548

Browse files
jackwmcknashharrison90academojoshhunt
authored
chore: import eslint config (#2723)
Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com> Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> Co-authored-by: Esteban Beltran <academo@users.noreply.github.com> Co-authored-by: Esteban Beltran <sergies@gmail.com> Co-authored-by: Josh Hunt <joshhunt@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: Timur Olzhabayev <timur.olzhabayev@grafana.com> Co-authored-by: Tom Ratcliffe <tom.ratcliffe@grafana.com>
1 parent e71e6ce commit 4fa0548

9 files changed

Lines changed: 406 additions & 2 deletions

File tree

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* @grafana/grafana-catalog @grafana/grafana-frontend-platform
33

44
/packages/create-plugin/ @grafana/grafana-frontend-platform
5+
/packages/eslint-config/ @grafana/grafana-frontend-platform
56
/packages/eslint-plugin-plugins/ @grafana/grafana-catalog
67
/packages/plugin-docs-parser/ @grafana/grafana-catalog
78
/packages/plugin-docs-cli/ @grafana/grafana-catalog

.release-please-manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
"packages/plugin-types-bundler": "0.6.0",
99
"packages/react-detect": "0.7.1",
1010
"packages/sign-plugin": "3.3.1",
11-
"packages/tsconfig": "2.2.0"
11+
"packages/tsconfig": "2.2.0",
12+
"packages/eslint-config": "10.0.0"
1213
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Changelog
2+
3+
## 10.0.0
4+
5+
- Support Eslint 10
6+
- Add typescript declaration
7+
- Replace @stylistic/eslint-plugin-ts with @stylistic/eslint-plugin
8+
9+
- **Breaking**: Drop support for eslint 7 and legacy configs
10+
- **Breaking**: Make package ESM
11+
12+
## 9.0.0
13+
14+
- **Breaking**: Update react hooks plugin to v7
15+
16+
## 8.0.0
17+
18+
- **Breaking**: Migrate dependencies to peerDependencies. Please make sure to install peerDependencies when using this package.
19+
- Add flat config for Eslint 9 support.
20+
21+
## 7.0.0
22+
23+
- Bump dependencies.
24+
25+
## 6.0.1
26+
27+
- Remove @typescript-eslint/explicit-member-accessibility rule.
28+
29+
## 6.0.0
30+
31+
- Bump dependencies.
32+
33+
## 5.1.0
34+
35+
- Bump dependencies to support Node 18.
36+
37+
## 5.0.0
38+
39+
- Add no-var rule.
40+
41+
## 4.0.0
42+
43+
- Bump dependencies.
44+
45+
## 3.0.0
46+
47+
- Remove eslint-plugin-prettier.
48+
49+
## 2.5.2
50+
51+
- Bump dependencies.
52+
53+
## 2.5.1
54+
55+
- Update eslint-config-prettier and eslint-plugin-jsdoc.
56+
- Report react-hooks/exhaustive-deps as error.
57+
58+
## 2.5.0
59+
60+
- Update typescript to 4.3.4.
61+
- Update @typescript-eslint/eslint-plugin and @typescript-eslint/parser.
62+
63+
## 2.4.0
64+
65+
- Update typescript to 4.2.4.
66+
- Update @typescript-eslint/eslint-plugin and @typescript-eslint/parser.
67+
68+
## 2.3.0
69+
70+
- Update Eslint dependency.
71+
72+
## 2.2.1
73+
74+
- Bump dependencies.
75+
76+
## 2.2.0
77+
78+
- Add no-duplicate-imports.
79+
80+
## 2.1.1
81+
82+
- Update eslint-plugin-prettier.
83+
84+
## 2.1.0
85+
86+
- Update Prettier and eslint-config-prettier.
87+
88+
## 2.0.6
89+
90+
- Adds eslint-plugin-react with recommended setings enabled.
91+
92+
## 2.0.5
93+
94+
- Allow console info statements.
95+
96+
## 2.0.4
97+
98+
- Bump eslint-plugin-react-hooks to 4.1.2.
99+
100+
## 2.0.3
101+
102+
- Pin dependencies to specific versions.
103+
104+
## 2.0.2
105+
106+
- Migrate peerDependencies to dependencies.
107+
108+
## 2.0.1
109+
110+
- Bump dependencies.
111+
112+
## 2.0.0
113+
114+
- Bump dependencies.
115+
116+
## 1.0.0-rc1
117+
118+
Initial release candidate.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Contributing to Grafana / Eslint Config
2+
3+
We are always grateful to receive contributions!<br />
4+
The following guidelines help you on how to start with the codebase and how to submit your work.
5+
6+
## Installation
7+
8+
### Prerequisites
9+
10+
You need to have `npm` installed.
11+
12+
### Installing
13+
14+
```bash
15+
git clone git@github.com:grafana/plugin-tools.git
16+
cd plugin-tools
17+
npm install
18+
```
19+
20+
## Overview
21+
22+
### Folder structure
23+
24+
_Work in progress._
25+
26+
## Development
27+
28+
Please read the main [contributing guide](../../CONTRIBUTING.md) before contributing any code changes to the project.
29+
30+
### Commmands
31+
32+
This package has no scripts/commands to run. The `.js` and `.d.ts` files are published as is.
33+
34+
### Conventions
35+
36+
It's probable that _any_ change will be a breaking one, so it's best to stick to major version releases whenever possible.

packages/eslint-config/README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Grafana / Eslint Config
2+
3+
> Grafana's [ESLint](https://eslint.org) config.
4+
5+
## Installation
6+
7+
```shell
8+
npm install @grafana/eslint-config --save-dev
9+
```
10+
11+
Don't forget to install peerDependencies.
12+
13+
1. Install the correct versions of each package, which are listed by the command:
14+
15+
```sh
16+
npm info "@grafana/eslint-config@latest" peerDependencies
17+
```
18+
19+
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.
20+
21+
## Configuration (new: eslint.config.js)
22+
23+
From v8.21.0, Eslint introduced a new flat config system where `eslint.config.js` replaces `.eslintrc*` as the default config file name. Eslint@8.x supports both systems, while Eslint@9.x only supports the new flat config.
24+
25+
A guide on how to migrate to a flat config can be found [here](https://eslint.org/docs/latest/extend/plugin-migration-flat-config).
26+
27+
The following official blog posts are available for interested parties:
28+
29+
- https://eslint.org/blog/2022/08/new-config-system-part-1/
30+
- https://eslint.org/blog/2022/08/new-config-system-part-2/
31+
- https://eslint.org/blog/2022/08/new-config-system-part-3/
32+
33+
This package contains a single flat config object which can be imported like so:
34+
35+
```js
36+
const grafanaConfig = require("@grafana/eslint-config/flat");
37+
38+
/**
39+
* @type {Array<import('eslint').Linter.Config>}
40+
*/
41+
module.exports = [
42+
...grafanaConfig,
43+
/* rest of your config */
44+
];
45+
```
46+
47+
You are then free to add/override properties.
48+
49+
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.
50+
51+
```js
52+
const grafanaConfig = require('@grafana/eslint-config/flat');
53+
54+
/**
55+
* @type {Array<import('eslint').Linter.Config>}
56+
*/
57+
module.exports = [
58+
{
59+
ignores: ['.github', '.yarn', '**/build/', '**/compiled/', '**/dist/'],
60+
},
61+
...grafanaConfig,
62+
{
63+
name: 'myproject/defaults',
64+
files: ['**/*.{ts,tsx,js,jsx}'],
65+
rules: {
66+
// add custom rules here.
67+
},
68+
},
69+
];
70+
```
71+
72+
## Configuration (legacy: .eslintrc\*)
73+
74+
Extend our configuration to get reasonable defaults:
75+
76+
```json
77+
{
78+
"extends": ["@grafana/eslint-config"]
79+
}
80+
```
81+
82+
It will automatically handle `*.(js|ts|tsx)` files.

packages/eslint-config/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Linter } from 'eslint';
2+
3+
declare const config: Linter.Config[];
4+
5+
export default config;

packages/eslint-config/index.js

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

0 commit comments

Comments
 (0)