@boehringer-ingelheim/eslint-config 7.0.0-typescript-eslint-parser-options.1 → 7.1.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 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,22 +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/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:
89
-
90
- ```js
91
- import boehringer from '@boehringer-ingelheim/eslint-config';
92
-
93
- export default boehringer.config(
94
- boehringer.configs.base,
95
- {
96
- languageOptions: {
97
- parserOptions: {
98
- project: ['./tsconfig.dev.json'],
99
- },
100
- },
101
- }
102
- );
103
- ```
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).
104
88
 
105
89
  ### Local
106
90
 
@@ -143,10 +127,24 @@ This shared ESLint configuration is specifically tailored for [React](https://re
143
127
  - [`eslint-plugin-jsx-a11y`](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y)
144
128
  - [`eslint-plugin-react`](https://github.com/jsx-eslint/eslint-plugin-react)
145
129
  - [`eslint-plugin-react-hooks`](https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks)
130
+ - [`eslint-plugin-react-refresh`](https://github.com/ArnaudBarre/eslint-plugin-react-refresh) (with rule severity `warn`)
146
131
 
147
132
  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
133
  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
134
 
135
+ ### Next.js
136
+
137
+ ```js
138
+ import boehringer from '@boehringer-ingelheim/eslint-config';
139
+
140
+ export default boehringer.config(
141
+ boehringer.configs.strict,
142
+ boehringer.configs.nextjs
143
+ );
144
+ ```
145
+
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.
147
+
150
148
  ### Playwright
151
149
 
152
150
  ```js
@@ -164,6 +162,20 @@ This shared ESLint configuration is designed to enforce best practices and recom
164
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.
165
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.
166
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
+
167
179
  ### Prettier-disable
168
180
 
169
181
  ```js
@@ -185,6 +197,60 @@ This shared ESLint configuration is wrapper around [`eslint-config-disable`](htt
185
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
186
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.
187
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
+
188
254
  ## Local Development
189
255
 
190
256
  ### Install Dependencies
@@ -240,7 +306,7 @@ Give a ⭐️ if this project helped you!
240
306
 
241
307
  ## License
242
308
 
243
- Copyright © 2023 [Boehringer Ingelheim](https://github.com/boehringer-ingelheim).<br />
309
+ Copyright © 2023 [Boehringer Ingelheim](https://github.com/boehringer-ingelheim).
244
310
  This project is [MIT](https://github.com/boehringer-ingelheim/eslint-config/blob/master/LICENSE) licensed.
245
311
 
246
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
- '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
 
@@ -138,7 +137,7 @@ module.exports = tseslint.config(
138
137
  {
139
138
  files: [
140
139
  '**/*.d.ts', // TypeScript declaration files
141
- '**/*.{spec,test}.*', // Usually test files
140
+ '**/*.{spec,test}.{js,cjs,mjs,jsx,ts,cts,mts,tsx}', // Usually test files
142
141
  './*.{js,cjs,mjs,ts,cts,mts}', // Mostly configuration files on root level
143
142
  ],
144
143
  rules: {
@@ -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,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,7 +1,9 @@
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');
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');
@@ -11,7 +13,9 @@ module.exports = {
11
13
  config: tseslint.config,
12
14
  configs: {
13
15
  base,
16
+ experimentalNamingConvention,
14
17
  local,
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-typescript-eslint-parser-options.1",
3
+ "version": "7.1.0",
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.19.0",
36
+ "@next/eslint-plugin-next": "^15.1.6",
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",
38
- "eslint-plugin-playwright": "^2.1.0",
39
- "eslint-plugin-react": "^7.37.2",
41
+ "eslint-plugin-perfectionist": "^4.8.0",
42
+ "eslint-plugin-playwright": "^2.2.0",
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.23.0"
46
50
  },
47
51
  "devDependencies": {
48
52
  "@boehringer-ingelheim/prettier-config": "2.0.0",
49
- "@commitlint/cli": "19.6.0",
50
- "@commitlint/config-conventional": "19.6.0",
53
+ "@commitlint/cli": "19.7.1",
54
+ "@commitlint/config-conventional": "19.7.1",
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
  }