eslint-config-beslogic 2.3.2 → 2.4.6

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.
@@ -1,6 +1,6 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Copyright 2024 Beslogic Inc.
3
- // Keep in sync with https://dev.azure.com/Beslogic/Beslogic%20Architecture%20Templates/_wiki/wikis/Beslogic-Architecture-Templates.wiki/757/VSCode-settings-and-extensions-(.vscode-.code-workspace)
3
+ // Keep in sync with https://dev.azure.com/Beslogic/Beslogic%20Architecture%20Reference/_wiki/wikis/Beslogic-Architecture-Reference.wiki/757/VSCode-settings-and-extensions-(.vscode-.code-workspace)
4
4
  //
5
5
  // Please keep in alphabetical order
6
6
  {
@@ -1,6 +1,6 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Copyright 2024 Beslogic Inc.
3
- // Keep in sync with https://dev.azure.com/Beslogic/Beslogic%20Architecture%20Templates/_wiki/wikis/Beslogic-Architecture-Templates.wiki/757/VSCode-settings-and-extensions-(.vscode-.code-workspace)
3
+ // Keep in sync with https://dev.azure.com/Beslogic/Beslogic%20Architecture%20Reference/_wiki/wikis/Beslogic-Architecture-Reference.wiki/757/VSCode-settings-and-extensions-(.vscode-.code-workspace)
4
4
 
5
5
  {
6
6
  "files.associations": {
package/CHANGELOG.md CHANGED
@@ -1,8 +1,30 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.4.6
4
+
5
+ - Replaced `@typescript-eslint/*` with `typescript-eslint`
6
+ - Loosened rules requirering `strictNullChecks` if `eslint-plugin-total-functions` isn't also installed
7
+
8
+ ## 2.4.5
9
+
10
+ - Include documentation about usage with `.pre-commit-config.yaml`/`pre-commit.ci`
11
+ - Allow omitting `esling-plugin-no-autofix`, `eslint-plugin-jest`, `eslint-plugin-jest-formatting` and `eslint-plugin-etc` for `.pre-commit-config.yaml`/`pre-commit.ci`
12
+ - `pre-commit.ci` run will always assume the following are not installed to save on space:
13
+ - `eslint-plugin-total-functions`
14
+ - `esling-plugin-no-autofix`
15
+ - `eslint-plugin-testing-library`
16
+ - `eslint-plugin-jest-formatting`
17
+ - `eslint-plugin-jest`
18
+ - `eslint-plugin-etc`
19
+ - Moved `eslint-plugin-angular-file-naming` to `optionalDependencies`
20
+ - Moved `eslint-plugin-testing-library` to `dependencies`
21
+ - Bumped `eslint-plugin-unused-imports` to `^3.2.0` to fix error with `@typescript-eslint@7.8`
22
+ - Don't check for camelcase properties in eslint config files
23
+ - Turn on `prefer-arrow/prefer-arrow-functions` autofixing for `singleReturnOnly`
24
+
3
25
  ## 2.3.2
4
26
 
5
- - Added "data-service", "interceptor" and "guard" as valid suffix for `angular-file-naming/service-filename-suffix`.
27
+ - Added "data-service", "interceptor" and "guard" as valid suffix for `angular-file-naming/service-filename-suffix`
6
28
 
7
29
  ## 2.3.1
8
30
 
@@ -32,7 +54,7 @@
32
54
  - Check context objects with `react/display-name`
33
55
  - Added React 18 deprecations
34
56
  - Remove accidental recommendation to install `eslint-plugn-react-redux` from non-redux presets in `README.md`
35
- - Now enforce at least 1 newline after imports even with dprint preset.
57
+ - Now enforce at least 1 newline after imports even with dprint preset
36
58
  - Turn on `allowImplicit`, `checkForEach`, and `allowVoid` for rule `array-callback-return`
37
59
  - Bumped `eslint-plugin-total-functions` to `>=6.0`
38
60
  - which bumps `typescript` dependency to `4.7.3`
package/README.md CHANGED
@@ -51,7 +51,7 @@ If deploying / bundling with an Angular npm package, also set `angularCompilerOp
51
51
 
52
52
  ### `.vscode/settings.json` and `.vscode/extensions.json`
53
53
 
54
- <!-- Keep in sync with https://dev.azure.com/Beslogic/Beslogic%20Architecture%20Templates/_wiki/wikis/Beslogic-Architecture-Templates.wiki/757/VSCode-settings-and-extensions-(.vscode-.code-workspace) -->
54
+ <!-- Keep in sync with https://dev.azure.com/Beslogic/Beslogic%20Architecture%20Reference/_wiki/wikis/Beslogic-Architecture-Reference.wiki/757/VSCode-settings-and-extensions-(.vscode-.code-workspace) -->
55
55
 
56
56
  Read and copy from [VSCode Settings and Extensions](https://socket.dev/npm/package/eslint-config-beslogic/files/latest/.vscode)
57
57
 
@@ -73,6 +73,24 @@ If you'd like to pin your config version, you can use a commit hash, like `https
73
73
 
74
74
  If also using [`beslogic/json-like` preset](#beslogicjson-like) extend from `https://raw.githubusercontent.com/BesLogic/shared-configs/main/dprint-json-like.json` instead.
75
75
 
76
+ ### Usage with `pre-commit.ci` (`.pre-commit-config.yaml`)
77
+
78
+ Use the following hook: <https://github.com/pre-commit/mirrors-eslint>
79
+
80
+ Set `args: [--fix, --quiet]`.
81
+
82
+ In the `additional_dependencies` field, you'll need to include _all_ the plugins we use (copy this project's `dependencies` in `package.json`), as well as the optional plugins you need for yor presets.
83
+
84
+ As you'll easily bust the 250MiB limit on the free tier, omit the following dependencies as they're special-cased to always be ignored on `pre-commit.ci` anyway:
85
+
86
+ - `dprint`
87
+ - `eslint-plugin-total-functions`
88
+ - `esling-plugin-no-autofix`
89
+ - `eslint-plugin-testing-library`
90
+ - `eslint-plugin-jest-formatting`
91
+ - `eslint-plugin-jest`
92
+ - `eslint-plugin-etc`
93
+
76
94
  ## Patched packages
77
95
 
78
96
  The following packages cause problems or have other type-safety issues that are automatically patched out by `eslint-config-beslogic` on install. To see the complete logs, add `foreground-scripts=true` to a root `.npmrc` file, or run `npm install` with `--foreground-scripts`.
package/angular.js CHANGED
@@ -1,10 +1,16 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Copyright 2024 Beslogic Inc.
3
3
 
4
- const { getModuleVersion, jestNoRestrictedSyntax, jestFilePatterns } = require("./lib/utils")
4
+ const { getModuleVersion, jestNoRestrictedSyntax, jestFilePatterns, resolveModuleLocation } =
5
+ require("./lib/utils")
5
6
 
6
7
  const angularEslintVersion = getModuleVersion("@angular-eslint/eslint-plugin", 16.2)
7
8
  const typescriptVersion = getModuleVersion("typescript", 4.7)
9
+ const hasTestingLibrary = !!resolveModuleLocation("eslint-plugin-testing-library")
10
+ // eslint-plugin-no-autofix is broken when run through pre-commit
11
+ // https://github.com/aladdin-add/eslint-plugin/issues/98
12
+ // Even if it gets fixed, `no-autofix` rules necessarily don't provide fixes anyway
13
+ const hasNoAutofix = !!resolveModuleLocation("eslint-plugin-no-autofix")
8
14
 
9
15
  const javascriptConfig = require("./javascript")
10
16
  const typescriptConfig = require("./typescript")
@@ -71,7 +77,9 @@ module.exports = {
71
77
  "overrides": [
72
78
  {
73
79
  "files": ["*.html"],
74
- "plugins": ["no-autofix"],
80
+ "plugins": hasNoAutofix
81
+ ? ["no-autofix"]
82
+ : [],
75
83
  "extends": ["plugin:@angular-eslint/template/all"],
76
84
  "rules": {
77
85
  "@angular-eslint/template/click-events-have-key-events": "off",
@@ -113,7 +121,9 @@ module.exports = {
113
121
  "@angular-eslint/template/i18n": "off",
114
122
  "no-autofix/@angular-eslint/template/i18n": [
115
123
  // Too many TODO and needs per-project extensions to justify this as "error"
116
- "warn",
124
+ hasNoAutofix
125
+ ? "warn"
126
+ : "off",
117
127
  {
118
128
  // NOTE: doesn't work for text elements.
119
129
  // See: https://github.com/angular-eslint/angular-eslint/issues/999
@@ -363,7 +373,9 @@ module.exports = {
363
373
  },
364
374
  {
365
375
  "files": jestFilePatterns,
366
- "extends": ["plugin:testing-library/angular"],
376
+ "extends": hasTestingLibrary
377
+ ? ["plugin:testing-library/angular"]
378
+ : [],
367
379
  "rules": { "no-restricted-syntax": jestNoRestrictedSyntax(noRestrictedSyntax) }
368
380
  },
369
381
  {
package/javascript.js CHANGED
@@ -2,36 +2,20 @@
2
2
  // Copyright 2024 Beslogic Inc.
3
3
 
4
4
  const restrictedGlobals = require("confusing-browser-globals")
5
- const { jestNoRestrictedSyntax, jestFilePatterns } = require("./lib/utils")
5
+ const { jestNoRestrictedSyntax, jestFilePatterns, resolveModuleLocation, idLenghtConfig } = require(
6
+ "./lib/utils"
7
+ )
8
+
9
+ // The only autofix we use is `no-implicit-any-catch` and this is a big module for pre-commit
10
+ // Outside of pre-commit, `eslint-plugin-etc` should NOT be considered optional !
11
+ const hasEtc = !!resolveModuleLocation("eslint-plugin-etc")
12
+ // eslint-plugin-no-autofix is broken when run through pre-commit
13
+ // https://github.com/aladdin-add/eslint-plugin/issues/98
14
+ // Even if it gets fixed, `no-autofix` rules necessarily don't provide fixes anyway
15
+ const hasNoAutofix = !!resolveModuleLocation("eslint-plugin-no-autofix")
6
16
 
7
17
  const commaDangleDefault = "always-multiline"
8
- const idLenghtConfig = {
9
- "min": 3,
10
- "max": 32,
11
- "properties": "never",
12
- "exceptionPatterns": [
13
- // Unused result
14
- "__?",
15
- // Comparison and Iterations
16
- "[a-bi-k]"
17
- ],
18
- "exceptions": [
19
- "id",
20
- "fn",
21
- "to",
22
- "TO",
23
- // Matches
24
- "or",
25
- "OR",
26
- "on",
27
- // Date formats
28
- "dd",
29
- "mm",
30
- "yy",
31
- // HTTP status codes
32
- "OK"
33
- ]
34
- }
18
+
35
19
  const noRestrictedSyntax = [
36
20
  "error",
37
21
  "WithStatement",
@@ -60,12 +44,16 @@ const noRestrictedSyntax = [
60
44
  module.exports = {
61
45
  "plugins": [
62
46
  "extra-rules",
63
- "no-autofix",
47
+ ...hasNoAutofix
48
+ ? ["no-autofix"]
49
+ : [],
64
50
  "prefer-arrow",
65
51
  "simple-import-sort",
66
52
  "no-relative-import-paths",
67
53
  "unused-imports",
68
- "etc"
54
+ ...hasEtc
55
+ ? ["etc"]
56
+ : []
69
57
  ],
70
58
  "extends": [
71
59
  "eslint:recommended",
@@ -345,7 +333,9 @@ module.exports = {
345
333
  ],
346
334
  // Using this to completely disallow all console calls except info, warn, error
347
335
  "no-autofix/no-console": [
348
- "error",
336
+ hasNoAutofix
337
+ ? "error"
338
+ : "off",
349
339
  {
350
340
  "allow": [
351
341
  "info",
@@ -394,6 +384,11 @@ module.exports = {
394
384
  // "extends": ["./json-like"]
395
385
  "globals": { "module": true },
396
386
  "rules": {
387
+ // We don't have control on keys names
388
+ "camelcase": [
389
+ "error",
390
+ { "properties": "never" }
391
+ ],
397
392
  // Keep consistent with preset rules
398
393
  "unicorn/prefer-string-raw": "off"
399
394
  }
@@ -452,7 +447,9 @@ module.exports = {
452
447
 
453
448
  // Extracted restricted import into its own rule so it's easier for projects to override/ignore
454
449
  "no-autofix/no-relative-import-paths/no-relative-import-paths": [
455
- "error",
450
+ hasNoAutofix
451
+ ? "error"
452
+ : "off",
456
453
  {
457
454
  "allowSameFolder": true
458
455
  }
@@ -464,7 +461,9 @@ module.exports = {
464
461
  // Loosing imports when commenting to test is extremely annoying and slow,
465
462
  // so we only use this rule when ran from the command-line
466
463
  // no-autofix/unused-imports/no-unused-imports is redundant with no-unused-vars and and eslint.codeActionsOnSave.rules
467
- "unused-imports/no-unused-imports": "warn",
464
+ "unused-imports/no-unused-imports": hasNoAutofix
465
+ ? "warn"
466
+ : "off",
468
467
 
469
468
  // unicorn/all overrides (https://github.com/sindresorhus/eslint-plugin-unicorn#rules)
470
469
  "unicorn/catch-error-name": [
@@ -569,7 +568,9 @@ module.exports = {
569
568
  /*
570
569
  * Cartant's etc rules
571
570
  */
572
- "etc/no-commented-out-code": "error",
571
+ "etc/no-commented-out-code": hasEtc
572
+ ? "error"
573
+ : "off",
573
574
 
574
575
  /*
575
576
  * Simple import rules
@@ -599,12 +600,25 @@ module.exports = {
599
600
  /*
600
601
  * Prefer Arrow rule
601
602
  */
603
+ // Autofixing is only applied when only checking for `singleReturnOnly: true`
604
+ // but we still want to check for other cases
605
+ "no-autofix/prefer-arrow/prefer-arrow-functions": [
606
+ hasNoAutofix
607
+ ? "error"
608
+ : "off",
609
+ {
610
+ "classPropertiesAllowed": true,
611
+ "disallowPrototype": true,
612
+ "singleReturnOnly": false,
613
+ "allowStandaloneDeclarations": false
614
+ }
615
+ ],
602
616
  "prefer-arrow/prefer-arrow-functions": [
603
617
  "error",
604
618
  {
605
619
  "classPropertiesAllowed": true,
606
620
  "disallowPrototype": true,
607
- "singleReturnOnly": false,
621
+ "singleReturnOnly": true,
608
622
  "allowStandaloneDeclarations": false
609
623
  }
610
624
  ],
@@ -668,7 +682,9 @@ module.exports = {
668
682
  // HACK: Workaround for coordinates objects
669
683
  // TODO: Should be using rule composition instead
670
684
  "no-autofix/id-length": [
671
- "error",
685
+ hasNoAutofix
686
+ ? "error"
687
+ : "off",
672
688
  idLenghtConfig
673
689
  ],
674
690
  "id-length": [
package/jest.js CHANGED
@@ -1,22 +1,38 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Copyright 2024 Beslogic Inc.
3
- const { getModuleVersion } = require("./lib/utils")
3
+ const { getModuleVersion, resolveModuleLocation } = require("./lib/utils")
4
4
 
5
5
  const jestGlobalsVersion = getModuleVersion("@jest/globals", 29)
6
+ // These are big modules for pre-commit.
7
+ // Outside of pre-commit, these should NOT be considered optional !
8
+ const hasTestingLibrary = !!resolveModuleLocation("eslint-plugin-testing-library")
9
+ const hasJestFormatting = !!resolveModuleLocation("eslint-plugin-jest-formatting")
10
+ const hasJest = !!resolveModuleLocation("eslint-plugin-jest")
6
11
 
7
12
  /** @type {import("eslint").Linter.Config} */
8
13
  module.exports = {
9
14
  "extends": [
10
- "plugin:jest/all",
11
- "plugin:jest-formatting/strict",
15
+ ...hasJest
16
+ ? ["plugin:jest/all"]
17
+ : [],
18
+ ...hasJestFormatting
19
+ ? ["plugin:jest-formatting/strict"]
20
+ : [],
12
21
  // Note: The DOM preset includes some rules not in Marko or Vue (eg.: no-await-sync-events).
13
22
  // Those must be disabled in their preset if we ever support them.
14
- "plugin:testing-library/dom"
23
+ ...hasTestingLibrary
24
+ ? ["plugin:testing-library/dom"]
25
+ : []
15
26
  ],
16
27
  "env": {
17
28
  "browser": false,
18
29
  "jest": true,
19
- "jest/globals": true
30
+ ...hasJest
31
+ ? {
32
+ // Setting to `false` is not enough: Environment key "jest/globals" is unknown
33
+ "jest/globals": true
34
+ }
35
+ : {}
20
36
  },
21
37
  "overrides": [
22
38
  {
@@ -62,40 +78,52 @@ module.exports = {
62
78
  "error",
63
79
  { "threshold": 8 }
64
80
  ],
65
- // Doesn't print well with testing-library's `findBy` and `waitFor`
66
- "jest/prefer-expect-resolves": "off",
67
- // May lead to accidentally missed expects
68
- "jest/prefer-expect-assertions": [
69
- "error",
70
- {
71
- "onlyFunctionsWithExpectInCallback": true,
72
- "onlyFunctionsWithExpectInLoop": true
73
- }
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
- : {}),
81
- // Top-level describe is often used for component name, which is capitalized
82
- "jest/prefer-lowercase-title": [
83
- "error",
84
- { "ignoreTopLevelDescribe": true }
85
- ],
86
- // Allow clearing mocks in beforeEach
87
- "jest/no-hooks": [
88
- "error",
89
- {
90
- "allow": ["beforeEach"]
81
+
82
+ /*
83
+ * jest/all overrides (https://github.com/jest-community/eslint-plugin-jest#rules)
84
+ */
85
+ ...hasJest
86
+ ? {
87
+ // Doesn't print well with testing-library's `findBy` and `waitFor`
88
+ "jest/prefer-expect-resolves": "off",
89
+ // May lead to accidentally missed expects
90
+ "jest/prefer-expect-assertions": [
91
+ "error",
92
+ {
93
+ "onlyFunctionsWithExpectInCallback": true,
94
+ "onlyFunctionsWithExpectInLoop": true
95
+ }
96
+ ],
97
+ // https://github.com/jestjs/jest/issues/15084
98
+ // Since this will require a major jest version bump anyway,
99
+ // I feel confortable not waiting for our own major version bump to add this
100
+ ...jestGlobalsVersion < 30
101
+ ? { "jest/prefer-importing-jest-globals": "off" }
102
+ : {},
103
+ // Top-level describe is often used for component name, which is capitalized
104
+ "jest/prefer-lowercase-title": [
105
+ "error",
106
+ { "ignoreTopLevelDescribe": true }
107
+ ],
108
+ // Allow clearing mocks in beforeEach
109
+ "jest/no-hooks": [
110
+ "error",
111
+ {
112
+ "allow": ["beforeEach"]
113
+ }
114
+ ]
91
115
  }
92
- ],
116
+ : {},
93
117
 
94
118
  /*
95
119
  * testing-library overrides (https://github.com/testing-library/eslint-plugin-testing-library#supported-rules)
96
120
  */
97
- "testing-library/no-debugging-utils": "error",
98
- "testing-library/prefer-user-event": "warn",
99
- "testing-library/prefer-explicit-assert": "error"
121
+ ...hasTestingLibrary
122
+ ? {
123
+ "testing-library/no-debugging-utils": "error",
124
+ "testing-library/prefer-user-event": "warn",
125
+ "testing-library/prefer-explicit-assert": "error"
126
+ }
127
+ : {}
100
128
  }
101
129
  }
package/lib/utils.js CHANGED
@@ -1,3 +1,7 @@
1
+ // const isPreCommitCI = __dirname.startsWith("/pc/clone/")
2
+ // console.log(__dirname)
3
+ // console.log(__filename)
4
+
1
5
  const getModuleVersion = (
2
6
  /** @type {string} */ nodeModule,
3
7
  /** @type {number} */ fallbackVersion
@@ -19,7 +23,16 @@ const getModuleVersion = (
19
23
 
20
24
  const resolveModuleLocation = (/** @type {string} */ nodeModule) => {
21
25
  try {
22
- return require.resolve(nodeModule)
26
+ // console.log(__dirname)
27
+ // console.log(__filename)
28
+ const resolved = require.resolve(nodeModule)
29
+ // DEBUG: console.log(resolved)
30
+ if (resolved.startsWith("/pc/clone/")) {
31
+ // Assume it's omitted from the pre-commit.ci run
32
+ return false
33
+ }
34
+
35
+ return resolved
23
36
  } catch {
24
37
  return false
25
38
  }
@@ -42,9 +55,39 @@ const jestFilePatterns = [
42
55
  "**/?(*.)+(spec|test).[jt]s?(x)"
43
56
  ]
44
57
 
58
+ const idLenghtConfig = {
59
+ "min": 3,
60
+ "max": 32,
61
+ "properties": "never",
62
+ "exceptionPatterns": [
63
+ // Unused result
64
+ "__?",
65
+ // Comparison and Iterations
66
+ "[a-bi-k]"
67
+ ],
68
+ "exceptions": [
69
+ "id",
70
+ "fn",
71
+ "to",
72
+ "TO",
73
+ // Matches
74
+ "or",
75
+ "OR",
76
+ "on",
77
+ // Date formats
78
+ "dd",
79
+ "mm",
80
+ "yy",
81
+ // HTTP status codes
82
+ "OK"
83
+ ]
84
+ }
85
+
45
86
  module.exports = {
46
87
  getModuleVersion,
88
+ idLenghtConfig,
89
+ // isPreCommitCI,
90
+ jestFilePatterns,
47
91
  jestNoRestrictedSyntax,
48
- resolveModuleLocation,
49
- jestFilePatterns
92
+ resolveModuleLocation
50
93
  }
package/mui.js CHANGED
@@ -1,10 +1,9 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Copyright 2024 Beslogic Inc.
3
3
 
4
- const javascriptConfig = require("./javascript")
5
4
  const typeScriptConfig = require("./typescript")
5
+ const { idLenghtConfig } = require("./lib/utils")
6
6
 
7
- const idLenghtConfig = javascriptConfig.rules?.["no-autofix/id-length"]?.[1]
8
7
  const noMagicNumbersConfig = typeScriptConfig.overrides?.[0].rules
9
8
  ?.["@typescript-eslint/no-magic-numbers"]?.[1]
10
9
 
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "eslint-config-beslogic",
3
- "version": "2.3.2",
3
+ "version": "2.4.6",
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",
7
7
  "scripts": {
8
- "eslint": "eslint ./ --ignore-path .gitignore",
8
+ "eslint": "set TIMING=1 && eslint ./ --ignore-path .gitignore",
9
9
  "lint": "node ./node_modules/dprint/bin check && npm run eslint",
10
10
  "lint:fix": "node ./node_modules/dprint/bin fmt && npm run eslint -- --fix",
11
11
  "upgrade": "npx npm-check-updates -u & npm i",
@@ -42,12 +42,10 @@
42
42
  "dependencies": {
43
43
  "@babel/eslint-parser": "^7.20.12",
44
44
  "@eslint-community/eslint-plugin-eslint-comments": "^4.1",
45
- "@typescript-eslint/eslint-plugin": "^7.4",
46
45
  "confusing-browser-globals": "^1.0",
47
46
  "dprint": "^0.40.2",
48
47
  "eslint": "^8.56",
49
48
  "eslint-import-resolver-typescript": "^3.2.6",
50
- "eslint-plugin-angular-file-naming": "^1.0.6",
51
49
  "eslint-plugin-autofix": "^1.1 || ^2.0",
52
50
  "eslint-plugin-etc": "^2.0",
53
51
  "eslint-plugin-extra-rules": "^0.0.0-development",
@@ -60,8 +58,10 @@
60
58
  "eslint-plugin-regexp": "^2.0",
61
59
  "eslint-plugin-simple-import-sort": ">=12.0",
62
60
  "eslint-plugin-sonarjs": "^1.0",
61
+ "eslint-plugin-testing-library": "^6.0",
63
62
  "eslint-plugin-unicorn": ">=49.0",
64
- "eslint-plugin-unused-imports": "^3.0"
63
+ "eslint-plugin-unused-imports": "^3.2",
64
+ "typescript-eslint": "^7.4"
65
65
  },
66
66
  "// eslint-plugin-total-functions": "Supported version is dictated by TypeScript and ESLint",
67
67
  "// (cont)": "Also made optional because of extra strictness",
@@ -69,6 +69,7 @@
69
69
  "@angular-eslint/eslint-plugin": ">=16.2",
70
70
  "@angular-eslint/eslint-plugin-template": ">=16.2",
71
71
  "@angular-eslint/template-parser": ">=16.2",
72
+ "eslint-plugin-angular-file-naming": "^1.0.6",
72
73
  "eslint-plugin-jsx-a11y": "^6.7.1",
73
74
  "eslint-plugin-mui": "^0.1.1",
74
75
  "eslint-plugin-n": ">=17.0",
@@ -79,7 +80,6 @@
79
80
  "eslint-plugin-rxjs": "^5.0.3",
80
81
  "eslint-plugin-rxjs-angular": "github:BesLogic/eslint-plugin-rxjs-angular#dist",
81
82
  "eslint-plugin-storybook": "^0.6.10",
82
- "eslint-plugin-testing-library": "^6.0",
83
83
  "eslint-plugin-total-functions": ">=6.0"
84
84
  },
85
85
  "// plugins": "Test against highest supported version to catch new breaking changes",
package/react.js CHANGED
@@ -3,6 +3,9 @@
3
3
 
4
4
  const javascriptConfig = require("./javascript")
5
5
  const typescriptConfig = require("./typescript")
6
+ const { jestFilePatterns, resolveModuleLocation } = require("./lib/utils")
7
+
8
+ const hasTestingLibrary = !!resolveModuleLocation("eslint-plugin-testing-library")
6
9
 
7
10
  const typeDefinitionOverride = typescriptConfig.overrides?.find(override =>
8
11
  override.files === "*.d.ts"
@@ -17,8 +20,6 @@ preventAbbreviationsConfig.allowList.Props = true
17
20
  preventAbbreviationsConfig.allowList.ref = true
18
21
  preventAbbreviationsConfig.allowList.Ref = true
19
22
 
20
- const { jestFilePatterns } = require("./lib/utils")
21
-
22
23
  /** @type {import("eslint").Linter.Config} */
23
24
  module.exports = {
24
25
  "extends": [
@@ -92,7 +93,9 @@ module.exports = {
92
93
  },
93
94
  {
94
95
  "files": jestFilePatterns,
95
- "extends": ["plugin:testing-library/react"]
96
+ "extends": hasTestingLibrary
97
+ ? ["plugin:testing-library/react"]
98
+ : []
96
99
  },
97
100
  typeDefinitionOverride
98
101
  ],
package/typescript.js CHANGED
@@ -2,8 +2,12 @@
2
2
  // Copyright 2024 Beslogic Inc.
3
3
 
4
4
  const javascriptConfig = require("./javascript")
5
- const { jestNoRestrictedSyntax, jestFilePatterns } = require("./lib/utils")
6
- const { resolveModuleLocation } = require("./lib/utils")
5
+ const { jestNoRestrictedSyntax, jestFilePatterns, resolveModuleLocation } = require("./lib/utils")
6
+
7
+ // The only autofix we use is `no-implicit-any-catch` and this is a big module for pre-commit
8
+ // Outside of pre-commit, `eslint-plugin-etc` should NOT be considered optional !
9
+ const hasEtc = !!resolveModuleLocation("eslint-plugin-etc")
10
+ const hasTotalFunctions = !!resolveModuleLocation("eslint-plugin-total-functions")
7
11
 
8
12
  const commaDangleDefault = "always-multiline"
9
13
  const noRestrictedSyntax = [
@@ -23,8 +27,6 @@ const paddingLineBetweenStatementsConfig = javascriptConfig
23
27
  ?.find(override => override.extends === "plugin:autofix/all")
24
28
  ?.rules?.["autofix/padding-line-between-statements"]
25
29
 
26
- const hasTotalFunctions = !!resolveModuleLocation("eslint-plugin-total-functions")
27
-
28
30
  /** @type {import("eslint").Linter.Config} */
29
31
  module.exports = {
30
32
  "overrides": [
@@ -41,7 +43,9 @@ module.exports = {
41
43
  ...hasTotalFunctions
42
44
  ? ["plugin:total-functions/recommended"]
43
45
  : [],
44
- "plugin:etc/recommended",
46
+ ...hasEtc
47
+ ? ["plugin:etc/recommended"]
48
+ : [],
45
49
  "plugin:import/typescript"
46
50
  ],
47
51
  "env": {
@@ -106,7 +110,7 @@ module.exports = {
106
110
  "total-functions/no-enums": "off",
107
111
  // It takes an advanced TypeScript user to fully make sense of this rule
108
112
  /**
109
- * (copied from https://dev.azure.com/Beslogic/Beslogic%20Architecture%20Templates/_wiki/wikis/Beslogic-Architecture-Templates.wiki/656/Frontend-linting-and-formatting?anchor=total-functions/no-unsafe-type-assertion)
113
+ * (copied from https://dev.azure.com/Beslogic/Beslogic%20Architecture%20Reference/_wiki/wikis/Beslogic-Architecture-Reference.wiki/656/Frontend-linting-and-formatting?anchor=total-functions/no-unsafe-type-assertion)
110
114
  * It can sometimes be hard to make sense of this rule, but let's be strict!
111
115
  * Tips:
112
116
  * - Prefer coercion over assertion: `String(value ?? '')` over `value as string | null`
@@ -135,15 +139,21 @@ module.exports = {
135
139
  /*
136
140
  * Cartant's etc rules
137
141
  */
138
- "etc/no-const-enum": "error",
139
- // Same as total-functions/no-enums
140
- "etc/no-enum": "warn",
141
- "etc/throw-error": "error",
142
- "etc/underscore-internal": "error",
143
- // These two are extremely slow. More than should be expected
144
- // https://github.com/cartant/eslint-plugin-etc/issues/10#issuecomment-1618450905
145
- "etc/no-deprecated": "off",
146
- "etc/no-internal": "off",
142
+ ...hasEtc
143
+ ? {
144
+ "etc/no-const-enum": "error",
145
+ // Same as total-functions/no-enums
146
+ "etc/no-enum": "warn",
147
+ "etc/throw-error": "error",
148
+ "etc/underscore-internal": "error",
149
+ // These two are extremely slow. More than should be expected
150
+ // https://github.com/cartant/eslint-plugin-etc/issues/10#issuecomment-1618450905
151
+ "etc/no-deprecated": "off",
152
+ "etc/no-internal": "off",
153
+ // See https://github.com/cartant/eslint-plugin-etc/issues/45#issuecomment-1137305254
154
+ "etc/prefer-interface": "off"
155
+ }
156
+ : {},
147
157
 
148
158
  /*
149
159
  * Overrides of base Javascript rules
@@ -292,10 +302,6 @@ module.exports = {
292
302
  }
293
303
  ],
294
304
  "@typescript-eslint/no-type-alias": "off",
295
- "@typescript-eslint/no-unnecessary-condition": [
296
- "error",
297
- { "allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing": true }
298
- ],
299
305
  // Note: These 2 drown TS2304 and actually make the errors harder to understand.
300
306
  // See: https://github.com/typescript-eslint/typescript-eslint/issues/2665
301
307
  // There's nothing we can do until a pedantic any check in TypeScript is added
@@ -303,8 +309,9 @@ module.exports = {
303
309
  // Which is likely never gonna happen: https://github.com/microsoft/TypeScript/issues/24737
304
310
  // We still want to be aware that we are using an any type and should be cautious
305
311
  //
306
- // TODO: Turn back no-unsafe-assignment to error after creating and publishing type extensions that replaces any
307
- // with unknown in standard libs. See Empassion for example *.d.ts files
312
+ // TODO: Turn back no-unsafe-assignment to error after creating and publishing type
313
+ // extensions that replaces any with unknown in standard libs.
314
+ // See Empassion for example *.d.ts files
308
315
  // Refs: https://github.com/Microsoft/TypeScript/issues/26188
309
316
  // and https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html
310
317
  "@typescript-eslint/no-unsafe-assignment": "warn",
@@ -446,8 +453,6 @@ module.exports = {
446
453
  "int32Hint": true
447
454
  }
448
455
  ],
449
- // We accept nullish as falsy
450
- "@typescript-eslint/strict-boolean-expressions": "off",
451
456
  "@typescript-eslint/switch-exhaustiveness-check": [
452
457
  "error",
453
458
  {
@@ -463,7 +468,24 @@ module.exports = {
463
468
  "@typescript-eslint/unified-signatures": [
464
469
  "error",
465
470
  { "ignoreDifferentlyNamedParameters": true }
466
- ]
471
+ ],
472
+
473
+ /*
474
+ * @typescript-eslint rules that require strictNullChecks
475
+ * Similar to eslint-plugin-total-functions, these requires stricter tsconfig or fails.
476
+ */
477
+ // Setting allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing makes this rule useless on
478
+ // null/undefined checks. So only set it if we don't already enforce stricter TS configs.
479
+ "@typescript-eslint/no-unnecessary-condition": [
480
+ "error",
481
+ { "allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing": !hasTotalFunctions }
482
+ ],
483
+ // IDEM, but fully useless w/o strictNullChecks
484
+ "@typescript-eslint/prefer-nullish-coalescing": hasTotalFunctions
485
+ ? "error"
486
+ : "off",
487
+ // We accept nullish as falsy
488
+ "@typescript-eslint/strict-boolean-expressions": "off"
467
489
  }
468
490
  },
469
491
  {
@@ -1,16 +0,0 @@
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_
@@ -1 +0,0 @@
1
- static-tests