eslint-config-beslogic 2.2.1 → 2.3.1

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_
@@ -0,0 +1 @@
1
+ static-tests
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.3.1
4
+
5
+ <!-- dprint-ignore -->
6
+ - Fixed the following error when parsing `typescript`` config:\
7
+ `Configuration for rule "@typescript-eslint/prefer-string-starts-ends-with" is invalid: Value true should be string.`
8
+ - Added `no-restricted-syntax` rules to ensure that Angular optional dependencies are marked as optional in TypeScript and vice-versa
9
+ - Fixed Storybook custom `.ts` configuration not being applied
10
+ - Disabled `autofix/indent-legacy`
11
+
12
+ <!-- TODO: Validate that static-tests are not published -->
13
+
14
+ ## 2.3.0
15
+
16
+ - Allow single element equality for `@typescript-eslint/prefer-string-starts-ends-with`
17
+ - Disabled `unicorn/prefer-string-raw` for json-like and eslintrc.json
18
+ - Set tsconfig's `angularCompilerOptions.enableI18nLegacyMessageIdFormat` to `false`
19
+ - Set tsconfig's `compilerOptions.target` to `"ES2022"`
20
+ 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)
21
+ - Presets for Jest now consider the framework (Angular, React, or DOM)
22
+ - Updated Jest file matching to Jest's default patterns
23
+ - No longer leaving empty strings for eslint extends generated by NX
24
+ - Fixed an invalid syntax for `@nx/js` patching
25
+
3
26
  ## 2.2.1
4
27
 
5
28
  - Bumped `eslint-plugin-react` to `^7.33`
@@ -29,7 +52,6 @@
29
52
  - `jest/prefer-importing-jest-globals` is enabled by default, which removes needing a dependency
30
53
  on often outdated `@types/jest` and removes the need for `types: ["jest"]` in `tsconfig.json`
31
54
  - Bumped `dprint` to `^0.40.2` to prepare for process plugins
32
-
33
55
  - Bumped `@typescript-eslint/eslint-plugin` to `^7.4`
34
56
  - Re-enabled `@typescript-eslint/no-import-type-side-effects`
35
57
  and set `@typescript-eslint/consistent-type-imports` back to default options
@@ -38,13 +60,11 @@
38
60
  - Prefered `@typescript-eslint/prefer-destructuring` over `autofix/prefer-destructuring`
39
61
  - Disabled `@typescript-eslint/key-spacing`, `autofix/func-call-spacing`,
40
62
  and `lines-around-comment` in `dprint` preset
41
-
42
63
  - Patched-out prettier from nx generators
43
64
  - Used Search&Replace based package patching:
44
65
  - Removes `patch-package` from dependencies
45
66
  - Removes bundled git patches
46
67
  - Speedup check for `eslint-plugin-total-functions` install
47
-
48
68
  - Bumped `eslint-plugin-n` to `>=16.2`. Notably, this:
49
69
  - improves support for ts-node
50
70
  - Updates documentation links
package/README.md CHANGED
@@ -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
 
@@ -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,7 +1,7 @@
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
6
  const angularEslintVersion = getModuleVersion("@angular-eslint/eslint-plugin", 16.2)
7
7
  const typescriptVersion = getModuleVersion("typescript", 4.7)
@@ -31,6 +31,17 @@ const noRestrictedSyntax = [
31
31
  "message":
32
32
  "Forbidden non-null property assertion. https://typescript-eslint.io/rules/no-non-null-assertion . " +
33
33
  "This is only allowed on required component @Input({ required:true }). https://angular.io/api/core/Input#required"
34
+ },
35
+ {
36
+ "selector":
37
+ "MethodDefinition[key.name=\"constructor\"]:has(TSParameterProperty:has(Decorator[expression.callee.name=\"Optional\"]):not(:has(Identifier[optional=true])))",
38
+ "message":
39
+ "Constructor parameter with @Optional decorator should be marked as optional using `?`."
40
+ },
41
+ {
42
+ "selector":
43
+ "ClassDeclaration:has(Decorator :matches([name=\"Component\"], [name=\"Injectable\"], [name=\"Directive\"], [name=\"Pipe\"])) MethodDefinition[key.name=\"constructor\"]:has(TSParameterProperty:has(Identifier[optional=true]):not(:has(Decorator[expression.callee.name=\"Optional\"])))",
44
+ "message": "Optional constructor parameter should have @Optional decorator."
34
45
  }
35
46
  ]
36
47
 
@@ -341,7 +352,8 @@ module.exports = {
341
352
  }
342
353
  },
343
354
  {
344
- "files": ["*spec.ts"],
355
+ "files": jestFilePatterns,
356
+ "extends": ["plugin:testing-library/angular"],
345
357
  "rules": { "no-restricted-syntax": jestNoRestrictedSyntax(noRestrictedSyntax) }
346
358
  },
347
359
  {
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 = {
@@ -90,7 +90,6 @@ 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,
94
93
  "overrides": [
95
94
  {
96
95
  "files": [
@@ -301,6 +300,9 @@ module.exports = {
301
300
  }
302
301
  ],
303
302
 
303
+ // indent-legacy is deprecated in favor of indent
304
+ "autofix/indent-legacy": "off",
305
+
304
306
  // Using simple-import-sort instead
305
307
  "autofix/sort-imports": "off",
306
308
 
@@ -379,10 +381,7 @@ module.exports = {
379
381
  }
380
382
  },
381
383
  {
382
- "files": [
383
- "*spec.js",
384
- ".test.jsx"
385
- ],
384
+ "files": jestFilePatterns,
386
385
  "extends": ["./jest"],
387
386
  "rules": { "no-restricted-syntax": jestNoRestrictedSyntax(noRestrictedSyntax) }
388
387
  },
@@ -393,7 +392,11 @@ module.exports = {
393
392
  ],
394
393
  // To reconsider, since this would conflict with a simple dprint default
395
394
  // "extends": ["./json-like"]
396
- "globals": { "module": true }
395
+ "globals": { "module": true },
396
+ "rules": {
397
+ // Keep consistent with preset rules
398
+ "unicorn/prefer-string-raw": "off"
399
+ }
397
400
  }
398
401
  ],
399
402
  "rules": {
@@ -576,18 +579,18 @@ module.exports = {
576
579
  {
577
580
  "groups": [
578
581
  // Side effect imports.
579
- [String.raw`^\u0000`],
582
+ ["^\\u0000"],
580
583
  // Node.js builtins prefixed with `node:`.
581
584
  ["^node:"],
582
585
  // Packages.
583
586
  // Things that start with a letter (or digit or underscore), or `@` followed by a letter.
584
- [String.raw`^@?\w`],
587
+ ["^@?\\w"],
585
588
  // Absolute imports and other imports such as Vue-style `@/foo`.
586
589
  // Anything not matched in another group.
587
590
  ["^"],
588
591
  // Relative imports.
589
592
  // Anything that starts with a dot or src/
590
- [String.raw`^(\.|src/)`]
593
+ ["^(\\.|src/)"]
591
594
  ]
592
595
  }
593
596
  ],
package/jest.js CHANGED
@@ -9,7 +9,9 @@ module.exports = {
9
9
  "extends": [
10
10
  "plugin:jest/all",
11
11
  "plugin:jest-formatting/strict",
12
- "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"
13
15
  ],
14
16
  "env": {
15
17
  "browser": false,
@@ -87,6 +89,13 @@ module.exports = {
87
89
  {
88
90
  "allow": ["beforeEach"]
89
91
  }
90
- ]
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"
91
100
  }
92
101
  }
@@ -67,16 +67,11 @@ const patches = [
67
67
  join(base, "src", "generators", "add-linting", "lib", "create-eslint-configuration.js"),
68
68
  [
69
69
  // Remove code that adds preset extensions
70
+ // plugin:@nx/angular-template
71
+ // plugin:@nx/angular
72
+ // plugin:@angular-eslint/template/process-inline-templates
70
73
  {
71
- "from": "plugin:@nx/angular",
72
- "to": ""
73
- },
74
- {
75
- "from": "plugin:@angular-eslint/template/process-inline-templates",
76
- "to": ""
77
- },
78
- {
79
- "from": "plugin:@nx/angular-template",
74
+ "from": /'plugin:.+?',?/gu,
80
75
  "to": ""
81
76
  },
82
77
  // Remove empty extends
@@ -146,8 +141,9 @@ const patches = [
146
141
  "to": "false"
147
142
  },
148
143
  {
149
- "from": "devkit_1.ensurePackage)('prettier'",
150
- "to": "//"
144
+ // eslint-disable-next-line regexp/no-super-linear-move -- Is it really?
145
+ "from": /.+?devkit_1\.ensurePackage\)\('prettier'.+?[\n;]/gu,
146
+ "to": ""
151
147
  }
152
148
  ]
153
149
  )
package/lib/utils.js CHANGED
@@ -36,8 +36,15 @@ const jestNoRestrictedSyntax = (
36
36
  !entry.selector.startsWith("ArrowFunctionExpression")
37
37
  )
38
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
+
39
45
  module.exports = {
40
46
  getModuleVersion,
41
47
  jestNoRestrictedSyntax,
42
- resolveModuleLocation
48
+ resolveModuleLocation,
49
+ jestFilePatterns
43
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-config-beslogic",
3
- "version": "2.2.1",
3
+ "version": "2.3.1",
4
4
  "description": "ESLint rules, plugins and configs used at Beslogic",
5
5
  "main": "index.js",
6
6
  "// dependencies": "Run for ourselves when we install dependencies w/o running npm i afterward",
@@ -10,6 +10,7 @@
10
10
  "lint:fix": "node ./node_modules/dprint/bin fmt && npm run eslint -- --fix",
11
11
  "upgrade": "npx npm-check-updates -u & npm i",
12
12
  "yalc": "yalc publish",
13
+ "prepack": "type .gitignore* > .npmignore",
13
14
  "postinstall": "node ./lib/patch-dependencies.js",
14
15
  "dependencies": "node ./lib/patch-dependencies.js"
15
16
  },
@@ -81,10 +82,17 @@
81
82
  "eslint-plugin-testing-library": "^6.0",
82
83
  "eslint-plugin-total-functions": ">=6.0"
83
84
  },
85
+ "// plugins": "Test against highest supported version to catch new breaking changes",
84
86
  "devDependencies": {
87
+ "@angular-eslint/eslint-plugin": ">=16.2",
88
+ "@angular-eslint/eslint-plugin-template": ">=16.2",
89
+ "@angular-eslint/template-parser": ">=16.2",
90
+ "@angular/core": ">=16.2",
85
91
  "@types/eslint": "^8.37.0",
86
92
  "@types/node": "^17.0",
87
93
  "eslint-plugin-eslint-plugin": "^4.1",
94
+ "eslint-plugin-storybook": "^0.6.10",
95
+ "eslint-plugin-total-functions": ">=6.0",
88
96
  "yalc": "^1.0.0-pre.53"
89
97
  }
90
98
  }
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": {
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} */
@@ -13,7 +13,7 @@ module.exports = {
13
13
  ],
14
14
  "overrides": [
15
15
  {
16
- "files": [".ts"],
16
+ "files": ["*.ts"],
17
17
  "rules": {
18
18
  "no-restricted-syntax": [
19
19
  ...noRestrictedSyntax,
@@ -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
@@ -10,7 +10,8 @@
10
10
  // You should probably disable it at least in tests.
11
11
  "noUncheckedIndexedAccess": true,
12
12
  "module": "ESNext", // ESNext or CommonJS
13
- "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
14
15
  "lib": [
15
16
  "ES2021", // ES2021 or higher
16
17
  "DOM",
@@ -20,8 +21,10 @@
20
21
  "emitDecoratorMetadata": true,
21
22
  "experimentalDecorators": true
22
23
  },
24
+ // https://next.angular.dev/reference/configs/angular-compiler-options
23
25
  "angularCompilerOptions": {
24
26
  // "strictMetadataEmit": true, // For bundling with an npm package
27
+ "enableI18nLegacyMessageIdFormat": false,
25
28
  "strictInjectionParameters": true,
26
29
  "strictInputAccessModifiers": true,
27
30
  "strictTemplates": true,
package/typescript.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 Beslogic Inc.
3
3
 
4
4
  const javascriptConfig = require("./javascript")
5
- const { jestNoRestrictedSyntax } = require("./lib/utils")
5
+ const { jestNoRestrictedSyntax, jestFilePatterns } = require("./lib/utils")
6
6
  const { resolveModuleLocation } = require("./lib/utils")
7
7
 
8
8
  const commaDangleDefault = "always-multiline"
@@ -396,6 +396,10 @@ module.exports = {
396
396
  "@typescript-eslint/prefer-enum-initializers": "off",
397
397
  // TODO: Would accept this if it had autofixes, otherwise this is too tedious to use. Check again later
398
398
  "@typescript-eslint/prefer-readonly-parameter-types": "off",
399
+ "@typescript-eslint/prefer-string-starts-ends-with": [
400
+ "error",
401
+ { "allowSingleElementEquality": "always" }
402
+ ],
399
403
  "@typescript-eslint/promise-function-async": [
400
404
  "error",
401
405
  {
@@ -507,10 +511,7 @@ module.exports = {
507
511
  }
508
512
  },
509
513
  {
510
- "files": [
511
- "*spec.ts",
512
- ".test.tsx"
513
- ],
514
+ "files": jestFilePatterns,
514
515
  "extends": ["./jest"],
515
516
  "rules": {
516
517
  "no-restricted-syntax": jestNoRestrictedSyntax(noRestrictedSyntax)