eslint-config-beslogic 2.1.0 → 2.3.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.
@@ -0,0 +1,16 @@
1
+ Thank you for your contribution to Beslogic's **ESLint-Config-Beslogic** repo.
2
+ Before submitting this PR, please make sure:
3
+
4
+ - [ ] The project is building
5
+ - [ ] There are no linting issues
6
+ - [ ] You updated the projects' README.md and CHANGELOG.md with the new changes
7
+ - [ ] You reviewed your own PR and made sure there's no test/debug code or any obvious mistakes.
8
+ - [ ] You set and configured auto-complete to "Complete associated work items after merging" & "Delete \<branch> after merging".
9
+ - [ ] You cleaned up your commit history or set the PR Merge type to "Squash".
10
+
11
+ Make sure that the code wasn't copied from elsewhere (check one):
12
+
13
+ - [ ] This is your own original code
14
+ - [ ] You have made sure that we have permission to use the copied code and that we follow its licensing
15
+
16
+ _Add a short description_
package/CHANGELOG.md CHANGED
@@ -2,6 +2,70 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 2.3.0
6
+
7
+ - Allow single element equality for `@typescript-eslint/prefer-string-starts-ends-with`
8
+ - Disabled `unicorn/prefer-string-raw` for json-like and eslintrc.json
9
+ - Set tsconfig's `angularCompilerOptions.enableI18nLegacyMessageIdFormat` to `false`
10
+ - Set tsconfig's `compilerOptions.target` to `"ES2022"`
11
+ For more details, see [this `@angular/cli` warning](https://github.com/angular/angular-cli/blob/16.2.0/packages/angular_devkit/build_angular/src/tools/webpack/plugins/typescript.ts#L36-L39)
12
+ - Presets for Jest now consider the framework (Angular, React, or DOM)
13
+ - Updated Jest file matching to Jest's default patterns
14
+ - No longer leaving empty strings for eslint extends generated by NX
15
+ - Fixed an invalid syntax for `@nx/js` patching
16
+
17
+ ## 2.2.1
18
+
19
+ - Bumped `eslint-plugin-react` to `^7.33`
20
+ - Check context objects with `react/display-name`
21
+ - Added React 18 deprecations
22
+ - Remove accidental recommendation to install `eslint-plugn-react-redux` from non-redux presets in `README.md`
23
+ - Now enforce at least 1 newline after imports even with dprint preset.
24
+ - Turn on `allowImplicit`, `checkForEach`, and `allowVoid` for rule `array-callback-return`
25
+ - Bumped `eslint-plugin-total-functions` to `>=6.0`
26
+ - which bumps `typescript` dependency to `4.7.3`
27
+ - Bumped `eslint-plugin-testing-library` to `^6.0` which enables a lot more rules by default
28
+ - Bumped `eslint-plugin-unicorn` to `>=49.0`
29
+ - Re-enabled `prefer-event-target` in Angular preset
30
+ - Disabled deprecated `unicorn/no-unsafe-regex`
31
+ - Start checking arguments again for `unicorn/no-useless-undefined`
32
+ now that it can also autofix `undefined` defaults to optional parameters
33
+ - Re-enabled `unicorn/no-nested-ternary`, which allows a single nested level if parenthesised
34
+ - Bumped `eslint-plugin-sonarjs` to `^1.0`
35
+ - Updated vulnerable dependencies
36
+ - They updated their license
37
+ - Bumped `eslint-plugin-simple-import-sort` to `>=12.0`
38
+ - Bumped `eslint-plugin-regexp` to `^2.0`
39
+ - Reduced dependencies
40
+ - Removal of deprecated rules: <https://github.com/ota-meshi/eslint-plugin-regexp#removed>
41
+ - Bumped `eslint-plugin-jest` to `^28.0.0`
42
+ - `jest/no-if` has been replaced by `jest/no-conditional-in-test`
43
+ - `jest/prefer-importing-jest-globals` is enabled by default, which removes needing a dependency
44
+ on often outdated `@types/jest` and removes the need for `types: ["jest"]` in `tsconfig.json`
45
+ - Bumped `dprint` to `^0.40.2` to prepare for process plugins
46
+ - Bumped `@typescript-eslint/eslint-plugin` to `^7.4`
47
+ - Re-enabled `@typescript-eslint/no-import-type-side-effects`
48
+ and set `@typescript-eslint/consistent-type-imports` back to default options
49
+ - Bumped `eslint` to `^8.56`
50
+ - which bumps `typescript` dependency to `4.7.5`
51
+ - Prefered `@typescript-eslint/prefer-destructuring` over `autofix/prefer-destructuring`
52
+ - Disabled `@typescript-eslint/key-spacing`, `autofix/func-call-spacing`,
53
+ and `lines-around-comment` in `dprint` preset
54
+ - Patched-out prettier from nx generators
55
+ - Used Search&Replace based package patching:
56
+ - Removes `patch-package` from dependencies
57
+ - Removes bundled git patches
58
+ - Speedup check for `eslint-plugin-total-functions` install
59
+ - Bumped `eslint-plugin-n` to `>=16.2`. Notably, this:
60
+ - improves support for ts-node
61
+ - Updates documentation links
62
+ - Sets Node 16 as the minimal default w/o having to configure `engines` in `package.json`
63
+ - Allow for automatic ts mapping detection
64
+ - Re-enabled `n/no-unpublished-*` rules by default as it's now based on package being public/private
65
+ - Set `ignoreTypeImport: true` by default for `n/no-unpublished-import`
66
+
67
+ ## 2.1.0
68
+
5
69
  - Bumped the following minimum versions:
6
70
  - `@angular-eslint/eslint-plugin@>=16.2`
7
71
  - `@angular-eslint/eslint-plugin-template@>=16.2`
@@ -12,7 +76,7 @@
12
76
  - Assuming `node>=16`, `typescript>=4.5` and `@angular/compiler>=16.2.5`
13
77
  - This should speedup config parsing that had to check for specific versions
14
78
  - Made `eslint-plugin-total-functions` optional due to its extra-strictness and it had to be
15
- explicitly specified anyway due to version resolution issues.
79
+ explicitly specified anyway due to version resolution issues
16
80
  - Added link to changelog in README
17
81
  - Improved detection of installed peer dependencies' version number to be more accurate and faster
18
82
 
@@ -26,7 +90,7 @@
26
90
 
27
91
  ## 2.0.0
28
92
 
29
- - Created CHANGELOG.md
93
+ - Created `CHANGELOG.md`
30
94
  - Changed the maximum line length from `120` to `100`
31
95
  - Split language-specific `editor.defaultFormatter` to work around
32
96
  <https://github.com/microsoft/vscode/issues/168411>
package/README.md CHANGED
@@ -45,7 +45,7 @@ Extend the following in your base `tsconfig.json` (follow link for more details)
45
45
  "extends": "eslint-config-beslogic/tsconfig.4.3.json",
46
46
  ```
47
47
 
48
- "No Unchecked Indexed Access" makes index accesses even stricter. You may not want it in your project. You can disable it with `"compilerOptions": { "noUncheckedIndexedAccess": false }`.
48
+ "No Unchecked Indexed Access" makes index accesses even stricter. You may not want it in your project or in your tests. You can disable it with `"compilerOptions": { "noUncheckedIndexedAccess": false }`.
49
49
 
50
50
  If deploying / bundling with an Angular npm package, also set `angularCompilerOptions": { "strictMetadataEmit": true }`
51
51
 
@@ -99,7 +99,7 @@ Default preset, extends from `beslogic/javascript` and `beslogic/typescript`.
99
99
 
100
100
  ### `beslogic/jest`
101
101
 
102
- [Jest](https://www.npmjs.com/package/jest) and [Testing Library](https://testing-library.com/) configs. Is already extended by `beslogic/javascript` and `beslogic/typescript` for all `*spec.[jt]s` and `*.test.[jt]sx` files. You should not need to extend from this configuration unless you want to add it to a test file that is not automatically picked up by the naming convention.
102
+ [Jest](https://www.npmjs.com/package/jest) and [Testing Library](https://testing-library.com/) configs. Is already extended by `beslogic/javascript` and `beslogic/typescript` for all `*spec.[jt]s` and `*.test.[jt]sx` files, as well as `*.[jt]s` and `*.[jt]sx` files inside of `__tests__` folders. You should not need to extend from this configuration unless you want to add it to a test file that is not automatically picked up by the naming convention.
103
103
 
104
104
  ### `beslogic/javascript`
105
105
 
@@ -141,7 +141,7 @@ Configurations for React projects. Comes with `JSX` support.
141
141
  Add the following `devDependencies` to your `package.json`:
142
142
 
143
143
  ```shell
144
- npm install --save-dev eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-redux eslint-plugin-react-prefer-function-component
144
+ npm install --save-dev eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-prefer-function-component
145
145
  ```
146
146
 
147
147
  ### `beslogic/react-native`
@@ -151,7 +151,7 @@ Configurations for [React Native](https://reactnative.dev/) projects, including
151
151
  Add the following `devDependencies` to your `package.json`:
152
152
 
153
153
  ```shell
154
- npm install --save-dev eslint-plugin-react-native eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-redux eslint-plugin-react-prefer-function-component
154
+ npm install --save-dev eslint-plugin-react-native eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-prefer-function-component
155
155
  ```
156
156
 
157
157
  ### `beslogic/react-redux`
@@ -161,7 +161,7 @@ Configurations for React projects using the Redux bindings. Already extends `bes
161
161
  Add the following `devDependencies` to your `package.json`:
162
162
 
163
163
  ```shell
164
- npm install --save-dev eslint-plugin-react-redux eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-redux eslint-plugin-react-prefer-function-component
164
+ npm install --save-dev eslint-plugin-react-redux eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-prefer-function-component
165
165
  ```
166
166
 
167
167
  ### `beslogic/mui`
@@ -171,7 +171,7 @@ npm install --save-dev eslint-plugin-react-redux eslint-plugin-jsx-a11y eslint-p
171
171
  Add the following `devDependencies` to your `package.json`:
172
172
 
173
173
  ```shell
174
- npm install --save-dev eslint-plugin-mui eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-redux eslint-plugin-react-prefer-function-component
174
+ npm install --save-dev eslint-plugin-mui eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-prefer-function-component
175
175
  ```
176
176
 
177
177
  ### `beslogic/angular`
@@ -179,7 +179,7 @@ npm install --save-dev eslint-plugin-mui eslint-plugin-jsx-a11y eslint-plugin-re
179
179
  Configurations for NGX projects. Comes with `html` template and inline template support. Already extends `beslogic/rxjs` and `beslogic/typescript`. Also extends `beslogic/node-js` for Javascript files.
180
180
 
181
181
  For the linting to be fully effective, please make sure that your base `tsconfig.json` extends `eslint-config-beslogic/tsconfig.X.X.json` (see [Parallel configurations](#parallel-configurations)).\
182
- If bundling with an npm package set `"strictMetadataEmit": true` under `angularCompilerOptions`.
182
+ If bundling as an npm package set `"strictMetadataEmit": true` under `angularCompilerOptions`.
183
183
 
184
184
  Add the following `devDependencies` to your `package.json`:
185
185
 
package/angular.js CHANGED
@@ -1,9 +1,10 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Copyright 2024 Beslogic Inc.
3
3
 
4
- const { getModuleVersion, jestNoRestrictedSyntax } = require("./lib/utils")
4
+ const { getModuleVersion, jestNoRestrictedSyntax, jestFilePatterns } = require("./lib/utils")
5
5
 
6
- const angularEslintPluginVersion = getModuleVersion("@angular-eslint/eslint-plugin", 16.2)
6
+ const angularEslintVersion = getModuleVersion("@angular-eslint/eslint-plugin", 16.2)
7
+ const typescriptVersion = getModuleVersion("typescript", 4.7)
7
8
 
8
9
  const javascriptConfig = require("./javascript")
9
10
  const typescriptConfig = require("./typescript")
@@ -17,6 +18,8 @@ const noRestrictedSyntax = [
17
18
  "message":
18
19
  "Angular hooks need to be functions defined on the prototype: https://github.com/angular/angular/issues/7270#issuecomment-201137617"
19
20
  },
21
+ // TODO: Possibly implement that ourselves?
22
+ // Upstream request: https://github.com/MelvinVermeer/eslint-plugin-no-relative-import-paths/issues/30
20
23
  {
21
24
  "selector": "ImportDeclaration[source.value=/\\.\\.\\u002F?$/]",
22
25
  "message": "Don't use imports that ends in \"..\" or \"../\""
@@ -90,7 +93,7 @@ module.exports = {
90
93
  ],
91
94
  // Autofix for this rule was broken: https://github.com/angular-eslint/angular-eslint/pull/1602
92
95
  // somewhat fixed in 16.1, but not proper: https://github.com/angular-eslint/angular-eslint/issues/1197
93
- "@angular-eslint/template/attributes-order": angularEslintPluginVersion >= 17.1
96
+ "@angular-eslint/template/attributes-order": angularEslintVersion >= 17.1
94
97
  ? "error"
95
98
  : "off",
96
99
  // and it was added in 14.2.0. Not enforcing it for now allows a wider range of versions.
@@ -178,7 +181,7 @@ module.exports = {
178
181
  // https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/README.md#parseroptionscreatedefaultprogram
179
182
  "deprecated__createDefaultProgram": true,
180
183
  // Needed specifically for @typescript-eslint/consistent-type-imports
181
- "emitDecoratorMetadata": true
184
+ "emitDecoratorMetadata": typescriptVersion >= 5
182
185
  },
183
186
  "rules": {
184
187
  /*
@@ -277,27 +280,6 @@ module.exports = {
277
280
  "@typescript-eslint/no-invalid-this": "off",
278
281
  // Redundant with Angular's dependecy injection
279
282
  "@typescript-eslint/parameter-properties": "off",
280
-
281
- /*
282
- * These two configs are meant to work around the following issue wit Decorators:
283
- * https://github.com/typescript-eslint/typescript-eslint/issues/5468#issuecomment-1906180432
284
- * Once the following PR is merged, we can check for that specific @typescript-eslint version
285
- * to only apply the workaround before it.
286
- * https://github.com/typescript-eslint/typescript-eslint/pull/8335
287
- */
288
- // This only relates to TypeScript 5.0's --verbatimModuleSyntax,
289
- // by not enforcing this rule yet, we are not loosing much compared to what we had before.
290
- // We have to disable it for the "fixStyle: 'inline-type-imports'" workaround to be allowed at all time
291
- "@typescript-eslint/no-import-type-side-effects": "off",
292
- "@typescript-eslint/consistent-type-imports": [
293
- "error",
294
- {
295
- // Sets the autofix to use `import { type A } from '...'` which works around the above mentionned issue
296
- // This only affects autofixing to help devs not aware of this edge case, both styles are always allowed.
297
- "fixStyle": "inline-type-imports"
298
- }
299
- ],
300
-
301
283
  "unicorn/no-keyword-prefix": [
302
284
  "error",
303
285
  {
@@ -308,8 +290,6 @@ module.exports = {
308
290
  ]
309
291
  }
310
292
  ],
311
- // False positives with Angular's EventEmitter: https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1853
312
- "unicorn/prefer-event-target": "off",
313
293
  // Angular is ESM
314
294
  "unicorn/prefer-module": "error",
315
295
  // This is not supported in Angular's Vite builder https://github.com/angular/angular-cli/issues/26507
@@ -361,7 +341,8 @@ module.exports = {
361
341
  }
362
342
  },
363
343
  {
364
- "files": ["*spec.ts"],
344
+ "files": jestFilePatterns,
345
+ "extends": ["plugin:testing-library/angular"],
365
346
  "rules": { "no-restricted-syntax": jestNoRestrictedSyntax(noRestrictedSyntax) }
366
347
  },
367
348
  {
package/dprint.js CHANGED
@@ -177,11 +177,13 @@ module.exports = {
177
177
  "computed-property-spacing": "off",
178
178
  "autofix/computed-property-spacing": "off",
179
179
  "func-call-spacing": "off",
180
+ "autofix/func-call-spacing": "off",
180
181
  "@typescript-eslint/func-call-spacing": "off",
181
182
  "generator-star-spacing": "off",
182
183
  "autofix/generator-star-spacing": "off",
183
184
  "key-spacing": "off",
184
185
  "autofix/key-spacing": "off",
186
+ "@typescript-eslint/key-spacing": "off",
185
187
  "keyword-spacing": "off",
186
188
  "autofix/keyword-spacing": "off",
187
189
  "@typescript-eslint/keyword-spacing": "off",
@@ -224,8 +226,9 @@ module.exports = {
224
226
  /*
225
227
  * Unconfigurable or unknown linked configuration
226
228
  */
227
- "@typescript-eslint/lines-around-comment": "off",
229
+ "lines-around-comment": "off",
228
230
  "autofix/lines-around-comment": "off",
231
+ "@typescript-eslint/lines-around-comment": "off",
229
232
  "no-extra-parens": "off",
230
233
  "autofix/no-extra-parens": "off",
231
234
  "@typescript-eslint/no-extra-parens": "off",
@@ -236,8 +239,7 @@ module.exports = {
236
239
  "new-parens": "off",
237
240
  "autofix/new-parens": "off",
238
241
  "no-floating-decimal": "off",
239
- "autofix/no-floating-decimal": "off",
240
- "import/newline-after-import": "off"
242
+ "autofix/no-floating-decimal": "off"
241
243
  }
242
244
  }
243
245
  ]
package/javascript.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 Beslogic Inc.
3
3
 
4
4
  const restrictedGlobals = require("confusing-browser-globals")
5
- const { jestNoRestrictedSyntax } = require("./lib/utils")
5
+ const { jestNoRestrictedSyntax, jestFilePatterns } = require("./lib/utils")
6
6
 
7
7
  const commaDangleDefault = "always-multiline"
8
8
  const idLenghtConfig = {
@@ -69,7 +69,7 @@ module.exports = {
69
69
  ],
70
70
  "extends": [
71
71
  "eslint:recommended",
72
- "plugin:sonarjs/recommended",
72
+ "plugin:sonarjs/recommended-legacy",
73
73
  "plugin:unicorn/all",
74
74
  "plugin:regexp/all",
75
75
  "plugin:import/recommended",
@@ -90,6 +90,7 @@ module.exports = {
90
90
  "ignorePatterns": ["node_modules/"],
91
91
  // Useful when using experimental features and code transpiled by Babel
92
92
  "parser": "@babel/eslint-parser",
93
+ "reportUnusedDisableDirectives": true,
93
94
  "overrides": [
94
95
  {
95
96
  "files": [
@@ -378,10 +379,7 @@ module.exports = {
378
379
  }
379
380
  },
380
381
  {
381
- "files": [
382
- "*spec.js",
383
- ".test.jsx"
384
- ],
382
+ "files": jestFilePatterns,
385
383
  "extends": ["./jest"],
386
384
  "rules": { "no-restricted-syntax": jestNoRestrictedSyntax(noRestrictedSyntax) }
387
385
  },
@@ -392,7 +390,11 @@ module.exports = {
392
390
  ],
393
391
  // To reconsider, since this would conflict with a simple dprint default
394
392
  // "extends": ["./json-like"]
395
- "globals": { "module": true }
393
+ "globals": { "module": true },
394
+ "rules": {
395
+ // Keep consistent with preset rules
396
+ "unicorn/prefer-string-raw": "off"
397
+ }
396
398
  }
397
399
  ],
398
400
  "rules": {
@@ -430,9 +432,18 @@ module.exports = {
430
432
  { "considerQueryString": true }
431
433
  ],
432
434
  "import/no-empty-named-blocks": "error",
435
+ // exactCount has issues with require, at least that's taken care of by dprint:
436
+ // https://github.com/import-js/eslint-plugin-import/issues/2905
437
+ // With https://github.com/dprint/dprint-plugin-typescript/issues/394 we could disable this
438
+ // rule entirely in dprint preset.
433
439
  "import/newline-after-import": [
434
440
  "error",
435
- { "considerComments": true }
441
+ {
442
+ /* eslint-disable-next-line etc/no-commented-out-code
443
+ -- see above comment, bump minimal eslint-plugin-import when this is fixed and enforced */
444
+ // "exactCount": false,
445
+ "considerComments": true
446
+ }
436
447
  ],
437
448
  "import/no-named-as-default": "error",
438
449
  "import/no-named-as-default-member": "error",
@@ -469,6 +480,9 @@ module.exports = {
469
480
  "case": "camelCase"
470
481
  }
471
482
  ],
483
+ // Only works on 3 node imports by default, and can't configure a default for all imports.
484
+ // Leave it up to the programmer.
485
+ "unicorn/import-style": "off",
472
486
  "unicorn/no-array-reduce": [
473
487
  "error",
474
488
  {
@@ -486,16 +500,10 @@ module.exports = {
486
500
  ]
487
501
  }
488
502
  ],
489
- "unicorn/no-nested-ternary": "off",
490
503
  "unicorn/no-null": "off",
491
- // Not as bad in frontend environment
492
- "unicorn/no-unsafe-regex": "warn",
493
- "unicorn/no-useless-undefined": [
494
- "error",
495
- {
496
- "checkArguments": false
497
- }
498
- ],
504
+ // This rule has been deprecated in favor of eslint-plugin-regexp
505
+ "unicorn/no-unsafe-regex": "off",
506
+ "unicorn/no-useless-undefined": "error",
499
507
  "unicorn/numeric-separators-style": "error",
500
508
  "unicorn/prefer-add-event-listener": "error",
501
509
  "unicorn/prefer-array-find": [
@@ -623,6 +631,8 @@ module.exports = {
623
631
  ],
624
632
  // I don't think this is that much more readable imo. Especially for regexp beginners
625
633
  "regexp/prefer-named-capture-group": "off",
634
+ // TODO: Re-enable once VSCode has syntax highlighting for the v flag
635
+ "regexp/require-unicode-sets-regexp": "off",
626
636
  // Obsoleted by eslint-plugin-regexp
627
637
  "no-invalid-regexp": "off",
628
638
  "prefer-named-capture-group": "off",
@@ -633,7 +643,10 @@ module.exports = {
633
643
  * Excludes rules taken care of by eslint-plugin-autofix
634
644
  */
635
645
  "accessor-pairs": "error",
636
- "array-callback-return": "error",
646
+ "array-callback-return": [
647
+ "error",
648
+ { "allowImplicit": true, "checkForEach": true, "allowVoid": true }
649
+ ],
637
650
  "block-scoped-var": "error",
638
651
  "camelcase": "error",
639
652
  "class-methods-use-this": "error",
@@ -828,7 +841,8 @@ module.exports = {
828
841
  ],
829
842
  "patterns": [
830
843
  {
831
- // no-realtive-import paths doesn't catch ./..
844
+ // no-relative-import paths doesn't catch ./..
845
+ // TODO: Consider fixing ourselves
832
846
  // https://github.com/MelvinVermeer/eslint-plugin-no-relative-import-paths/issues/30
833
847
  "group": ["./../"],
834
848
  "message": "Relative parent imports are not allowed."
package/jest.js CHANGED
@@ -1,12 +1,17 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Copyright 2024 Beslogic Inc.
3
+ const { getModuleVersion } = require("./lib/utils")
4
+
5
+ const jestGlobalsVersion = getModuleVersion("@jest/globals", 29)
3
6
 
4
7
  /** @type {import("eslint").Linter.Config} */
5
8
  module.exports = {
6
9
  "extends": [
7
10
  "plugin:jest/all",
8
11
  "plugin:jest-formatting/strict",
9
- "plugin:testing-library/angular"
12
+ // Note: The DOM preset includes some rules not in Marko or Vue (eg.: no-await-sync-events).
13
+ // Those must be disabled in their preset if we ever support them.
14
+ "plugin:testing-library/dom"
10
15
  ],
11
16
  "env": {
12
17
  "browser": false,
@@ -67,6 +72,12 @@ module.exports = {
67
72
  "onlyFunctionsWithExpectInLoop": true
68
73
  }
69
74
  ],
75
+ // https://github.com/jestjs/jest/issues/15084
76
+ // Since this will require a major jest version bump anyway,
77
+ // I feel confortable not waiting for our own major version bump to add this
78
+ ...(jestGlobalsVersion < 30
79
+ ? { "jest/prefer-importing-jest-globals": "off" }
80
+ : {}),
70
81
  // Top-level describe is often used for component name, which is capitalized
71
82
  "jest/prefer-lowercase-title": [
72
83
  "error",
@@ -78,6 +89,13 @@ module.exports = {
78
89
  {
79
90
  "allow": ["beforeEach"]
80
91
  }
81
- ]
92
+ ],
93
+
94
+ /*
95
+ * testing-library overrides (https://github.com/testing-library/eslint-plugin-testing-library#supported-rules)
96
+ */
97
+ "testing-library/no-debugging-utils": "error",
98
+ "testing-library/prefer-user-event": "warn",
99
+ "testing-library/prefer-explicit-assert": "error"
82
100
  }
83
101
  }
package/json-like.js CHANGED
@@ -29,6 +29,7 @@ module.exports = {
29
29
  "error",
30
30
  "double"
31
31
  ],
32
- "autofix/quote-props": "error"
32
+ "autofix/quote-props": "error",
33
+ "unicorn/prefer-string-raw": "off"
33
34
  }
34
35
  }
@@ -0,0 +1,161 @@
1
+ const { readFileSync, writeFileSync } = require("node:fs")
2
+ const { join, dirname } = require("node:path")
3
+ const { resolveModuleLocation } = require("./utils")
4
+
5
+ // ANSI color chart: https://en.m.wikipedia.org/wiki/ANSI_escape_code#Colors
6
+
7
+ const searchAndReplace = async (
8
+ /** @type {string} */ file,
9
+ /** @type {{from: string | RegExp, to: string}[]} */ replacements
10
+ ) => {
11
+ try {
12
+ /* eslint-disable n/no-sync -- We're a script running in async methods */
13
+ let data = readFileSync(file, "utf8")
14
+ for (const replacement of replacements) {
15
+ data = data.replaceAll(replacement.from, replacement.to)
16
+ }
17
+ writeFileSync(file, data, "utf8")
18
+ /* eslint-enable n/no-sync */
19
+ } catch (error) {
20
+ console.error(
21
+ "\n\u001B[31m" +
22
+ `The following error happenned while patching ${file} with eslint-config-beslogic. ` +
23
+ "Please contact samuel.therrien@beslogic.com with the package version and the full error to get it fixed." +
24
+ "\u001B[0m"
25
+ )
26
+ throw error
27
+ }
28
+ }
29
+
30
+ const getPackageBase = (/** @type {string} */ packageName) => {
31
+ const location = resolveModuleLocation(`${packageName}/package.json`)
32
+ if (!location) {
33
+ console.info(
34
+ `\n\u001B[32m${packageName} not found in node_modules, no need to patch.\u001B[0m`
35
+ )
36
+
37
+ return
38
+ }
39
+
40
+ return dirname(location)
41
+ }
42
+
43
+ const patches = [
44
+ async () => {
45
+ const packageName = "@angular/material"
46
+ const base = getPackageBase(packageName)
47
+ if (!base) return
48
+ await searchAndReplace(
49
+ join(base, "dialog", "index.d.ts"),
50
+ [
51
+ {
52
+ "from": "MatDialogRef<T, R = any>",
53
+ "to": "MatDialogRef<T, R = void>"
54
+ }
55
+ ]
56
+ )
57
+
58
+ return packageName
59
+ },
60
+
61
+ async () => {
62
+ const packageName = "@nx/angular"
63
+ const base = getPackageBase(packageName)
64
+ if (!base) return
65
+ await Promise.all([
66
+ searchAndReplace(
67
+ join(base, "src", "generators", "add-linting", "lib", "create-eslint-configuration.js"),
68
+ [
69
+ // Remove code that adds preset extensions
70
+ // plugin:@nx/angular-template
71
+ // plugin:@nx/angular
72
+ // plugin:@angular-eslint/template/process-inline-templates
73
+ {
74
+ "from": /'plugin:.+?',?/gu,
75
+ "to": ""
76
+ },
77
+ // Remove empty extends
78
+ {
79
+ "from": /extends: \[\s*\],?/gu,
80
+ "to": ""
81
+ }
82
+ ]
83
+ ),
84
+ // Patch out prettier
85
+ searchAndReplace(
86
+ join(base, "src", "generators", "ng-add", "utilities", "workspace.js"),
87
+ [
88
+ {
89
+ "from": "!packageJson.devDependencies['prettier']",
90
+ "to": "false"
91
+ },
92
+ {
93
+ "from": "esbenp.prettier-vscode",
94
+ "to": ""
95
+ }
96
+ ]
97
+ )
98
+ ])
99
+
100
+ return packageName
101
+ },
102
+ async () => {
103
+ const packageName = "@nx/eslint"
104
+ const base = getPackageBase(packageName)
105
+ if (!base) return
106
+ // Patch out prettier
107
+ await searchAndReplace(
108
+ join(base, "src", "generators", "lint-project", "setup-root-eslint.js"),
109
+ [
110
+ {
111
+ "from": /'eslint-config-prettier':.+?,/gu,
112
+ "to": ""
113
+ }
114
+ ]
115
+ )
116
+
117
+ return packageName
118
+ },
119
+ async () => {
120
+ const packageName = "@nx/js"
121
+ const base = getPackageBase(packageName)
122
+ if (!base) return
123
+ // Patch out prettier
124
+ await searchAndReplace(
125
+ join(base, "src", "generators", "init", "init.js"),
126
+ [
127
+ {
128
+ "from": /prettier:.+?,/gu,
129
+ "to": ""
130
+ },
131
+ {
132
+ "from": "if (prettierrcNameOptions",
133
+ "to": "if (false && prettierrcNameOptions"
134
+ },
135
+ {
136
+ "from": "!tree.exists(`.prettierignore`)",
137
+ "to": "false"
138
+ },
139
+ {
140
+ "from": "!json.recommendations.includes(extension)",
141
+ "to": "false"
142
+ },
143
+ {
144
+ // eslint-disable-next-line regexp/no-super-linear-move -- Is it really?
145
+ "from": /.+?devkit_1\.ensurePackage\)\('prettier'.+?[\n;]/gu,
146
+ "to": ""
147
+ }
148
+ ]
149
+ )
150
+
151
+ return packageName
152
+ }
153
+ ].map(patch =>
154
+ patch().then(packageName =>
155
+ packageName && console.info(
156
+ `\n\u001B[32m${packageName} patched successfully! Now go write great code!\u001B[0m`
157
+ )
158
+ )
159
+ )
160
+
161
+ Promise.all(patches)
package/lib/utils.js CHANGED
@@ -6,12 +6,25 @@ const getModuleVersion = (
6
6
  // eslint-disable-next-line n/global-require -- Dynamic loading
7
7
  return Number.parseFloat(require(`${nodeModule}/package.json`).version)
8
8
  } catch (error) {
9
- console.warn(error)
9
+ if (
10
+ !(error instanceof Error &&
11
+ error.message.startsWith(`Cannot find module '${nodeModule}/package.json'`))
12
+ ) {
13
+ console.warn(error)
14
+ }
10
15
 
11
16
  return fallbackVersion
12
17
  }
13
18
  }
14
19
 
20
+ const resolveModuleLocation = (/** @type {string} */ nodeModule) => {
21
+ try {
22
+ return require.resolve(nodeModule)
23
+ } catch {
24
+ return false
25
+ }
26
+ }
27
+
15
28
  const jestNoRestrictedSyntax = (
16
29
  /** @type {(string | number | { selector: string; })[]} */ noRestrictedSyntax
17
30
  ) =>
@@ -23,7 +36,15 @@ const jestNoRestrictedSyntax = (
23
36
  !entry.selector.startsWith("ArrowFunctionExpression")
24
37
  )
25
38
 
39
+ // Matching Jest's own default file patterns: https://jestjs.io/docs/configuration#testmatch-arraystring
40
+ const jestFilePatterns = [
41
+ "**/__tests__/**/*.[jt]s?(x)",
42
+ "**/?(*.)+(spec|test).[jt]s?(x)"
43
+ ]
44
+
26
45
  module.exports = {
27
46
  getModuleVersion,
28
- jestNoRestrictedSyntax
47
+ jestNoRestrictedSyntax,
48
+ resolveModuleLocation,
49
+ jestFilePatterns
29
50
  }
package/node-js.js CHANGED
@@ -32,20 +32,22 @@ module.exports = {
32
32
  },
33
33
  "rules": {
34
34
  // Node settings (https://github.com/eslint-community/eslint-plugin-n#readme)
35
- "n/handle-callback-err": "error",
36
- "n/no-callback-literal": "error",
37
- "n/no-new-require": "error",
38
- "n/no-path-concat": "error",
39
- "n/no-process-exit": "error",
40
35
  "n/callback-return": "error",
41
36
  "n/exports-style": "error",
37
+ "n/global-require": "error",
38
+ "n/handle-callback-err": "error",
39
+ "n/no-callback-literal": "error",
42
40
  "n/no-extraneous-import": [
43
41
  "error",
44
42
  {
45
43
  "allowModules": ["ws"]
46
44
  }
47
45
  ],
48
- "n/global-require": "error",
46
+ "n/no-new-require": "error",
47
+ "n/no-path-concat": "error",
48
+ "n/no-process-exit": "error",
49
+ // Doesn't really work
50
+ "n/no-missing-import": "off",
49
51
  "n/no-mixed-requires": "error",
50
52
  "n/no-restricted-import": "error",
51
53
  "n/no-restricted-require": "error",
@@ -53,6 +55,12 @@ module.exports = {
53
55
  "error",
54
56
  { "allowAtRootLevel": true }
55
57
  ],
58
+ "n/no-unpublished-import": [
59
+ "error",
60
+ {
61
+ "ignoreTypeImport": true
62
+ }
63
+ ],
56
64
  "n/prefer-global/buffer": "error",
57
65
  "n/prefer-global/console": "error",
58
66
  "n/prefer-global/process": "error",
@@ -60,21 +68,18 @@ module.exports = {
60
68
  "n/prefer-global/text-encoder": "error",
61
69
  "n/prefer-global/url-search-params": "error",
62
70
  "n/prefer-global/url": "error",
71
+ // Only available in eslint-plugin-n@17
72
+ // No need to support as long as unicorn/prefer-node-protocol isn't deprecated
73
+ // "n/prefer-node-protocol": "error",
63
74
  "n/prefer-promises/dns": "error",
64
75
  "n/prefer-promises/fs": "error",
65
- // Doesn't really work
66
- "n/no-missing-import": "off",
67
- // no-unpublished-* only matters for published packages
68
- "n/no-unpublished-import": "off",
69
- "n/no-unpublished-require": "off",
76
+
70
77
  // Is CommonJS, not ESM
71
78
  "unicorn/prefer-module": "off",
72
79
  "unicorn/prevent-abbreviations": [
73
80
  "error",
74
81
  preventAbbreviationsConfig
75
82
  ],
76
- // Actually important in backend apps
77
- "unicorn/no-unsafe-regex": "error",
78
83
  // Use some logging instead
79
84
  "no-console": "error",
80
85
  "no-restricted-globals": [
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "eslint-config-beslogic",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "description": "ESLint rules, plugins and configs used at Beslogic",
5
5
  "main": "index.js",
6
+ "// dependencies": "Run for ourselves when we install dependencies w/o running npm i afterward",
6
7
  "scripts": {
7
8
  "eslint": "eslint ./ --ignore-path .gitignore",
8
9
  "lint": "node ./node_modules/dprint/bin check && npm run eslint",
9
10
  "lint:fix": "node ./node_modules/dprint/bin fmt && npm run eslint -- --fix",
10
11
  "upgrade": "npx npm-check-updates -u & npm i",
11
12
  "yalc": "yalc publish",
12
- "postinstall": "node ./lib/apply-patches.js",
13
- "dependencies": "node ./lib/apply-patches.js"
13
+ "postinstall": "node ./lib/patch-dependencies.js",
14
+ "dependencies": "node ./lib/patch-dependencies.js"
14
15
  },
15
16
  "keywords": [
16
17
  "eslint",
@@ -40,27 +41,26 @@
40
41
  "dependencies": {
41
42
  "@babel/eslint-parser": "^7.20.12",
42
43
  "@eslint-community/eslint-plugin-eslint-comments": "^4.1",
43
- "@typescript-eslint/eslint-plugin": "^6.2",
44
+ "@typescript-eslint/eslint-plugin": "^7.4",
44
45
  "confusing-browser-globals": "^1.0",
45
- "dprint": "^0.39.1",
46
- "eslint": "^8.28",
47
- "eslint-import-resolver-typescript": "^3.1",
46
+ "dprint": "^0.40.2",
47
+ "eslint": "^8.56",
48
+ "eslint-import-resolver-typescript": "^3.2.6",
48
49
  "eslint-plugin-angular-file-naming": "^1.0.6",
49
- "eslint-plugin-autofix": "^1.1.0",
50
+ "eslint-plugin-autofix": "^1.1 || ^2.0",
50
51
  "eslint-plugin-etc": "^2.0",
51
52
  "eslint-plugin-extra-rules": "^0.0.0-development",
52
53
  "eslint-plugin-import": "^2.27.3",
53
- "eslint-plugin-jest": "^27.2.3",
54
+ "eslint-plugin-jest": "^28.0",
54
55
  "eslint-plugin-jest-formatting": "^3.1",
55
- "eslint-plugin-no-autofix": "^1.2",
56
+ "eslint-plugin-no-autofix": "^1.2 || ^2.0",
56
57
  "eslint-plugin-no-relative-import-paths": "^1.5.3",
57
58
  "eslint-plugin-prefer-arrow": "^1.2",
58
- "eslint-plugin-regexp": "^1.12",
59
- "eslint-plugin-simple-import-sort": ">=9.0",
60
- "eslint-plugin-sonarjs": "^0.20",
61
- "eslint-plugin-unicorn": "^46.0",
62
- "eslint-plugin-unused-imports": "^3.0",
63
- "patch-package": "^7.0.0"
59
+ "eslint-plugin-regexp": "^2.0",
60
+ "eslint-plugin-simple-import-sort": ">=12.0",
61
+ "eslint-plugin-sonarjs": "^1.0",
62
+ "eslint-plugin-unicorn": ">=49.0",
63
+ "eslint-plugin-unused-imports": "^3.0"
64
64
  },
65
65
  "// eslint-plugin-total-functions": "Supported version is dictated by TypeScript and ESLint",
66
66
  "// (cont)": "Also made optional because of extra strictness",
@@ -70,16 +70,16 @@
70
70
  "@angular-eslint/template-parser": ">=16.2",
71
71
  "eslint-plugin-jsx-a11y": "^6.7.1",
72
72
  "eslint-plugin-mui": "^0.1.1",
73
- "eslint-plugin-n": ">=14.0",
74
- "eslint-plugin-react": "^7.32.2",
75
- "eslint-plugin-react-hooks": "^4.3",
73
+ "eslint-plugin-n": ">=17.0",
74
+ "eslint-plugin-react": "^7.33",
75
+ "eslint-plugin-react-hooks": "^4.3 || ^5.0",
76
76
  "eslint-plugin-react-prefer-function-component": "^3.2.0",
77
77
  "eslint-plugin-react-redux": "^4.0",
78
78
  "eslint-plugin-rxjs": "^5.0.3",
79
79
  "eslint-plugin-rxjs-angular": "github:BesLogic/eslint-plugin-rxjs-angular#dist",
80
80
  "eslint-plugin-storybook": "^0.6.10",
81
- "eslint-plugin-testing-library": "^5.10.2",
82
- "eslint-plugin-total-functions": ">=5.0"
81
+ "eslint-plugin-testing-library": "^6.0",
82
+ "eslint-plugin-total-functions": ">=6.0"
83
83
  },
84
84
  "devDependencies": {
85
85
  "@types/eslint": "^8.37.0",
package/react.js CHANGED
@@ -17,6 +17,8 @@ preventAbbreviationsConfig.allowList.Props = true
17
17
  preventAbbreviationsConfig.allowList.ref = true
18
18
  preventAbbreviationsConfig.allowList.Ref = true
19
19
 
20
+ const { jestFilePatterns } = require("./lib/utils")
21
+
20
22
  /** @type {import("eslint").Linter.Config} */
21
23
  module.exports = {
22
24
  "extends": [
@@ -88,6 +90,10 @@ module.exports = {
88
90
  ]
89
91
  }
90
92
  },
93
+ {
94
+ "files": jestFilePatterns,
95
+ "extends": ["plugin:testing-library/react"]
96
+ },
91
97
  typeDefinitionOverride
92
98
  ],
93
99
  "rules": {
@@ -114,7 +120,14 @@ module.exports = {
114
120
  */
115
121
  // Using only max-lines and not max-lines-per-function as most of the react code lives in functions.
116
122
  "max-lines-per-function": "off",
117
- // react overrides (https://github.com/yannickcr/eslint-plugin-react#list-of-supported-rules)
123
+
124
+ /*
125
+ * react overrides (https://github.com/yannickcr/eslint-plugin-react#list-of-supported-rules)
126
+ */
127
+ "react/display-name": [
128
+ "error",
129
+ { "checkContextObjects": true }
130
+ ],
118
131
  "react/forbid-component-props": [
119
132
  "error",
120
133
  // With most styling solutions, style can be fine
package/storybook.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 Beslogic Inc.
3
3
 
4
4
  const angularConfig = require("./angular")
5
- const { jestNoRestrictedSyntax } = require("./lib/utils")
5
+ const { jestNoRestrictedSyntax, jestFilePatterns } = require("./lib/utils")
6
6
 
7
7
  const noRestrictedSyntax = angularConfig.overrides?.[1].rules?.["no-restricted-syntax"]
8
8
  /** @type {import("eslint").Linter.Config} */
@@ -28,10 +28,7 @@ module.exports = {
28
28
  }
29
29
  },
30
30
  {
31
- "files": [
32
- "*spec.ts",
33
- ".test.tsx"
34
- ],
31
+ "files": jestFilePatterns,
35
32
  "rules": { "no-restricted-syntax": jestNoRestrictedSyntax(noRestrictedSyntax) }
36
33
  }
37
34
  ]
package/tsconfig.4.3.json CHANGED
@@ -4,11 +4,14 @@
4
4
  "newLine": "LF", // Now default in TypeScript 5.0
5
5
  "forceConsistentCasingInFileNames": true, // Now default in TypeScript 5.0
6
6
  "noFallthroughCasesInSwitch": true,
7
- "noImplicitOverride": true, // TypeScript 4.3+
7
+ "noImplicitOverride": true,
8
8
  "noImplicitReturns": true,
9
- "noUncheckedIndexedAccess": true, // This makes index accesses even stricter. You may not want it in your project.
9
+ // This makes index accesses even stricter. You may not want it in your project.
10
+ // You should probably disable it at least in tests.
11
+ "noUncheckedIndexedAccess": true,
10
12
  "module": "ESNext", // ESNext or CommonJS
11
- "target": "ES2017", // ES2017 or higher
13
+ // See: https://github.com/angular/angular-cli/blob/16.2.0/packages/angular_devkit/build_angular/src/tools/webpack/plugins/typescript.ts#L36-L39
14
+ "target": "ES2022", // ES2022 or higher
12
15
  "lib": [
13
16
  "ES2021", // ES2021 or higher
14
17
  "DOM",
@@ -18,8 +21,10 @@
18
21
  "emitDecoratorMetadata": true,
19
22
  "experimentalDecorators": true
20
23
  },
24
+ // https://next.angular.dev/reference/configs/angular-compiler-options
21
25
  "angularCompilerOptions": {
22
26
  // "strictMetadataEmit": true, // For bundling with an npm package
27
+ "enableI18nLegacyMessageIdFormat": false,
23
28
  "strictInjectionParameters": true,
24
29
  "strictInputAccessModifiers": true,
25
30
  "strictTemplates": true,
package/tsconfig.5.0.json CHANGED
@@ -1,6 +1,11 @@
1
1
  {
2
2
  "extends": "./tsconfig.4.3.json",
3
3
  "compilerOptions": {
4
- "verbatimModuleSyntax": true
4
+ "verbatimModuleSyntax": true,
5
+ // Since this is no longer needed for Angular with TypeScript 5, let's
6
+ // disable it so @typescript-eslint/consistent-type-imports doesn't turn
7
+ // itself off in files using decorators.
8
+ // https://typescript-eslint.io/rules/consistent-type-imports/#caveat-decorators--experimentaldecorators-true--emitdecoratormetadata-true
9
+ "experimentalDecorators": false
5
10
  }
6
11
  }
package/typescript.js CHANGED
@@ -2,8 +2,8 @@
2
2
  // Copyright 2024 Beslogic Inc.
3
3
 
4
4
  const javascriptConfig = require("./javascript")
5
- const { jestNoRestrictedSyntax } = require("./lib/utils")
6
- const { getModuleVersion } = require("./lib/utils")
5
+ const { jestNoRestrictedSyntax, jestFilePatterns } = require("./lib/utils")
6
+ const { resolveModuleLocation } = require("./lib/utils")
7
7
 
8
8
  const commaDangleDefault = "always-multiline"
9
9
  const noRestrictedSyntax = [
@@ -23,7 +23,7 @@ const paddingLineBetweenStatementsConfig = javascriptConfig
23
23
  ?.find(override => override.extends === "plugin:autofix/all")
24
24
  ?.rules?.["autofix/padding-line-between-statements"]
25
25
 
26
- const totalFunctionsVersion = getModuleVersion("eslint-plugin-total-functions", 0)
26
+ const hasTotalFunctions = !!resolveModuleLocation("eslint-plugin-total-functions")
27
27
 
28
28
  /** @type {import("eslint").Linter.Config} */
29
29
  module.exports = {
@@ -33,12 +33,12 @@ module.exports = {
33
33
  "*.ts",
34
34
  "*.tsx"
35
35
  ],
36
- "plugins": totalFunctionsVersion
36
+ "plugins": hasTotalFunctions
37
37
  ? ["total-functions"]
38
38
  : [],
39
39
  "extends": [
40
40
  "plugin:@typescript-eslint/all",
41
- ...totalFunctionsVersion
41
+ ...hasTotalFunctions
42
42
  ? ["plugin:total-functions/recommended"]
43
43
  : [],
44
44
  "plugin:etc/recommended",
@@ -123,7 +123,7 @@ module.exports = {
123
123
  * - `inputEvent.target as Partial<HTMLInputElement>` <-- Oops!
124
124
  * - `event.target as Partial<HTMLInputElement> | null` <-- Ok!
125
125
  */
126
- "total-functions/no-unsafe-type-assertion": totalFunctionsVersion
126
+ "total-functions/no-unsafe-type-assertion": hasTotalFunctions
127
127
  ? "warn"
128
128
  : "off",
129
129
  // False positives with external library
@@ -153,9 +153,6 @@ module.exports = {
153
153
  // TypeScript already ensures no options are missing
154
154
  "unicorn/no-object-as-default-parameter": "off",
155
155
 
156
- // Note: not useable with interfaces https://github.com/typescript-eslint/typescript-eslint/issues/1103
157
- // @typescript-eslint/class-methods-use-this only exists since 6.2
158
- "class-methods-use-this": "off",
159
156
  // Using simple-import-sort instead
160
157
  "sort-imports": "off",
161
158
  // Not usable with typescript anyway
@@ -180,6 +177,10 @@ module.exports = {
180
177
  "error",
181
178
  commaDangleDefault
182
179
  ],
180
+ // @typescript-eslint v7.1.0 will disable this automatically as it added its own version
181
+ "consistent-return": "off",
182
+ // Prefer "noImplicitReturns": true in tsconfig.json
183
+ "@typescript-eslint/consistent-return": "off",
183
184
  // Explicit types rules complicates things uselessly and are redundant
184
185
  "@typescript-eslint/explicit-function-return-type": "off",
185
186
  "@typescript-eslint/explicit-member-accessibility": [
@@ -375,9 +376,30 @@ module.exports = {
375
376
  ]
376
377
  }
377
378
  ],
379
+ // Favor safer @typescript-eslint/prefer-destructuring
380
+ "autofix/prefer-destructuring": "off",
381
+ "@typescript-eslint/prefer-destructuring": [
382
+ "error",
383
+ {
384
+ // Same as default, needed to configure the second object
385
+ "array": true,
386
+ "object": true
387
+ },
388
+ {
389
+ // Destructuring w/o assignement keyword (const/let) requires wrapping in parentheses,
390
+ // which can be confusing for example when destructuring into `this`.
391
+ // https://github.com/eslint/eslint/issues/18460
392
+ "enforceForRenamedProperties": false,
393
+ "enforceForDeclarationWithTypeAnnotation": true
394
+ }
395
+ ],
378
396
  "@typescript-eslint/prefer-enum-initializers": "off",
379
397
  // TODO: Would accept this if it had autofixes, otherwise this is too tedious to use. Check again later
380
398
  "@typescript-eslint/prefer-readonly-parameter-types": "off",
399
+ "@typescript-eslint/prefer-string-starts-ends-with": [
400
+ "error",
401
+ { "allowSingleElementEquality": true }
402
+ ],
381
403
  "@typescript-eslint/promise-function-async": [
382
404
  "error",
383
405
  {
@@ -402,6 +424,9 @@ module.exports = {
402
424
  {
403
425
  "allowBoolean": true,
404
426
  "allowNullish": true
427
+ // Purposefully keeping allowArray: false (v7.4)
428
+ // as the best way to format arrays is to use Intl.ListFormat
429
+ // and array's default .join() risks producing "[object Object]"
405
430
  }
406
431
  ],
407
432
  "@typescript-eslint/semi": [
@@ -421,7 +446,14 @@ module.exports = {
421
446
  "int32Hint": true
422
447
  }
423
448
  ],
449
+ // We accept nullish as falsy
424
450
  "@typescript-eslint/strict-boolean-expressions": "off",
451
+ "@typescript-eslint/switch-exhaustiveness-check": [
452
+ "error",
453
+ {
454
+ "requireDefaultForNonUnion": true
455
+ }
456
+ ],
425
457
  "@typescript-eslint/unbound-method": [
426
458
  "error",
427
459
  {
@@ -479,10 +511,7 @@ module.exports = {
479
511
  }
480
512
  },
481
513
  {
482
- "files": [
483
- "*spec.ts",
484
- ".test.tsx"
485
- ],
514
+ "files": jestFilePatterns,
486
515
  "extends": ["./jest"],
487
516
  "rules": {
488
517
  "no-restricted-syntax": jestNoRestrictedSyntax(noRestrictedSyntax)
@@ -1,76 +0,0 @@
1
- const { exec } = require("node:child_process")
2
- const { readdirSync, existsSync } = require("node:fs")
3
- const { join } = require("node:path")
4
-
5
- // ANSI color chart: https://en.m.wikipedia.org/wiki/ANSI_escape_code#Colors
6
-
7
- const appRootPath = join(__dirname, "..", "..", "..")
8
- if (!existsSync(join(appRootPath, "package.json"))) {
9
- /* eslint-disable-next-line n/no-process-exit, unicorn/no-process-exit --
10
- Probably ran in eslint-config-beslogic, just early exit. patch-package would fail anyway */
11
- process.exit(0)
12
- }
13
-
14
- const execCallback = (/** @type {string} */ packageName) =>
15
- (
16
- /** @type {import('node:child_process').ExecException | null} */
17
- error,
18
- /** @type {string} */
19
- stdout,
20
- /** @type {string} */
21
- stderr
22
- ) => {
23
- // NOTE: Can't use `.startsWith` because if "--force" is used, the message will start with
24
- // "npm WARN using --force Recommended protections disabled."
25
- if (stdout) console.info(stdout)
26
- if (stderr.includes("Error: Patch file found for package")) {
27
- console.info(`\u001B[32m${packageName} not found in node_modules, no need to patch.\u001B[0m`)
28
-
29
- return
30
- }
31
- if (stderr.includes("\nWarning: ")) {
32
- const reworded = stderr.replace(
33
- "run\n\n patch-package @nx/angular",
34
- "contact\n\n samuel.therrien@beslogic.com"
35
- )
36
- console.warn(`\u001B[33m${reworded}\u001B[0m`)
37
-
38
- return
39
- }
40
- if (stderr.includes("\n**ERROR** Failed to apply patch for package") && stdout.includes("✔")) {
41
- console.info(
42
- `\u001B[32m${packageName} has patches for multiple versions, at least one was applied successfully!\u001B[0m`
43
- )
44
-
45
- return
46
- }
47
- if (error) {
48
- console.error(
49
- "\u001B[31m" +
50
- `The following error happenned while patching ${packageName} with eslint-config-beslogic. ` +
51
- "Please contact samuel.therrien@beslogic.com with the package version and the full error to get it fixed." +
52
- "\u001B[0m"
53
- )
54
- throw error
55
- }
56
- if (stderr) console.error(`\u001B[31m${stderr}\u001B[0m`)
57
- console.info(`\u001B[32m${packageName} patched successfully! Now go write great code!\u001B[0m`)
58
- }
59
-
60
- const folders = readdirSync("lib/patches")
61
- for (const folder of folders) {
62
- const packageName = folder.replaceAll("+", "/")
63
- console.info(`\u001B[93mPatching ${packageName}\u001B[0m`)
64
- // We cannot apply individual patches with patch-package, ang using git is more cumbersome / less safe.
65
- // So instead we apply individual patch folders.
66
- // This is necessary if we have multiple patches for optional dependencies.
67
- // https://www.npmjs.com/package/patch-package#user-content-notes
68
- exec(
69
- "npx patch-package" +
70
- ` --patch-dir=node_modules/eslint-config-beslogic/lib/patches/${folder}` +
71
- " --ignore-whitespace" +
72
- " --error-on-fail",
73
- { "cwd": appRootPath },
74
- execCallback(packageName)
75
- )
76
- }
@@ -1,13 +0,0 @@
1
- diff --git a/node_modules/@angular/material/dialog/index.d.ts b/node_modules/@angular/material/dialog/index.d.ts
2
- index 6dc3eab..c9fa899 100644
3
- --- a/node_modules/@angular/material/dialog/index.d.ts
4
- +++ b/node_modules/@angular/material/dialog/index.d.ts
5
- @@ -397,7 +397,7 @@ export declare class MatDialogModule {
6
- /**
7
- * Reference to a dialog opened via the MatDialog service.
8
- */
9
- -export declare class MatDialogRef<T, R = any> {
10
- +export declare class MatDialogRef<T, R = void> {
11
- private _ref;
12
- _containerInstance: _MatDialogContainerBase;
13
- /** The instance of component opened into the dialog. */
@@ -1,14 +0,0 @@
1
- # https://github.com/angular/components/issues/12898
2
- diff --git a/node_modules/@angular/material/dialog/index.d.ts b/node_modules/@angular/material/dialog/index.d.ts
3
- index 914c287..80caedb 100644
4
- --- a/node_modules/@angular/material/dialog/index.d.ts
5
- +++ b/node_modules/@angular/material/dialog/index.d.ts
6
- @@ -425,7 +425,7 @@ export declare class MatDialogModule {
7
- /**
8
- * Reference to a dialog opened via the MatDialog service.
9
- */
10
- -export declare class MatDialogRef<T, R = any> {
11
- +export declare class MatDialogRef<T, R = void> {
12
- private _ref;
13
- _containerInstance: _MatDialogContainerBase;
14
- /** The instance of component opened into the dialog. */
@@ -1,13 +0,0 @@
1
- diff --git a/node_modules/@angular/material/dialog/index.d.ts b/node_modules/@angular/material/dialog/index.d.ts
2
- index 7d4f965..cd6bdcf 100644
3
- --- a/node_modules/@angular/material/dialog/index.d.ts
4
- +++ b/node_modules/@angular/material/dialog/index.d.ts
5
- @@ -428,7 +428,7 @@ export declare class MatDialogModule {
6
- /**
7
- * Reference to a dialog opened via the MatDialog service.
8
- */
9
- -export declare class MatDialogRef<T, R = any> {
10
- +export declare class MatDialogRef<T, R = void> {
11
- private _ref;
12
- _containerInstance: _MatDialogContainerBase;
13
- /** The instance of component opened into the dialog. */
@@ -1,13 +0,0 @@
1
- diff --git a/node_modules/@angular/material/dialog/index.d.ts b/node_modules/@angular/material/dialog/index.d.ts
2
- index e1a0275..efecaab 100644
3
- --- a/node_modules/@angular/material/dialog/index.d.ts
4
- +++ b/node_modules/@angular/material/dialog/index.d.ts
5
- @@ -420,7 +420,7 @@ export declare class MatDialogModule {
6
- /**
7
- * Reference to a dialog opened via the MatDialog service.
8
- */
9
- -export declare class MatDialogRef<T, R = any> {
10
- +export declare class MatDialogRef<T, R = void> {
11
- private _ref;
12
- _containerInstance: MatDialogContainer;
13
- /** The instance of component opened into the dialog. */
@@ -1,56 +0,0 @@
1
- diff --git a/node_modules/@nx/angular/src/generators/add-linting/lib/create-eslint-configuration.js b/node_modules/@nx/angular/src/generators/add-linting/lib/create-eslint-configuration.js
2
- index 7acd7d3..dde125a 100644
3
- --- a/node_modules/@nx/angular/src/generators/add-linting/lib/create-eslint-configuration.js
4
- +++ b/node_modules/@nx/angular/src/generators/add-linting/lib/create-eslint-configuration.js
5
- @@ -7,8 +7,6 @@ const extendAngularEslintJson = (json, options) => {
6
- const overrides = [
7
- Object.assign(Object.assign({}, json.overrides[0]), { files: ['*.ts'], extends: [
8
- ...(json.overrides[0].extends || []),
9
- - 'plugin:@nx/angular',
10
- - 'plugin:@angular-eslint/template/process-inline-templates',
11
- ], rules: {
12
- '@angular-eslint/directive-selector': [
13
- 'error',
14
- @@ -27,15 +25,6 @@ const extendAngularEslintJson = (json, options) => {
15
- },
16
- ],
17
- } }),
18
- - {
19
- - files: ['*.html'],
20
- - extends: ['plugin:@nx/angular-template'],
21
- - /**
22
- - * Having an empty rules object present makes it more obvious to the user where they would
23
- - * extend things from if they needed to
24
- - */
25
- - rules: {},
26
- - },
27
- ];
28
- return Object.assign(Object.assign({}, json), { overrides });
29
- };
30
- @@ -53,10 +42,6 @@ function createEsLintConfiguration(tree, options) {
31
- overrides: [
32
- {
33
- files: ['*.ts'],
34
- - extends: [
35
- - 'plugin:@nx/angular',
36
- - 'plugin:@angular-eslint/template/process-inline-templates',
37
- - ],
38
- /**
39
- * NOTE: We no longer set parserOptions.project by default when creating new projects.
40
- *
41
- @@ -94,15 +79,6 @@ function createEsLintConfiguration(tree, options) {
42
- ],
43
- },
44
- },
45
- - {
46
- - files: ['*.html'],
47
- - extends: ['plugin:@nx/angular-template'],
48
- - /**
49
- - * Having an empty rules object present makes it more obvious to the user where they would
50
- - * extend things from if they needed to
51
- - */
52
- - rules: {},
53
- - },
54
- ],
55
- };
56
- (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, '.eslintrc.json'), configJson);