@boehringer-ingelheim/eslint-config 7.0.0-migrate-flat-config.1 → 7.0.0-naming-convetion-configuration.2

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 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 eslint configurations.
65
+ Opinionated Options that differ from the standard/recommended ESLint configurations.
67
66
 
68
67
  ### Base
69
68
 
@@ -85,21 +84,20 @@ 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/architecture/parser) and [`eslint-import-resolver-typescript`](https://github.com/import-js/eslint-import-resolver-typescript). The TypeScript project file `./tsconfig.json` is set as default value for the project option in the parser configuration. If this is not the case, this must be changed accordingly:
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). The TypeScript project configuration file `./tsconfig.json` is set as default value in the parser configuration. If this is not the case, this must be changed accordingly:
89
88
 
90
89
  ```js
91
90
  import boehringer from '@boehringer-ingelheim/eslint-config';
92
91
 
93
- export default boehringer.config(
94
- boehringer.configs.base,
95
- {
96
- languageOptions: {
97
- parserOptions: {
98
- project: ['./tsconfig.dev.json'],
92
+ export default boehringer.config(boehringer.configs.base, {
93
+ languageOptions: {
94
+ parserOptions: {
95
+ projectService: {
96
+ defaultProject: ['./tsconfig.dev.json'],
99
97
  },
100
98
  },
101
- }
102
- );
99
+ },
100
+ });
103
101
  ```
104
102
 
105
103
  ### Local
@@ -143,10 +141,24 @@ This shared ESLint configuration is specifically tailored for [React](https://re
143
141
  - [`eslint-plugin-jsx-a11y`](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y)
144
142
  - [`eslint-plugin-react`](https://github.com/jsx-eslint/eslint-plugin-react)
145
143
  - [`eslint-plugin-react-hooks`](https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks)
144
+ - [`eslint-plugin-react-refresh`](https://github.com/ArnaudBarre/eslint-plugin-react-refresh) (with rule severity `warn`)
146
145
 
147
146
  The configuration sets several custom rules, including [`@typescript-eslint/no-restricted-types`](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/no-restricted-types.mdx) and [`@typescript-eslint/consistent-type-definitions`](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/consistent-type-definitions.mdx), as well as rules for organizing and formatting import statements.
148
147
  Additionally in restricts the usage of enums using [`no-restricted-syntax`](https://github.com/eslint/eslint/blob/main/docs/src/rules/no-restricted-syntax.md).
149
148
 
149
+ ### Next.js
150
+
151
+ ```js
152
+ import boehringer from '@boehringer-ingelheim/eslint-config';
153
+
154
+ export default boehringer.config(
155
+ boehringer.configs.strict,
156
+ boehringer.configs.nextjs
157
+ );
158
+ ```
159
+
160
+ 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.
161
+
150
162
  ### Playwright
151
163
 
152
164
  ```js
@@ -164,6 +176,20 @@ This shared ESLint configuration is designed to enforce best practices and recom
164
176
  - [`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.
165
177
  - [`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.
166
178
 
179
+ ### Naming Convention
180
+
181
+ ```js
182
+ import boehringer from '@boehringer-ingelheim/eslint-config';
183
+
184
+ export default boehringer.config(
185
+ boehringer.configs.strict,
186
+ // possibly other configs,
187
+ boehringer.configs.namingConvention
188
+ );
189
+ ```
190
+
191
+ 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)
192
+
167
193
  ### Prettier-disable
168
194
 
169
195
  ```js
@@ -185,6 +211,69 @@ This shared ESLint configuration is wrapper around [`eslint-config-disable`](htt
185
211
  - [`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
186
212
  - [`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.
187
213
 
214
+ ## Known issues
215
+
216
+ ### Parsing error
217
+
218
+ ESLint may throw the following error for some files (even for its own eslint.config.js): `ESLint was configured to run ... However, that TSConfig does not / none of those TSConfigs include this file`.
219
+
220
+ 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 [FAQ of typescript-eslint](https://typescript-eslint.io/troubleshooting/typed-linting/#i-get-errors-telling-me-eslint-was-configured-to-run--however-that-tsconfig-does-not--none-of-those-tsconfigs-include-this-file).
221
+
222
+ Our recommendation is to keep type-aware linting of those files.
223
+
224
+ #### Solution 1
225
+
226
+ Include the .(c|m)?js files in your main tsconfig.json:
227
+
228
+ ```json
229
+ {
230
+ "include": [
231
+ // your existing includes
232
+ "*.*js", // this will include all .js, .cjs, .mjs files and similar in your project root
233
+ "*.ts", // this will include all .ts files and similar in your project root
234
+ // Add all other files/folders in which this error occurs
235
+ ]
236
+ }
237
+ ```
238
+
239
+ #### Solution 2
240
+
241
+ Extend your main tsconfig.json in a tsconfig.eslint.json (or similar) which includes those files and ensures allowJs is set to true, which is used in a similar way by typescript-eslint in [their own repo](https://github.com/typescript-eslint/typescript-eslint/tree/v8.20.0):
242
+
243
+ ```json
244
+ {
245
+ "compilerOptions": {
246
+ "noEmit": true,
247
+ "allowJs": true
248
+ },
249
+ "extends": "./tsconfig.json",
250
+ "include": [
251
+ // you have to add here all the items from your original tsconfig.json as it overwrites the whole array
252
+ "*.*js", // this will include all .js, .cjs, .mjs files and similar in your project root
253
+ "*.ts", // this will include all .ts files and similar in your project root
254
+ // Add all other files/folders in which this error occurs
255
+ ]
256
+ }
257
+ ```
258
+
259
+ In this case you have to overwrite the configured tsconfig file:
260
+
261
+ ```js
262
+ import boehringer from '@boehringer-ingelheim/eslint-config';
263
+
264
+ export default boehringer.config(
265
+ // other configs,
266
+ {
267
+ languageOptions: {
268
+ parserOptions: {
269
+ project: './tsconfig.eslint.json',
270
+ tsconfigRootDir: __dirname,
271
+ },
272
+ },
273
+ },
274
+ )
275
+ ```
276
+
188
277
  ## Local Development
189
278
 
190
279
  ### Install Dependencies
@@ -240,7 +329,7 @@ Give a ⭐️ if this project helped you!
240
329
 
241
330
  ## License
242
331
 
243
- Copyright © 2023 [Boehringer Ingelheim](https://github.com/boehringer-ingelheim).<br />
332
+ Copyright © 2023 [Boehringer Ingelheim](https://github.com/boehringer-ingelheim).
244
333
  This project is [MIT](https://github.com/boehringer-ingelheim/eslint-config/blob/master/LICENSE) licensed.
245
334
 
246
335
  ## Resources
package/configs/base.js CHANGED
@@ -22,7 +22,7 @@ module.exports = tseslint.config(
22
22
  languageOptions: {
23
23
  parserOptions: {
24
24
  // find the tsconfig.json nearest each source file
25
- project: true,
25
+ projectService: true,
26
26
  },
27
27
  },
28
28
  linterOptions: {
@@ -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
- 'import/no-unused-modules': [
78
- 'error',
79
- {
80
- missingExports: true,
81
- src: ['.'],
82
- unusedExports: true,
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
 
@@ -95,14 +94,14 @@ module.exports = tseslint.config(
95
94
  'perfectionist/sort-classes': [
96
95
  'error',
97
96
  {
98
- ...perfectionist.configs['recommended-natural-legacy'].rules['perfectionist/sort-classes'][1],
97
+ ...perfectionist.configs['recommended-natural'].rules['perfectionist/sort-classes'][1],
99
98
  groups: SORT_CLASSES_GROUPS,
100
99
  },
101
100
  ],
102
101
  'perfectionist/sort-imports': [
103
102
  'error',
104
103
  {
105
- ...perfectionist.configs['recommended-natural-legacy'].rules['perfectionist/sort-imports'][1],
104
+ ...perfectionist.configs['recommended-natural'].rules['perfectionist/sort-imports'][1],
106
105
  groups: SORT_IMPORTS_GROUPS,
107
106
  newlinesBetween: 'ignore',
108
107
  },
@@ -110,21 +109,21 @@ module.exports = tseslint.config(
110
109
  'perfectionist/sort-intersection-types': [
111
110
  'error',
112
111
  {
113
- ...perfectionist.configs['recommended-natural-legacy'].rules['perfectionist/sort-intersection-types'][1],
112
+ ...perfectionist.configs['recommended-natural'].rules['perfectionist/sort-intersection-types'][1],
114
113
  groups: SORT_INTERSECTION_TYPES_GROUPS,
115
114
  },
116
115
  ],
117
116
  'perfectionist/sort-named-imports': [
118
117
  'error',
119
118
  {
120
- ...perfectionist.configs['recommended-natural-legacy'].rules['perfectionist/sort-named-imports'][1],
119
+ ...perfectionist.configs['recommended-natural'].rules['perfectionist/sort-named-imports'][1],
121
120
  ignoreAlias: true,
122
121
  },
123
122
  ],
124
123
  'perfectionist/sort-objects': [
125
124
  'error',
126
125
  {
127
- ...perfectionist.configs['recommended-natural-legacy'].rules['perfectionist/sort-objects'][1],
126
+ ...perfectionist.configs['recommended-natural'].rules['perfectionist/sort-objects'][1],
128
127
  partitionByComment: true,
129
128
  },
130
129
  ],
@@ -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
+ });
@@ -0,0 +1,46 @@
1
+ const nextPlugin = require('@next/eslint-plugin-next');
2
+ const tseslint = require('typescript-eslint');
3
+
4
+ const react = require('./react.js');
5
+
6
+ module.exports = tseslint.config(
7
+ ...react,
8
+ {
9
+ plugins: {
10
+ '@next/next': nextPlugin,
11
+ },
12
+ rules: {
13
+ // eslint-plugin-react-refresh: https://github.com/ArnaudBarre/eslint-plugin-react-refresh
14
+ 'react-refresh/only-export-components': [
15
+ 'warn',
16
+ {
17
+ /**
18
+ * Next.js allows exporting the following options in pages, layouts and route handlers
19
+ *
20
+ * @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config
21
+ */
22
+ allowExportNames: [
23
+ 'config',
24
+ 'dynamic',
25
+ 'dynamicParams',
26
+ 'fetchCache',
27
+ 'generateMetadata',
28
+ 'generateStaticParams',
29
+ 'generateViewport',
30
+ 'maxDuration',
31
+ 'metadata',
32
+ 'preferredRegion',
33
+ 'revalidate',
34
+ 'runtime',
35
+ 'viewport',
36
+ ],
37
+ },
38
+ ],
39
+ ...nextPlugin.configs.recommended.rules,
40
+ ...nextPlugin.configs['core-web-vitals'].rules,
41
+ },
42
+ },
43
+ {
44
+ ignores: ['.next/*'],
45
+ },
46
+ );
package/configs/react.js CHANGED
@@ -13,6 +13,7 @@ module.exports = tseslint.config(
13
13
  jsxA11y.flatConfigs.recommended,
14
14
  react.configs.flat.recommended,
15
15
  react.configs.flat['jsx-runtime'],
16
+ reactRefresh.configs.recommended,
16
17
  {
17
18
  languageOptions: {
18
19
  globals: {
@@ -25,9 +26,7 @@ module.exports = tseslint.config(
25
26
  },
26
27
  },
27
28
  plugins: {
28
- 'jsx-a11y': jsxA11y,
29
29
  'react-hooks': reactHooks,
30
- 'react-refresh': reactRefresh,
31
30
  },
32
31
  rules: {
33
32
  // @typescript-eslint: https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/eslint-plugin/docs/rules
@@ -79,8 +78,8 @@ module.exports = tseslint.config(
79
78
  'error',
80
79
  {
81
80
  customGroups: {
82
- callback: 'on*',
83
- reservedProps: ['children', 'dangerouslySetInnerHTML', 'key', 'ref'], // Reserved props from: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/rules/jsx-sort-props.js#L40C12-L40C12
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
84
83
  },
85
84
  groups: ['reservedProps', 'unknown', 'callback'],
86
85
  ignoreCase: true,
package/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { Config } from 'typescript-eslint';
2
+
3
+ type Configs = 'base' | 'local' | 'nextjs' | 'playwright' | 'prettierDisable' | 'react' | 'strict';
4
+
5
+ declare module './index' {
6
+ const config: typeof import('typescript-eslint').config;
7
+ const configs: Record<Configs, Config>;
8
+
9
+ export { config, configs };
10
+ }
package/index.js CHANGED
@@ -2,6 +2,8 @@ const tseslint = require('typescript-eslint');
2
2
 
3
3
  const base = require('./configs/base.js');
4
4
  const local = require('./configs/local.js');
5
+ const namingConvention = require('./configs/naming-convention.js');
6
+ const nextjs = require('./configs/nextjs.js');
5
7
  const playwright = require('./configs/playwright.js');
6
8
  const prettierDisable = require('./configs/prettier-disable.js');
7
9
  const react = require('./configs/react.js');
@@ -12,6 +14,8 @@ module.exports = {
12
14
  configs: {
13
15
  base,
14
16
  local,
17
+ namingConvention,
18
+ nextjs,
15
19
  playwright,
16
20
  prettierDisable,
17
21
  react,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boehringer-ingelheim/eslint-config",
3
- "version": "7.0.0-migrate-flat-config.1",
3
+ "version": "7.0.0-naming-convetion-configuration.2",
4
4
  "description": "Shared eslint configuration used at Boehringer Ingelheim for code styling",
5
5
  "keywords": [
6
6
  "boehringer",
@@ -15,45 +15,49 @@
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",
24
27
  "release:ci": "semantic-release",
25
- "repair": "npx --no rimraf .git/hooks node_modules package-lock.json && npm install",
28
+ "repair": "npx --no rimraf@6 .git/hooks node_modules package-lock.json && npm install",
26
29
  "lint": "eslint ."
27
30
  },
28
31
  "peerDependencies": {
29
32
  "eslint": ">= 8"
30
33
  },
31
34
  "dependencies": {
32
- "@eslint/js": "^9.17.0",
33
- "eslint-config-prettier": "^9.1.0",
35
+ "@eslint/js": "^9.18.0",
36
+ "@next/eslint-plugin-next": "^15.1.4",
37
+ "eslint-config-prettier": "^10.0.1",
34
38
  "eslint-import-resolver-typescript": "^3.7.0",
35
39
  "eslint-plugin-import": "^2.31.0",
36
40
  "eslint-plugin-jsx-a11y": "^6.10.2",
37
- "eslint-plugin-perfectionist": "^4.3.0",
41
+ "eslint-plugin-perfectionist": "^4.6.0",
38
42
  "eslint-plugin-playwright": "^2.1.0",
39
- "eslint-plugin-react": "^7.37.2",
43
+ "eslint-plugin-react": "^7.37.4",
40
44
  "eslint-plugin-react-hooks": "^5.1.0",
41
- "eslint-plugin-react-refresh": "^0.4.16",
45
+ "eslint-plugin-react-refresh": "^0.4.18",
42
46
  "eslint-plugin-sonarjs": "^1.0.4",
43
47
  "globals": "^15.14.0",
44
48
  "is-ci": "^4.1.0",
45
- "typescript-eslint": "^8.18.1"
49
+ "typescript-eslint": "^8.20.0"
46
50
  },
47
51
  "devDependencies": {
48
52
  "@boehringer-ingelheim/prettier-config": "2.0.0",
49
- "@commitlint/cli": "19.6.0",
53
+ "@commitlint/cli": "19.6.1",
50
54
  "@commitlint/config-conventional": "19.6.0",
51
55
  "@commitlint/types": "19.5.0",
52
56
  "@semantic-release/changelog": "6.0.3",
53
57
  "@semantic-release/git": "10.0.1",
54
- "dotenv-cli": "7.4.4",
58
+ "dotenv-cli": "8.0.0",
55
59
  "husky": "9.1.7",
56
60
  "prettier": "3.4.2",
57
- "semantic-release": "24.2.0"
61
+ "semantic-release": "24.2.1"
58
62
  }
59
63
  }