@boehringer-ingelheim/eslint-config 7.0.0-shared-configuration-nextjs.4 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -21
- package/configs/base.js +7 -8
- package/configs/experimental-naming-convention.js +68 -0
- package/configs/react.js +2 -2
- package/index.d.ts +18 -0
- package/index.js +2 -0
- package/package.json +10 -7
package/README.md
CHANGED
|
@@ -52,8 +52,7 @@ export default boehringer.config(
|
|
|
52
52
|
);
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
More Information: [ESLint - Configuration Files
|
|
56
|
-
](https://eslint.org/docs/latest/use/configure/configuration-files#extending-configuration-files)
|
|
55
|
+
More Information: [ESLint - Configuration Files](https://eslint.org/docs/latest/use/configure/configuration-files#extending-configuration-files)
|
|
57
56
|
|
|
58
57
|
### Run
|
|
59
58
|
|
|
@@ -63,7 +62,7 @@ npx eslint .
|
|
|
63
62
|
|
|
64
63
|
## Shared Configurations
|
|
65
64
|
|
|
66
|
-
Opinionated Options that differ from the standard/recommended
|
|
65
|
+
Opinionated Options that differ from the standard/recommended ESLint configurations.
|
|
67
66
|
|
|
68
67
|
### Base
|
|
69
68
|
|
|
@@ -85,21 +84,7 @@ The following plugins are used in this configuration:
|
|
|
85
84
|
|
|
86
85
|
Additionally, the [`eslint-plugin-perfectionist`](https://github.com/azat-io/eslint-plugin-perfectionist) is used to automatically fix sorting issues.
|
|
87
86
|
|
|
88
|
-
This configuration also sets up the TypeScript parser [`@typescript-eslint/parser`](https://typescript-eslint.io/packages/parser/) and [`eslint-import-resolver-typescript`](https://github.com/import-js/eslint-import-resolver-typescript).
|
|
89
|
-
|
|
90
|
-
```js
|
|
91
|
-
import boehringer from '@boehringer-ingelheim/eslint-config';
|
|
92
|
-
|
|
93
|
-
export default boehringer.config(boehringer.configs.base, {
|
|
94
|
-
languageOptions: {
|
|
95
|
-
parserOptions: {
|
|
96
|
-
projectService: {
|
|
97
|
-
defaultProject: ['./tsconfig.dev.json'],
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
```
|
|
87
|
+
This configuration also sets up the TypeScript parser [`@typescript-eslint/parser`](https://typescript-eslint.io/packages/parser/) and [`eslint-import-resolver-typescript`](https://github.com/import-js/eslint-import-resolver-typescript).
|
|
103
88
|
|
|
104
89
|
### Local
|
|
105
90
|
|
|
@@ -160,8 +145,6 @@ export default boehringer.config(
|
|
|
160
145
|
|
|
161
146
|
This shared ESLint configuration is specifically tailored for [Next.js](https://nextjs.org/) projects. It extends the [react configuration](#react) and includes the [`@next/eslint-plugin-next`](https://nextjs.org/docs/app/api-reference/config/eslint) plugin with the recommended and [`core-web-vital`](https://nextjs.org/docs/app/api-reference/config/eslint#with-core-web-vitals) rule set. The configuration also adapts the rule `react-refresh/only-export-components` to be compatible with Next.js.
|
|
162
147
|
|
|
163
|
-
It
|
|
164
|
-
|
|
165
148
|
### Playwright
|
|
166
149
|
|
|
167
150
|
```js
|
|
@@ -179,6 +162,20 @@ This shared ESLint configuration is designed to enforce best practices and recom
|
|
|
179
162
|
- [`playwright/prefer-to-have-length`](https://github.com/playwright-community/eslint-plugin-playwright/blob/main/docs/rules/prefer-to-have-length.md): enforces the use of `.toHaveLength()` instead of `.toEqual(n)` when testing the length of an object.
|
|
180
163
|
- [`playwright/require-top-level-describe`](https://github.com/playwright-community/eslint-plugin-playwright/blob/main/docs/rules/require-top-level-describe.md): requires tests to be organized into top-level `describe()` blocks.
|
|
181
164
|
|
|
165
|
+
### (experimental) Naming Convention
|
|
166
|
+
|
|
167
|
+
```js
|
|
168
|
+
import boehringer from '@boehringer-ingelheim/eslint-config';
|
|
169
|
+
|
|
170
|
+
export default boehringer.config(
|
|
171
|
+
boehringer.configs.strict,
|
|
172
|
+
// possibly other configs,
|
|
173
|
+
boehringer.configs.experimentalNamingConvention
|
|
174
|
+
);
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
This shared ESLint configuration is designed to enforce some naming conventions. It uses the [`@typescript-eslint/naming-convention`](https://typescript-eslint.io/rules/naming-convention/) rule for enforcing the naming conventions. The enforced conventions can be found in [configs/naming-convention.js](./configs/naming-convention.js#L7-L65)
|
|
178
|
+
|
|
182
179
|
### Prettier-disable
|
|
183
180
|
|
|
184
181
|
```js
|
|
@@ -200,6 +197,60 @@ This shared ESLint configuration is wrapper around [`eslint-config-disable`](htt
|
|
|
200
197
|
- [`curly`](https://github.com/eslint/eslint/blob/main/docs/src/rules/curly.md) with the (default) option "all": Enforce consistent brace style for all control statements
|
|
201
198
|
- [`no-confusing-arrow`](https://github.com/eslint/eslint/blob/main/docs/src/rules/no-confusing-arrow.md) with allowParens `false` and onlyOneSimpleParam `true`: Disallow arrow functions where they could be confused with comparisons.
|
|
202
199
|
|
|
200
|
+
## Known issues
|
|
201
|
+
|
|
202
|
+
### Parsing error
|
|
203
|
+
|
|
204
|
+
ESLint may throw one of the following errors for some files (even for its own eslint.config.js):
|
|
205
|
+
|
|
206
|
+
- `ESLint was configured to run ... However, that TSConfig does not / none of those TSConfigs include this file`.
|
|
207
|
+
- `... was not found by the project service. Consider either including it in the tsconfig.json or including it in allowDefaultProject`
|
|
208
|
+
|
|
209
|
+
This error is caused by including the respective file in the scope of ESLint but not in the scope of TypeScript. For more information about this error and more suggestions how to solve it you can check the [troubleshooting of typescript-eslint](https://typescript-eslint.io/troubleshooting/typed-linting/#i-get-errors-telling-me--was-not-found-by-the-project-service-consider-either-including-it-in-the-tsconfigjson-or-including-it-in-allowdefaultproject).
|
|
210
|
+
|
|
211
|
+
Our recommendation is to keep type-aware linting of those files.
|
|
212
|
+
|
|
213
|
+
#### Solution 1
|
|
214
|
+
|
|
215
|
+
Include the .(c|m)?js files in your main tsconfig.json:
|
|
216
|
+
|
|
217
|
+
```jsonc
|
|
218
|
+
{
|
|
219
|
+
"include": [
|
|
220
|
+
// your existing includes
|
|
221
|
+
"*.*js", // this will include all .js, .cjs, .mjs files and similar in your project root
|
|
222
|
+
"*.ts", // this will include all .ts files and similar in your project root
|
|
223
|
+
// Add all other files/folders in which this error occurs
|
|
224
|
+
]
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
#### Solution 2
|
|
229
|
+
|
|
230
|
+
You can use the new [`allowDefaultProject`](https://typescript-eslint.io/packages/parser#allowdefaultproject) option, which works perfectly with our [`projectService` configuration](./configs/base.js#L25):
|
|
231
|
+
|
|
232
|
+
```js
|
|
233
|
+
import boehringer from '@boehringer-ingelheim/eslint-config';
|
|
234
|
+
|
|
235
|
+
export default boehringer.config(
|
|
236
|
+
// other configs,
|
|
237
|
+
{
|
|
238
|
+
languageOptions: {
|
|
239
|
+
parserOptions: {
|
|
240
|
+
projectService: {
|
|
241
|
+
allowDefaultProject: [
|
|
242
|
+
'*.*js',
|
|
243
|
+
'.*.*js',
|
|
244
|
+
],
|
|
245
|
+
// defaultProject can be used to specify separate tsconfig options for "out-of-project" files included by allowDefaultProject
|
|
246
|
+
// defaultProject: 'tsconfig.eslint.json',
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
)
|
|
252
|
+
```
|
|
253
|
+
|
|
203
254
|
## Local Development
|
|
204
255
|
|
|
205
256
|
### Install Dependencies
|
|
@@ -255,7 +306,7 @@ Give a ⭐️ if this project helped you!
|
|
|
255
306
|
|
|
256
307
|
## License
|
|
257
308
|
|
|
258
|
-
Copyright © 2023 [Boehringer Ingelheim](https://github.com/boehringer-ingelheim)
|
|
309
|
+
Copyright © 2023 [Boehringer Ingelheim](https://github.com/boehringer-ingelheim).
|
|
259
310
|
This project is [MIT](https://github.com/boehringer-ingelheim/eslint-config/blob/master/LICENSE) licensed.
|
|
260
311
|
|
|
261
312
|
## Resources
|
package/configs/base.js
CHANGED
|
@@ -74,14 +74,13 @@ module.exports = tseslint.config(
|
|
|
74
74
|
|
|
75
75
|
// eslint-plugin-import: https://github.com/import-js/eslint-plugin-import/tree/main/docs/rules
|
|
76
76
|
'import/no-cycle': 'error',
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
],
|
|
77
|
+
/**
|
|
78
|
+
* The rule is disabled for now as it is not compatible with flat-configs, without adding an artifical `.eslintrc` file.
|
|
79
|
+
*
|
|
80
|
+
* @see: https://github.com/import-js/eslint-plugin-import/issues/3079#issuecomment-2557191925
|
|
81
|
+
* @todo Enable rule, as soon as fix is available: https://github.com/Boehringer-Ingelheim/eslint-config/blob/9f028ed43bb5db11082a2982f249ddfe7eaf5c13/configs/base.js#L77
|
|
82
|
+
*/
|
|
83
|
+
'import/no-unused-modules': 'off',
|
|
85
84
|
'import/order': 'off', // disabled due to conflict with eslint-plugin-perfectionist
|
|
86
85
|
'import/prefer-default-export': 'off',
|
|
87
86
|
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const tseslint = require('typescript-eslint');
|
|
2
|
+
|
|
3
|
+
module.exports = tseslint.config({
|
|
4
|
+
rules: {
|
|
5
|
+
'@typescript-eslint/naming-convention': [
|
|
6
|
+
'error',
|
|
7
|
+
{
|
|
8
|
+
// Enforce that interface names do not start with an 'I'
|
|
9
|
+
custom: {
|
|
10
|
+
match: false,
|
|
11
|
+
regex: '^I[A-Z]',
|
|
12
|
+
},
|
|
13
|
+
format: ['StrictPascalCase'],
|
|
14
|
+
leadingUnderscore: 'forbid',
|
|
15
|
+
selector: 'interface',
|
|
16
|
+
trailingUnderscore: 'forbid',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
// Enforce that type alias names do not start with an 'T'
|
|
20
|
+
custom: {
|
|
21
|
+
match: false,
|
|
22
|
+
regex: '^T[A-Z]',
|
|
23
|
+
},
|
|
24
|
+
format: ['StrictPascalCase'],
|
|
25
|
+
leadingUnderscore: 'forbid',
|
|
26
|
+
selector: 'typeAlias',
|
|
27
|
+
trailingUnderscore: 'forbid',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
// Enforce that all top-level variables are in UPPER_CASE
|
|
31
|
+
format: ['UPPER_CASE'],
|
|
32
|
+
leadingUnderscore: 'forbid',
|
|
33
|
+
modifiers: ['global'],
|
|
34
|
+
selector: 'variable',
|
|
35
|
+
trailingUnderscore: 'forbid',
|
|
36
|
+
types: ['boolean', 'number', 'string'],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
// Enforce that all top-level array variables are in UPPER_CASE and are suffixed with a 'S' to indicate plural form
|
|
40
|
+
format: ['UPPER_CASE'],
|
|
41
|
+
leadingUnderscore: 'forbid',
|
|
42
|
+
modifiers: ['global'],
|
|
43
|
+
selector: 'variable',
|
|
44
|
+
suffix: ['S'],
|
|
45
|
+
trailingUnderscore: 'forbid',
|
|
46
|
+
types: ['array'],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
// Enforce that array variables are suffixed with a 's' to indicate plural form
|
|
50
|
+
format: ['strictCamelCase'],
|
|
51
|
+
leadingUnderscore: 'forbid',
|
|
52
|
+
selector: 'variable',
|
|
53
|
+
suffix: ['s'],
|
|
54
|
+
trailingUnderscore: 'forbid',
|
|
55
|
+
types: ['array'],
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
// Enforce that boolean variables are prefixed with an allowed verb
|
|
59
|
+
format: ['StrictPascalCase'],
|
|
60
|
+
leadingUnderscore: 'forbid',
|
|
61
|
+
prefix: ['is', 'has', 'should', 'can'],
|
|
62
|
+
selector: 'variable',
|
|
63
|
+
trailingUnderscore: 'forbid',
|
|
64
|
+
types: ['boolean'],
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
});
|
package/configs/react.js
CHANGED
|
@@ -78,8 +78,8 @@ module.exports = tseslint.config(
|
|
|
78
78
|
'error',
|
|
79
79
|
{
|
|
80
80
|
customGroups: {
|
|
81
|
-
callback: 'on
|
|
82
|
-
reservedProps: ['children', 'dangerouslySetInnerHTML', 'key', 'ref'], // Reserved props from: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/rules/jsx-sort-props.js#
|
|
81
|
+
callback: '^on.+',
|
|
82
|
+
reservedProps: ['children', 'dangerouslySetInnerHTML', 'key', 'ref'], // Reserved props from: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/rules/jsx-sort-props.js#L41-L46
|
|
83
83
|
},
|
|
84
84
|
groups: ['reservedProps', 'unknown', 'callback'],
|
|
85
85
|
ignoreCase: true,
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Config } from 'typescript-eslint';
|
|
2
|
+
|
|
3
|
+
type Configs =
|
|
4
|
+
| 'base'
|
|
5
|
+
| 'experimentalNamingConvention'
|
|
6
|
+
| 'local'
|
|
7
|
+
| 'nextjs'
|
|
8
|
+
| 'playwright'
|
|
9
|
+
| 'prettierDisable'
|
|
10
|
+
| 'react'
|
|
11
|
+
| 'strict';
|
|
12
|
+
|
|
13
|
+
declare module './index' {
|
|
14
|
+
const config: typeof import('typescript-eslint').config;
|
|
15
|
+
const configs: Record<Configs, Config>;
|
|
16
|
+
|
|
17
|
+
export { config, configs };
|
|
18
|
+
}
|
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const tseslint = require('typescript-eslint');
|
|
2
2
|
|
|
3
3
|
const base = require('./configs/base.js');
|
|
4
|
+
const experimentalNamingConvention = require('./configs/experimental-naming-convention.js');
|
|
4
5
|
const local = require('./configs/local.js');
|
|
5
6
|
const nextjs = require('./configs/nextjs.js');
|
|
6
7
|
const playwright = require('./configs/playwright.js');
|
|
@@ -12,6 +13,7 @@ module.exports = {
|
|
|
12
13
|
config: tseslint.config,
|
|
13
14
|
configs: {
|
|
14
15
|
base,
|
|
16
|
+
experimentalNamingConvention,
|
|
15
17
|
local,
|
|
16
18
|
nextjs,
|
|
17
19
|
playwright,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@boehringer-ingelheim/eslint-config",
|
|
3
|
-
"version": "7.0.0
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Shared eslint configuration used at Boehringer Ingelheim for code styling",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"boehringer",
|
|
@@ -15,9 +15,12 @@
|
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"files": [
|
|
17
17
|
"configs",
|
|
18
|
-
"lib"
|
|
18
|
+
"lib",
|
|
19
|
+
"index.js",
|
|
20
|
+
"index.d.ts"
|
|
19
21
|
],
|
|
20
22
|
"main": "index.js",
|
|
23
|
+
"types": "index.d.ts",
|
|
21
24
|
"scripts": {
|
|
22
25
|
"prepare": "husky",
|
|
23
26
|
"release": "dotenv -- semantic-release --no-ci",
|
|
@@ -29,21 +32,21 @@
|
|
|
29
32
|
"eslint": ">= 8"
|
|
30
33
|
},
|
|
31
34
|
"dependencies": {
|
|
32
|
-
"@eslint/js": "^9.
|
|
35
|
+
"@eslint/js": "^9.18.0",
|
|
33
36
|
"@next/eslint-plugin-next": "^15.1.4",
|
|
34
|
-
"eslint-config-prettier": "^
|
|
37
|
+
"eslint-config-prettier": "^10.0.1",
|
|
35
38
|
"eslint-import-resolver-typescript": "^3.7.0",
|
|
36
39
|
"eslint-plugin-import": "^2.31.0",
|
|
37
40
|
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
38
41
|
"eslint-plugin-perfectionist": "^4.6.0",
|
|
39
42
|
"eslint-plugin-playwright": "^2.1.0",
|
|
40
|
-
"eslint-plugin-react": "^7.37.
|
|
43
|
+
"eslint-plugin-react": "^7.37.4",
|
|
41
44
|
"eslint-plugin-react-hooks": "^5.1.0",
|
|
42
|
-
"eslint-plugin-react-refresh": "^0.4.
|
|
45
|
+
"eslint-plugin-react-refresh": "^0.4.18",
|
|
43
46
|
"eslint-plugin-sonarjs": "^1.0.4",
|
|
44
47
|
"globals": "^15.14.0",
|
|
45
48
|
"is-ci": "^4.1.0",
|
|
46
|
-
"typescript-eslint": "^8.
|
|
49
|
+
"typescript-eslint": "^8.20.0"
|
|
47
50
|
},
|
|
48
51
|
"devDependencies": {
|
|
49
52
|
"@boehringer-ingelheim/prettier-config": "2.0.0",
|