eslint-plugin-wyrm 0.0.7 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +39 -19
- package/dist/_virtual/rolldown_runtime.mjs +20 -0
- package/dist/configs/{index.js → index.mjs} +3 -3
- package/dist/{index.d.ts → index.d.mts} +2 -2
- package/dist/index.mjs +12 -0
- package/dist/{plugin.js → plugin.mjs} +1 -1
- package/dist/rules/distribute-boolean-casts.d.mts +7 -0
- package/dist/rules/{distribute-boolean-casts.js → distribute-boolean-casts.mjs} +16 -8
- package/dist/rules/index.d.mts +43 -0
- package/dist/rules/index.mjs +80 -0
- package/dist/rules/no-constant-template-expression.d.mts +10 -0
- package/dist/rules/no-constant-template-expression.mjs +108 -0
- package/dist/rules/no-convoluted-logical-expressions.d.mts +7 -0
- package/dist/rules/no-convoluted-logical-expressions.mjs +126 -0
- package/dist/rules/no-duplicated-return.d.mts +7 -0
- package/dist/rules/no-duplicated-return.mjs +83 -0
- package/dist/rules/{no-else-throw.d.ts → no-else-break.d.mts} +3 -3
- package/dist/rules/{no-else-break.js → no-else-break.mjs} +5 -3
- package/dist/rules/no-else-continue.d.mts +7 -0
- package/dist/rules/{no-else-continue.js → no-else-continue.mjs} +5 -3
- package/dist/rules/no-else-throw.d.mts +7 -0
- package/dist/rules/{no-else-throw.js → no-else-throw.mjs} +5 -3
- package/dist/rules/no-empty-attribute.d.mts +9 -0
- package/dist/rules/no-empty-attribute.mjs +77 -0
- package/dist/rules/no-empty-comment.d.mts +9 -0
- package/dist/rules/{no-empty-comment.js → no-empty-comment.mjs} +7 -8
- package/dist/rules/no-empty-jsx-expression.d.mts +7 -0
- package/dist/rules/{no-empty-jsx-expression.js → no-empty-jsx-expression.mjs} +1 -2
- package/dist/rules/no-empty-literal-iteration.d.mts +7 -0
- package/dist/rules/no-empty-literal-iteration.mjs +98 -0
- package/dist/rules/no-extra-false-fallback.d.mts +8 -0
- package/dist/rules/no-extra-false-fallback.mjs +172 -0
- package/dist/rules/no-extra-nested-boolean-cast.d.mts +8 -0
- package/dist/rules/{no-extra-nested-boolean-cast.js → no-extra-nested-boolean-cast.mjs} +29 -4
- package/dist/rules/no-first-last.d.mts +7 -0
- package/dist/rules/no-first-last.mjs +171 -0
- package/dist/rules/no-inline-jsdoc-tag.d.mts +9 -0
- package/dist/rules/no-inline-jsdoc-tag.mjs +155 -0
- package/dist/rules/no-invalid-date-literal.d.mts +7 -0
- package/dist/rules/{no-invalid-date-literal.js → no-invalid-date-literal.mjs} +1 -1
- package/dist/rules/no-jsx-statement.d.mts +7 -0
- package/dist/rules/{no-jsx-statement.js → no-jsx-statement.mjs} +3 -2
- package/dist/rules/no-optional-type-guard-param.d.mts +7 -0
- package/dist/rules/no-optional-type-guard-param.mjs +43 -0
- package/dist/rules/no-redundant-function-declaration.d.mts +7 -0
- package/dist/rules/no-redundant-function-declaration.mjs +60 -0
- package/dist/rules/no-return-to-void.d.mts +7 -0
- package/dist/rules/no-return-to-void.mjs +96 -0
- package/dist/rules/no-sloppy-length-check.d.mts +8 -0
- package/dist/rules/no-sloppy-length-check.mjs +249 -0
- package/dist/rules/no-suspicious-jsx-semicolon.d.mts +8 -0
- package/dist/rules/no-suspicious-jsx-semicolon.mjs +57 -0
- package/dist/rules/no-ternary-return.d.mts +10 -0
- package/dist/rules/{no-ternary-return.js → no-ternary-return.mjs} +12 -3
- package/dist/rules/no-unassigned-todo.d.mts +7 -0
- package/dist/rules/no-unassigned-todo.mjs +38 -0
- package/dist/rules/no-unused-param-read.d.mts +7 -0
- package/dist/rules/no-unused-param-read.mjs +34 -0
- package/dist/rules/no-useless-computed-key.d.mts +7 -0
- package/dist/rules/no-useless-computed-key.mjs +39 -0
- package/dist/rules/no-useless-iife.d.mts +7 -0
- package/dist/rules/no-useless-iife.mjs +173 -0
- package/dist/rules/no-useless-logical-fallback.d.mts +8 -0
- package/dist/rules/no-useless-logical-fallback.mjs +256 -0
- package/dist/rules/no-useless-return-undefined.d.mts +7 -0
- package/dist/rules/no-useless-return-undefined.mjs +106 -0
- package/dist/rules/no-useless-use-strict.d.mts +7 -0
- package/dist/rules/no-useless-use-strict.mjs +61 -0
- package/dist/rules/no-useless-usememo.d.mts +7 -0
- package/dist/rules/no-useless-usememo.mjs +132 -0
- package/dist/rules/no-whitespace-property.d.mts +7 -0
- package/dist/rules/no-whitespace-property.mjs +43 -0
- package/dist/rules/prefer-catch-method.d.mts +7 -0
- package/dist/rules/{prefer-catch-method.js → prefer-catch-method.mjs} +22 -9
- package/dist/rules/prefer-early-return.d.mts +7 -0
- package/dist/rules/prefer-early-return.mjs +123 -0
- package/dist/rules/prefer-repeat.d.mts +7 -0
- package/dist/rules/{prefer-repeat.js → prefer-repeat.mjs} +8 -5
- package/dist/rules/{unsafe-asserted-chain.d.ts → unsafe-asserted-chain.d.mts} +1 -1
- package/dist/rules/unsafe-asserted-chain.mjs +72 -0
- package/dist/utils/compareTokens.mjs +20 -0
- package/package.json +37 -22
- package/dist/_virtual/rolldown_runtime.js +0 -15
- package/dist/index.js +0 -12
- package/dist/rules/distribute-boolean-casts.d.ts +0 -7
- package/dist/rules/index.d.ts +0 -23
- package/dist/rules/index.js +0 -40
- package/dist/rules/no-constant-template-expression.d.ts +0 -10
- package/dist/rules/no-constant-template-expression.js +0 -82
- package/dist/rules/no-else-break.d.ts +0 -7
- package/dist/rules/no-else-continue.d.ts +0 -7
- package/dist/rules/no-empty-comment.d.ts +0 -9
- package/dist/rules/no-empty-jsx-expression.d.ts +0 -7
- package/dist/rules/no-extra-nested-boolean-cast.d.ts +0 -8
- package/dist/rules/no-invalid-date-literal.d.ts +0 -7
- package/dist/rules/no-jsx-statement.d.ts +0 -7
- package/dist/rules/no-suspicious-jsx-semicolon.d.ts +0 -8
- package/dist/rules/no-suspicious-jsx-semicolon.js +0 -39
- package/dist/rules/no-ternary-return.d.ts +0 -10
- package/dist/rules/no-useless-iife.d.ts +0 -7
- package/dist/rules/no-useless-iife.js +0 -93
- package/dist/rules/prefer-catch-method.d.ts +0 -7
- package/dist/rules/prefer-repeat.d.ts +0 -7
- package/dist/rules/unsafe-asserted-chain.js +0 -49
- /package/dist/configs/{index.d.ts → index.d.mts} +0 -0
- /package/dist/utils/{createRule.d.ts → createRule.d.mts} +0 -0
- /package/dist/utils/{createRule.js → createRule.mjs} +0 -0
- /package/dist/utils/{option.js → option.mjs} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.9](https://github.com/mchevestrier/eslint-plugin-wyrm/compare/eslint-plugin-wyrm-v0.0.8...eslint-plugin-wyrm-v0.0.9) (2025-11-30)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* add no-convoluted-logical-expressions ([28586c1](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/28586c121b85d2f48dcfa0ef1c4707373f4f041b))
|
|
9
|
+
* add no-empty-attribute ([b22ff03](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/b22ff0368226d692e22977dce02061ac9afe9b6f))
|
|
10
|
+
* add no-empty-literal-iteration ([630c8ef](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/630c8ef4ac9cc50f2e381b38b6a64ef8001e3033))
|
|
11
|
+
* add no-first-last ([516a527](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/516a52739ae5d256973acf396e2d4d9f457f8e7f))
|
|
12
|
+
* add no-inline-jsdoc-tag ([f82a538](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/f82a538b29282743cdc5bde61fe3ff0683372088))
|
|
13
|
+
* add no-redundant-function-declaration ([8f4e20e](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/8f4e20eebd76d7cc97763a821b5968139e08b443))
|
|
14
|
+
* add no-sloppy-length-check ([676f230](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/676f2304ca497669375f16219d926bf3dcf6b4d3))
|
|
15
|
+
* add no-unassigned-todo ([42ba01a](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/42ba01a01fc4bef061d50a4b7454964fbd68ca48))
|
|
16
|
+
* add no-unused-param-read ([1f6c997](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/1f6c9972aa949da09a077a4f916749e25eef38bc))
|
|
17
|
+
* add no-useless-computed-key ([37e7b97](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/37e7b97d6151d8a24672f8365f76c6100b34212e))
|
|
18
|
+
* add no-useless-use-strict ([fbffbc2](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/fbffbc2545121f3d2bfb696105fa98b28d7c69c9))
|
|
19
|
+
* add no-useless-usememo ([349221d](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/349221d26e86a6c8f1bb3fc4b4f8e9ace98a7fa8))
|
|
20
|
+
* improve some rules ([73f3b99](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/73f3b99284b0b66ccd7ff0a3ac0f529f4bd1ad93))
|
|
21
|
+
|
|
22
|
+
## [0.0.8](https://github.com/mchevestrier/eslint-plugin-wyrm/compare/eslint-plugin-wyrm-v0.0.7...eslint-plugin-wyrm-v0.0.8) (2025-11-16)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* add no-duplicated-return & prefer-early-return ([41372c9](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/41372c9d1d147e9597259b22bc4fe29d8f6873e1))
|
|
28
|
+
* add no-extra-false-fallback ([f2e2bcd](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/f2e2bcd9f5aae66535f159c2d6fb1ca51ba3176f))
|
|
29
|
+
* add no-optional-type-guard-param ([6b3d9a1](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/6b3d9a1be37da3e4104de462bcf27dc1147741db))
|
|
30
|
+
* add no-return-to-void & no-useless-return-undefined ([5b5da17](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/5b5da17a778bf23c4b29bd44ddbea7d3919c9d0e))
|
|
31
|
+
* add no-useless-logical-fallback ([129eaea](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/129eaea5ec6db9b07cf3478fd42f7d766ada2e82))
|
|
32
|
+
* add no-whitespace-property ([6aab31a](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/6aab31a2e61e6b68bad909420ea845aee281e184))
|
|
33
|
+
* improve no-duplicated-return ([60ed1d8](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/60ed1d8e09154d3e1fd45bd409bfbdef644857ac))
|
|
34
|
+
* improve no-useless-logical-fallback ([c770119](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/c7701199ee0486494a8a5b688540725113aca17c))
|
|
35
|
+
* improve rules ([68cb444](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/68cb4442a9436b39fe739ea5cdfe85ba2b6ed897))
|
|
36
|
+
|
|
3
37
|
## [0.0.7](https://github.com/mchevestrier/eslint-plugin-wyrm/compare/eslint-plugin-wyrm-v0.0.6...eslint-plugin-wyrm-v0.0.7) (2025-11-05)
|
|
4
38
|
|
|
5
39
|
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/eslint-plugin-wyrm)
|
|
4
4
|
[](https://github.com/mchevestrier/eslint-plugin-wyrm/releases/latest)
|
|
5
|
-
[](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/
|
|
5
|
+
[](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/LICENSE.md)
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -49,23 +49,43 @@ export default defineConfig([
|
|
|
49
49
|
💡 Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).\
|
|
50
50
|
💭 Requires [type information](https://typescript-eslint.io/linting/typed-linting).
|
|
51
51
|
|
|
52
|
-
| Name
|
|
53
|
-
|
|
|
54
|
-
| [distribute-boolean-casts](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/distribute-boolean-casts.md)
|
|
55
|
-
| [no-constant-template-expression](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-constant-template-expression.md)
|
|
56
|
-
| [no-
|
|
57
|
-
| [no-
|
|
58
|
-
| [no-else-
|
|
59
|
-
| [no-
|
|
60
|
-
| [no-
|
|
61
|
-
| [no-
|
|
62
|
-
| [no-
|
|
63
|
-
| [no-jsx-
|
|
64
|
-
| [no-
|
|
65
|
-
| [no-
|
|
66
|
-
| [no-
|
|
67
|
-
| [
|
|
68
|
-
| [
|
|
69
|
-
| [
|
|
52
|
+
| Name | Description | 💼 | 🔧 | 💡 | 💭 |
|
|
53
|
+
| :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :------------------------------------------------------------------------ | :---------- | :-- | :-- | :-- |
|
|
54
|
+
| [distribute-boolean-casts](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/distribute-boolean-casts.md) | Enforce that boolean casts are distributed over logical expressions | 🟪 ☑️ | 🔧 | | |
|
|
55
|
+
| [no-constant-template-expression](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-constant-template-expression.md) | Disallow constant string expressions in template literals | ☑️ | | 💡 | 💭 |
|
|
56
|
+
| [no-convoluted-logical-expressions](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-convoluted-logical-expressions.md) | Forbid simplifiable logical expressions | 🟩 ✅ 🟪 ☑️ | 🔧 | | |
|
|
57
|
+
| [no-duplicated-return](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-duplicated-return.md) | Forbid duplicated branches with early returns | 🟩 ✅ 🟪 ☑️ | | | |
|
|
58
|
+
| [no-else-break](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-else-break.md) | Forbid unnecessary `else` block after a `break` statement | 🟩 ✅ 🟪 ☑️ | 🔧 | | |
|
|
59
|
+
| [no-else-continue](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-else-continue.md) | Forbid unnecessary `else` block after a `continue` statement | 🟩 ✅ 🟪 ☑️ | 🔧 | | |
|
|
60
|
+
| [no-else-throw](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-else-throw.md) | Forbid unnecessary `else` block after a `throw` statement | 🟩 ✅ 🟪 ☑️ | 🔧 | | |
|
|
61
|
+
| [no-empty-attribute](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-empty-attribute.md) | Forbid some empty JSX attributes | 🟪 ☑️ | | | |
|
|
62
|
+
| [no-empty-comment](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-empty-comment.md) | Forbid empty comments | 🟪 ☑️ | | | |
|
|
63
|
+
| [no-empty-jsx-expression](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-empty-jsx-expression.md) | Forbid empty JSX expression containers | 🟩 ✅ 🟪 ☑️ | | | |
|
|
64
|
+
| [no-empty-literal-iteration](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-empty-literal-iteration.md) | Forbid iterating over empty literals | 🟪 ☑️ | | | |
|
|
65
|
+
| [no-extra-false-fallback](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-extra-false-fallback.md) | Forbid extra `?? false` in conditions and predicates | 🟪 ☑️ | | 💡 | |
|
|
66
|
+
| [no-extra-nested-boolean-cast](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-extra-nested-boolean-cast.md) | Forbid extra boolean casts in conditions and predicates | 🟪 ☑️ | | | |
|
|
67
|
+
| [no-first-last](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-first-last.md) | Forbid confusing naming for "first" or "last" | 🟩 ✅ 🟪 ☑️ | 🔧 | | |
|
|
68
|
+
| [no-inline-jsdoc-tag](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-inline-jsdoc-tag.md) | Forbid JSDoc tags in code comments | 🟪 ☑️ | | | |
|
|
69
|
+
| [no-invalid-date-literal](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-invalid-date-literal.md) | Disallow invalid date literals | 🟩 ✅ 🟪 ☑️ | | | |
|
|
70
|
+
| [no-jsx-statement](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-jsx-statement.md) | Forbid JSX expression statements | 🟩 ✅ 🟪 ☑️ | | | |
|
|
71
|
+
| [no-optional-type-guard-param](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-optional-type-guard-param.md) | Forbid optional parameters in type guards | 🟩 ✅ 🟪 ☑️ | | | |
|
|
72
|
+
| [no-redundant-function-declaration](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-redundant-function-declaration.md) | Forbid redundant function declarations | 🟩 ✅ 🟪 ☑️ | 🔧 | | |
|
|
73
|
+
| [no-return-to-void](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-return-to-void.md) | Forbid returning values in void-returning callbacks | ☑️ | | | 💭 |
|
|
74
|
+
| [no-sloppy-length-check](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-sloppy-length-check.md) | Forbid sloppy collection size checks | 🟩 ✅ 🟪 ☑️ | | | |
|
|
75
|
+
| [no-suspicious-jsx-semicolon](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-suspicious-jsx-semicolon.md) | Forbid suspicious semicolons in JSX | 🟩 ✅ 🟪 ☑️ | | | |
|
|
76
|
+
| [no-ternary-return](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-ternary-return.md) | Disallow ternary conditions in return statements | 🟪 ☑️ | 🔧 | | |
|
|
77
|
+
| [no-unassigned-todo](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-unassigned-todo.md) | Forbid unassigned TODO comments | 🟪 ☑️ | | | |
|
|
78
|
+
| [no-unused-param-read](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-unused-param-read.md) | Forbid referencing parameters marked as unused with a leading underscore | 🟪 ☑️ | | | |
|
|
79
|
+
| [no-useless-computed-key](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-useless-computed-key.md) | Forbid useless computed keys | 🟪 ☑️ | 🔧 | | |
|
|
80
|
+
| [no-useless-iife](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-useless-iife.md) | Forbid useless IIFEs | 🟩 ✅ 🟪 ☑️ | | 💡 | |
|
|
81
|
+
| [no-useless-logical-fallback](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-useless-logical-fallback.md) | Forbid useless fallback values for logical expressions | ✅ ☑️ | | 💡 | 💭 |
|
|
82
|
+
| [no-useless-return-undefined](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-useless-return-undefined.md) | Forbid returning `undefined` in void-returning callbacks | ☑️ | | | 💭 |
|
|
83
|
+
| [no-useless-use-strict](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-useless-use-strict.md) | Forbid useless "use strict" directives. | 🟪 ☑️ | | | |
|
|
84
|
+
| [no-useless-usememo](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-useless-usememo.md) | Forbid useless `useMemo()` | 🟪 ☑️ | | | |
|
|
85
|
+
| [no-whitespace-property](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/no-whitespace-property.md) | Forbid leading or trailing whitespace in object keys | 🟪 ☑️ | | | |
|
|
86
|
+
| [prefer-catch-method](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/prefer-catch-method.md) | Enforce usage of `Promise.prototype.catch()` when it improves readability | 🟩 ✅ 🟪 ☑️ | | 💡 | |
|
|
87
|
+
| [prefer-early-return](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/prefer-early-return.md) | Require early returns when possible | 🟪 ☑️ | 🔧 | | |
|
|
88
|
+
| [prefer-repeat](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/prefer-repeat.md) | Enforce usage of `String.prototype.repeat` | 🟩 ✅ 🟪 ☑️ | | 💡 | |
|
|
89
|
+
| [unsafe-asserted-chain](https://github.com/mchevestrier/eslint-plugin-wyrm/blob/master/packages/eslint-plugin-wyrm/docs/rules/unsafe-asserted-chain.md) | Disallow unsafe type assertions on optional chained expressions | ☑️ | | | 💭 |
|
|
70
90
|
|
|
71
91
|
<!-- end auto-generated rules list -->
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
//#region rolldown:runtime
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __export = (all, symbols) => {
|
|
6
|
+
let target = {};
|
|
7
|
+
for (var name in all) {
|
|
8
|
+
__defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
if (symbols) {
|
|
14
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
15
|
+
}
|
|
16
|
+
return target;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { __export };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { __export } from "../_virtual/rolldown_runtime.
|
|
2
|
-
import { rules_exports } from "../rules/index.
|
|
3
|
-
import { plugin } from "../plugin.
|
|
1
|
+
import { __export } from "../_virtual/rolldown_runtime.mjs";
|
|
2
|
+
import { rules_exports } from "../rules/index.mjs";
|
|
3
|
+
import { plugin } from "../plugin.mjs";
|
|
4
4
|
|
|
5
5
|
//#region lib/configs/index.ts
|
|
6
6
|
var configs_exports = /* @__PURE__ */ __export({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { index_d_exports } from "./configs/index.
|
|
2
|
-
import { index_d_exports as index_d_exports$1 } from "./rules/index.
|
|
1
|
+
import { index_d_exports } from "./configs/index.mjs";
|
|
2
|
+
import { index_d_exports as index_d_exports$1 } from "./rules/index.mjs";
|
|
3
3
|
|
|
4
4
|
//#region lib/index.d.ts
|
|
5
5
|
interface CompatibleConfig {
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { rules_exports } from "./rules/index.mjs";
|
|
2
|
+
import { configs_exports } from "./configs/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region lib/index.ts
|
|
5
|
+
const plugin = {
|
|
6
|
+
rules: rules_exports,
|
|
7
|
+
configs: configs_exports
|
|
8
|
+
};
|
|
9
|
+
var lib_default = plugin;
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { lib_default as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { WyrmPluginDocs } from "../utils/createRule.mjs";
|
|
2
|
+
import * as _typescript_eslint_utils_ts_eslint0 from "@typescript-eslint/utils/ts-eslint";
|
|
3
|
+
|
|
4
|
+
//#region lib/rules/distribute-boolean-casts.d.ts
|
|
5
|
+
declare const _default: _typescript_eslint_utils_ts_eslint0.RuleModule<"distributeBooleanCast", [], WyrmPluginDocs, _typescript_eslint_utils_ts_eslint0.RuleListener>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _default };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createRule } from "../utils/createRule.
|
|
2
|
-
import { None, Some } from "../utils/option.
|
|
1
|
+
import { createRule } from "../utils/createRule.mjs";
|
|
2
|
+
import { None, Some } from "../utils/option.mjs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
5
5
|
|
|
@@ -11,7 +11,7 @@ var distribute_boolean_casts_default = createRule({
|
|
|
11
11
|
type: "suggestion",
|
|
12
12
|
docs: {
|
|
13
13
|
description: "Enforce that boolean casts are distributed over logical expressions",
|
|
14
|
-
|
|
14
|
+
strict: true
|
|
15
15
|
},
|
|
16
16
|
fixable: "code",
|
|
17
17
|
schema: [],
|
|
@@ -29,13 +29,22 @@ var distribute_boolean_casts_default = createRule({
|
|
|
29
29
|
fix(fixer) {
|
|
30
30
|
const left = maybeWrapInBooleanCast(node.left);
|
|
31
31
|
const right = maybeWrapInBooleanCast(node.right);
|
|
32
|
-
const newText =
|
|
32
|
+
const newText = `(${left} ${node.operator} ${right})`;
|
|
33
33
|
return fixer.replaceText(parentCast.value, newText);
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
} };
|
|
37
|
+
function getTextWithPreviousComments(node) {
|
|
38
|
+
const txt = context.sourceCode.getText(node);
|
|
39
|
+
const prev = context.sourceCode.getTokenBefore(node);
|
|
40
|
+
/* v8 ignore if -- @preserve */
|
|
41
|
+
if (!prev) return txt;
|
|
42
|
+
const previousComments = context.sourceCode.getAllComments().filter((comment) => comment.range[0] >= prev.range[1] && comment.range[1] <= node.range[0]);
|
|
43
|
+
if (!previousComments.length) return txt;
|
|
44
|
+
return `\n${previousComments.map((comment) => context.sourceCode.getText(comment)).join("\n")}\n${txt}`;
|
|
45
|
+
}
|
|
37
46
|
function maybeWrapInBooleanCast(expr) {
|
|
38
|
-
const txt =
|
|
47
|
+
const txt = getTextWithPreviousComments(expr);
|
|
39
48
|
if (isBooleanLike(expr)) return txt;
|
|
40
49
|
return `!!(${txt})`;
|
|
41
50
|
}
|
|
@@ -44,8 +53,8 @@ var distribute_boolean_casts_default = createRule({
|
|
|
44
53
|
function isBooleanLike(expr) {
|
|
45
54
|
if (expr.type === AST_NODE_TYPES.UnaryExpression) return expr.operator === "!";
|
|
46
55
|
if (expr.type === AST_NODE_TYPES.BinaryExpression) switch (expr.operator) {
|
|
47
|
-
case "&&":
|
|
48
|
-
case "||":
|
|
56
|
+
case "&&": return true;
|
|
57
|
+
case "||": return true;
|
|
49
58
|
case "!=":
|
|
50
59
|
case "!==":
|
|
51
60
|
case "==":
|
|
@@ -62,7 +71,6 @@ function isBooleanLike(expr) {
|
|
|
62
71
|
return false;
|
|
63
72
|
}
|
|
64
73
|
function getParentBooleanCast(node) {
|
|
65
|
-
if (!node.parent) return None;
|
|
66
74
|
if (node.parent.type === AST_NODE_TYPES.UnaryExpression && isDoubleNegation(node.parent)) return Some(node.parent.parent);
|
|
67
75
|
if (node.parent.type === AST_NODE_TYPES.CallExpression && isBooleanCall(node.parent)) return Some(node.parent);
|
|
68
76
|
return None;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { _default } from "./distribute-boolean-casts.mjs";
|
|
2
|
+
import { _default as _default$1 } from "./no-constant-template-expression.mjs";
|
|
3
|
+
import { _default as _default$2 } from "./no-convoluted-logical-expressions.mjs";
|
|
4
|
+
import { _default as _default$3 } from "./no-duplicated-return.mjs";
|
|
5
|
+
import { _default as _default$4 } from "./no-else-break.mjs";
|
|
6
|
+
import { _default as _default$5 } from "./no-else-continue.mjs";
|
|
7
|
+
import { _default as _default$6 } from "./no-else-throw.mjs";
|
|
8
|
+
import { _default as _default$7 } from "./no-empty-attribute.mjs";
|
|
9
|
+
import { _default as _default$8 } from "./no-empty-comment.mjs";
|
|
10
|
+
import { _default as _default$9 } from "./no-empty-jsx-expression.mjs";
|
|
11
|
+
import { _default as _default$10 } from "./no-empty-literal-iteration.mjs";
|
|
12
|
+
import { _default as _default$11 } from "./no-extra-false-fallback.mjs";
|
|
13
|
+
import { _default as _default$12 } from "./no-extra-nested-boolean-cast.mjs";
|
|
14
|
+
import { _default as _default$13 } from "./no-first-last.mjs";
|
|
15
|
+
import { _default as _default$14 } from "./no-inline-jsdoc-tag.mjs";
|
|
16
|
+
import { _default as _default$15 } from "./no-invalid-date-literal.mjs";
|
|
17
|
+
import { _default as _default$16 } from "./no-jsx-statement.mjs";
|
|
18
|
+
import { _default as _default$17 } from "./no-optional-type-guard-param.mjs";
|
|
19
|
+
import { _default as _default$18 } from "./no-redundant-function-declaration.mjs";
|
|
20
|
+
import { _default as _default$19 } from "./no-return-to-void.mjs";
|
|
21
|
+
import { _default as _default$20 } from "./no-sloppy-length-check.mjs";
|
|
22
|
+
import { _default as _default$21 } from "./no-suspicious-jsx-semicolon.mjs";
|
|
23
|
+
import { _default as _default$22 } from "./no-ternary-return.mjs";
|
|
24
|
+
import { _default as _default$23 } from "./no-unassigned-todo.mjs";
|
|
25
|
+
import { _default as _default$24 } from "./no-unused-param-read.mjs";
|
|
26
|
+
import { _default as _default$25 } from "./no-useless-computed-key.mjs";
|
|
27
|
+
import { _default as _default$26 } from "./no-useless-iife.mjs";
|
|
28
|
+
import { _default as _default$27 } from "./no-useless-logical-fallback.mjs";
|
|
29
|
+
import { _default as _default$28 } from "./no-useless-return-undefined.mjs";
|
|
30
|
+
import { _default as _default$29 } from "./no-useless-use-strict.mjs";
|
|
31
|
+
import { _default as _default$30 } from "./no-useless-usememo.mjs";
|
|
32
|
+
import { _default as _default$31 } from "./no-whitespace-property.mjs";
|
|
33
|
+
import { _default as _default$32 } from "./prefer-catch-method.mjs";
|
|
34
|
+
import { _default as _default$33 } from "./prefer-early-return.mjs";
|
|
35
|
+
import { _default as _default$34 } from "./prefer-repeat.mjs";
|
|
36
|
+
import { _default as _default$35 } from "./unsafe-asserted-chain.mjs";
|
|
37
|
+
|
|
38
|
+
//#region lib/rules/index.d.ts
|
|
39
|
+
declare namespace index_d_exports {
|
|
40
|
+
export { _default as "distribute-boolean-casts", _default$1 as "no-constant-template-expression", _default$2 as "no-convoluted-logical-expressions", _default$3 as "no-duplicated-return", _default$4 as "no-else-break", _default$5 as "no-else-continue", _default$6 as "no-else-throw", _default$7 as "no-empty-attribute", _default$8 as "no-empty-comment", _default$9 as "no-empty-jsx-expression", _default$10 as "no-empty-literal-iteration", _default$11 as "no-extra-false-fallback", _default$12 as "no-extra-nested-boolean-cast", _default$13 as "no-first-last", _default$14 as "no-inline-jsdoc-tag", _default$15 as "no-invalid-date-literal", _default$16 as "no-jsx-statement", _default$17 as "no-optional-type-guard-param", _default$18 as "no-redundant-function-declaration", _default$19 as "no-return-to-void", _default$20 as "no-sloppy-length-check", _default$21 as "no-suspicious-jsx-semicolon", _default$22 as "no-ternary-return", _default$23 as "no-unassigned-todo", _default$24 as "no-unused-param-read", _default$25 as "no-useless-computed-key", _default$26 as "no-useless-iife", _default$27 as "no-useless-logical-fallback", _default$28 as "no-useless-return-undefined", _default$29 as "no-useless-use-strict", _default$30 as "no-useless-usememo", _default$31 as "no-whitespace-property", _default$32 as "prefer-catch-method", _default$33 as "prefer-early-return", _default$34 as "prefer-repeat", _default$35 as "unsafe-asserted-chain" };
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { index_d_exports };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { __export } from "../_virtual/rolldown_runtime.mjs";
|
|
2
|
+
import distribute_boolean_casts_default from "./distribute-boolean-casts.mjs";
|
|
3
|
+
import no_constant_template_expression_default from "./no-constant-template-expression.mjs";
|
|
4
|
+
import no_convoluted_logical_expressions_default from "./no-convoluted-logical-expressions.mjs";
|
|
5
|
+
import no_duplicated_return_default from "./no-duplicated-return.mjs";
|
|
6
|
+
import no_else_break_default from "./no-else-break.mjs";
|
|
7
|
+
import no_else_continue_default from "./no-else-continue.mjs";
|
|
8
|
+
import no_else_throw_default from "./no-else-throw.mjs";
|
|
9
|
+
import no_empty_attribute_default from "./no-empty-attribute.mjs";
|
|
10
|
+
import no_empty_comment_default from "./no-empty-comment.mjs";
|
|
11
|
+
import no_empty_jsx_expression_default from "./no-empty-jsx-expression.mjs";
|
|
12
|
+
import no_empty_literal_iteration_default from "./no-empty-literal-iteration.mjs";
|
|
13
|
+
import no_extra_false_fallback_default from "./no-extra-false-fallback.mjs";
|
|
14
|
+
import no_extra_nested_boolean_cast_default from "./no-extra-nested-boolean-cast.mjs";
|
|
15
|
+
import no_first_last_default from "./no-first-last.mjs";
|
|
16
|
+
import no_inline_jsdoc_tag_default from "./no-inline-jsdoc-tag.mjs";
|
|
17
|
+
import no_invalid_date_literal_default from "./no-invalid-date-literal.mjs";
|
|
18
|
+
import no_jsx_statement_default from "./no-jsx-statement.mjs";
|
|
19
|
+
import no_optional_type_guard_param_default from "./no-optional-type-guard-param.mjs";
|
|
20
|
+
import no_redundant_function_declaration_default from "./no-redundant-function-declaration.mjs";
|
|
21
|
+
import no_return_to_void_default from "./no-return-to-void.mjs";
|
|
22
|
+
import no_sloppy_length_check_default from "./no-sloppy-length-check.mjs";
|
|
23
|
+
import no_suspicious_jsx_semicolon_default from "./no-suspicious-jsx-semicolon.mjs";
|
|
24
|
+
import no_ternary_return_default from "./no-ternary-return.mjs";
|
|
25
|
+
import no_unassigned_todo_default from "./no-unassigned-todo.mjs";
|
|
26
|
+
import no_unused_param_read_default from "./no-unused-param-read.mjs";
|
|
27
|
+
import no_useless_computed_key_default from "./no-useless-computed-key.mjs";
|
|
28
|
+
import no_useless_iife_default from "./no-useless-iife.mjs";
|
|
29
|
+
import no_useless_logical_fallback_default from "./no-useless-logical-fallback.mjs";
|
|
30
|
+
import no_useless_return_undefined_default from "./no-useless-return-undefined.mjs";
|
|
31
|
+
import no_useless_use_strict_default from "./no-useless-use-strict.mjs";
|
|
32
|
+
import no_useless_usememo_default from "./no-useless-usememo.mjs";
|
|
33
|
+
import no_whitespace_property_default from "./no-whitespace-property.mjs";
|
|
34
|
+
import prefer_catch_method_default from "./prefer-catch-method.mjs";
|
|
35
|
+
import prefer_early_return_default from "./prefer-early-return.mjs";
|
|
36
|
+
import prefer_repeat_default from "./prefer-repeat.mjs";
|
|
37
|
+
import unsafe_asserted_chain_default from "./unsafe-asserted-chain.mjs";
|
|
38
|
+
|
|
39
|
+
//#region lib/rules/index.ts
|
|
40
|
+
var rules_exports = /* @__PURE__ */ __export({
|
|
41
|
+
"distribute-boolean-casts": () => distribute_boolean_casts_default,
|
|
42
|
+
"no-constant-template-expression": () => no_constant_template_expression_default,
|
|
43
|
+
"no-convoluted-logical-expressions": () => no_convoluted_logical_expressions_default,
|
|
44
|
+
"no-duplicated-return": () => no_duplicated_return_default,
|
|
45
|
+
"no-else-break": () => no_else_break_default,
|
|
46
|
+
"no-else-continue": () => no_else_continue_default,
|
|
47
|
+
"no-else-throw": () => no_else_throw_default,
|
|
48
|
+
"no-empty-attribute": () => no_empty_attribute_default,
|
|
49
|
+
"no-empty-comment": () => no_empty_comment_default,
|
|
50
|
+
"no-empty-jsx-expression": () => no_empty_jsx_expression_default,
|
|
51
|
+
"no-empty-literal-iteration": () => no_empty_literal_iteration_default,
|
|
52
|
+
"no-extra-false-fallback": () => no_extra_false_fallback_default,
|
|
53
|
+
"no-extra-nested-boolean-cast": () => no_extra_nested_boolean_cast_default,
|
|
54
|
+
"no-first-last": () => no_first_last_default,
|
|
55
|
+
"no-inline-jsdoc-tag": () => no_inline_jsdoc_tag_default,
|
|
56
|
+
"no-invalid-date-literal": () => no_invalid_date_literal_default,
|
|
57
|
+
"no-jsx-statement": () => no_jsx_statement_default,
|
|
58
|
+
"no-optional-type-guard-param": () => no_optional_type_guard_param_default,
|
|
59
|
+
"no-redundant-function-declaration": () => no_redundant_function_declaration_default,
|
|
60
|
+
"no-return-to-void": () => no_return_to_void_default,
|
|
61
|
+
"no-sloppy-length-check": () => no_sloppy_length_check_default,
|
|
62
|
+
"no-suspicious-jsx-semicolon": () => no_suspicious_jsx_semicolon_default,
|
|
63
|
+
"no-ternary-return": () => no_ternary_return_default,
|
|
64
|
+
"no-unassigned-todo": () => no_unassigned_todo_default,
|
|
65
|
+
"no-unused-param-read": () => no_unused_param_read_default,
|
|
66
|
+
"no-useless-computed-key": () => no_useless_computed_key_default,
|
|
67
|
+
"no-useless-iife": () => no_useless_iife_default,
|
|
68
|
+
"no-useless-logical-fallback": () => no_useless_logical_fallback_default,
|
|
69
|
+
"no-useless-return-undefined": () => no_useless_return_undefined_default,
|
|
70
|
+
"no-useless-use-strict": () => no_useless_use_strict_default,
|
|
71
|
+
"no-useless-usememo": () => no_useless_usememo_default,
|
|
72
|
+
"no-whitespace-property": () => no_whitespace_property_default,
|
|
73
|
+
"prefer-catch-method": () => prefer_catch_method_default,
|
|
74
|
+
"prefer-early-return": () => prefer_early_return_default,
|
|
75
|
+
"prefer-repeat": () => prefer_repeat_default,
|
|
76
|
+
"unsafe-asserted-chain": () => unsafe_asserted_chain_default
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
export { rules_exports };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WyrmPluginDocs } from "../utils/createRule.mjs";
|
|
2
|
+
import { TSESLint } from "@typescript-eslint/utils";
|
|
3
|
+
|
|
4
|
+
//#region lib/rules/no-constant-template-expression.d.ts
|
|
5
|
+
|
|
6
|
+
declare const _default: TSESLint.RuleModule<"noConstantTemplateExpression" | "replaceByString", [{
|
|
7
|
+
minAllowedLength: number;
|
|
8
|
+
}], WyrmPluginDocs, TSESLint.RuleListener>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { _default };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { createRule } from "../utils/createRule.mjs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { ASTUtils, AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
|
|
4
|
+
import * as ts from "typescript";
|
|
5
|
+
|
|
6
|
+
//#region lib/rules/no-constant-template-expression.ts
|
|
7
|
+
/**
|
|
8
|
+
* @fileoverview
|
|
9
|
+
*
|
|
10
|
+
* It is sometimes clearer to inline interpolated expressions when their values are constant:
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const foo = 'foobar';
|
|
15
|
+
* const str = `${foo}_baz`;
|
|
16
|
+
* // This would be clearer as:
|
|
17
|
+
* const str = 'foobar_baz';
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* By default, this rule allows constant values when they take up at least 10 characters.
|
|
21
|
+
* This can be configured with the `minAllowedLength` option.
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
const { name } = path.parse(import.meta.filename);
|
|
25
|
+
const DEFAULT_MIN_ALLOWED_LENGTH = 10;
|
|
26
|
+
var no_constant_template_expression_default = createRule({
|
|
27
|
+
name,
|
|
28
|
+
meta: {
|
|
29
|
+
type: "suggestion",
|
|
30
|
+
docs: {
|
|
31
|
+
description: "Disallow constant string expressions in template literals",
|
|
32
|
+
requiresTypeChecking: true,
|
|
33
|
+
strict: true
|
|
34
|
+
},
|
|
35
|
+
hasSuggestions: true,
|
|
36
|
+
schema: [{
|
|
37
|
+
type: "object",
|
|
38
|
+
properties: { minAllowedLength: {
|
|
39
|
+
type: "number",
|
|
40
|
+
description: `Minimum string length allowed for constant expressions. Default: ${DEFAULT_MIN_ALLOWED_LENGTH}`
|
|
41
|
+
} }
|
|
42
|
+
}],
|
|
43
|
+
messages: {
|
|
44
|
+
noConstantTemplateExpression: "Replace this constant template expression by its value as a string ('{{value}}')",
|
|
45
|
+
replaceByString: "Replace by '{{value}}'"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
defaultOptions: [{ minAllowedLength: DEFAULT_MIN_ALLOWED_LENGTH }],
|
|
49
|
+
create(context, [options]) {
|
|
50
|
+
function checkExpression(expr, quasis, scope) {
|
|
51
|
+
if (expr.type === AST_NODE_TYPES.Identifier) {
|
|
52
|
+
const variable = ASTUtils.findVariable(scope, expr);
|
|
53
|
+
if (variable) {
|
|
54
|
+
const { references, defs } = variable;
|
|
55
|
+
if (references.length > 2) return;
|
|
56
|
+
const def = defs.at(-1);
|
|
57
|
+
if (def?.parent?.type === AST_NODE_TYPES.VariableDeclaration && (def.parent.parent.type === AST_NODE_TYPES.ExportNamedDeclaration || def.parent.parent.type === AST_NODE_TYPES.ExportDefaultDeclaration)) return;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const services = ESLintUtils.getParserServices(context);
|
|
61
|
+
const checker = services.program.getTypeChecker();
|
|
62
|
+
const value = getLiteralValue(services.getTypeAtLocation(expr), checker);
|
|
63
|
+
if (value === null) return;
|
|
64
|
+
if (value.length >= options.minAllowedLength) return;
|
|
65
|
+
const sym = services.getSymbolAtLocation(expr);
|
|
66
|
+
if (sym && sym.getFlags() & ts.SymbolFlags.EnumMember && !quasis.some((quasi) => quasi.value.cooked)) return;
|
|
67
|
+
context.report({
|
|
68
|
+
node: expr,
|
|
69
|
+
messageId: "noConstantTemplateExpression",
|
|
70
|
+
data: { value },
|
|
71
|
+
suggest: [{
|
|
72
|
+
messageId: "replaceByString",
|
|
73
|
+
data: { value },
|
|
74
|
+
*fix(fixer) {
|
|
75
|
+
const [identStart, identEnd] = expr.range;
|
|
76
|
+
const previousQuasi = quasis.toReversed().find((quasi) => quasi.range[1] <= identStart);
|
|
77
|
+
const nextQuasi = quasis.find((quasi) => quasi.range[0] >= identEnd);
|
|
78
|
+
/* v8 ignore if -- @preserve */
|
|
79
|
+
if (!previousQuasi || !nextQuasi) {
|
|
80
|
+
console.error("No previous/next quasi found. This should never happen.");
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const start = previousQuasi.range[1];
|
|
84
|
+
const end = nextQuasi.range[0];
|
|
85
|
+
const range = [start - 2, end + 1];
|
|
86
|
+
yield fixer.replaceTextRange(range, value);
|
|
87
|
+
}
|
|
88
|
+
}]
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return { TemplateLiteral(node) {
|
|
92
|
+
const { expressions, quasis } = node;
|
|
93
|
+
if (quasis.some((quasi) => quasi.value.cooked.includes(" "))) return;
|
|
94
|
+
const scope = context.sourceCode.getScope(node);
|
|
95
|
+
for (const expr of expressions) checkExpression(expr, quasis, scope);
|
|
96
|
+
} };
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
function getLiteralValue(type, checker) {
|
|
100
|
+
if (type.isStringLiteral()) return type.value;
|
|
101
|
+
if (type.isNumberLiteral()) return type.value.toString();
|
|
102
|
+
if (type === checker.getTrueType()) return "true";
|
|
103
|
+
if (type === checker.getFalseType()) return "false";
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
//#endregion
|
|
108
|
+
export { no_constant_template_expression_default as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { WyrmPluginDocs } from "../utils/createRule.mjs";
|
|
2
|
+
import * as _typescript_eslint_utils_ts_eslint3 from "@typescript-eslint/utils/ts-eslint";
|
|
3
|
+
|
|
4
|
+
//#region lib/rules/no-convoluted-logical-expressions.d.ts
|
|
5
|
+
declare const _default: _typescript_eslint_utils_ts_eslint3.RuleModule<"noConvolutedLogicalExpression", [], WyrmPluginDocs, _typescript_eslint_utils_ts_eslint3.RuleListener>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _default };
|