eslint-plugin-wyrm 0.0.5 β 0.0.7
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 +16 -0
- package/README.md +18 -9
- package/dist/configs/index.js +3 -3
- package/dist/rules/distribute-boolean-casts.d.ts +7 -0
- package/dist/rules/distribute-boolean-casts.js +83 -0
- package/dist/rules/index.d.ts +17 -8
- package/dist/rules/index.js +18 -0
- package/dist/rules/no-else-break.d.ts +7 -0
- package/dist/rules/no-else-break.js +51 -0
- package/dist/rules/no-else-continue.d.ts +7 -0
- package/dist/rules/no-else-continue.js +51 -0
- package/dist/rules/no-else-throw.d.ts +7 -0
- package/dist/rules/no-else-throw.js +51 -0
- package/dist/rules/no-empty-comment.d.ts +3 -3
- package/dist/rules/no-empty-jsx-expression.d.ts +2 -2
- package/dist/rules/no-empty-jsx-expression.js +1 -0
- package/dist/rules/no-extra-nested-boolean-cast.d.ts +2 -2
- package/dist/rules/no-invalid-date-literal.d.ts +7 -0
- package/dist/rules/no-invalid-date-literal.js +70 -0
- package/dist/rules/no-jsx-statement.d.ts +2 -2
- package/dist/rules/no-suspicious-jsx-semicolon.d.ts +8 -0
- package/dist/rules/no-suspicious-jsx-semicolon.js +39 -0
- package/dist/rules/no-ternary-return.d.ts +4 -3
- package/dist/rules/no-useless-iife.d.ts +7 -0
- package/dist/rules/no-useless-iife.js +93 -0
- package/dist/rules/prefer-catch-method.d.ts +7 -0
- package/dist/rules/prefer-catch-method.js +121 -0
- package/dist/rules/prefer-repeat.d.ts +7 -0
- package/dist/rules/prefer-repeat.js +108 -0
- package/dist/utils/option.js +18 -0
- package/package.json +1 -1
- package/docs/rules/no-constant-template-expression.md +0 -83
- package/docs/rules/no-empty-comment.md +0 -70
- package/docs/rules/no-empty-jsx-expression.md +0 -77
- package/docs/rules/no-extra-nested-boolean-cast.md +0 -112
- package/docs/rules/no-jsx-statement.md +0 -36
- package/docs/rules/no-ternary-return.md +0 -46
- package/docs/rules/unsafe-asserted-chain.md +0 -68
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [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
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* add distribute-boolean-casts ([a6a7a1d](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/a6a7a1d34fe2dca977bd98fb27337797ce1b1200))
|
|
9
|
+
* add prefer-catch-method ([fb1b614](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/fb1b614f2a2e53c8e2ca197b706f458cbe73ba4a))
|
|
10
|
+
|
|
11
|
+
## [0.0.6](https://github.com/mchevestrier/eslint-plugin-wyrm/compare/eslint-plugin-wyrm-v0.0.5...eslint-plugin-wyrm-v0.0.6) (2025-11-04)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* add no-else-break and no-else-continue ([eb2647f](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/eb2647feb3a5d04782a86db8324259afb70a5369))
|
|
17
|
+
* add no-else-throw ([cedc18e](https://github.com/mchevestrier/eslint-plugin-wyrm/commit/cedc18efd6952c3c3195d378dbd59a8772b7613d))
|
|
18
|
+
|
|
3
19
|
## [0.0.5](https://github.com/mchevestrier/eslint-plugin-wyrm/compare/eslint-plugin-wyrm-v0.0.4...eslint-plugin-wyrm-v0.0.5) (2025-11-02)
|
|
4
20
|
|
|
5
21
|
|
package/README.md
CHANGED
|
@@ -49,14 +49,23 @@ 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Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β | Description
|
|
53
|
-
| :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
54
|
-
| [
|
|
55
|
-
| [no-
|
|
56
|
-
| [no-
|
|
57
|
-
| [no-
|
|
58
|
-
| [no-
|
|
59
|
-
| [no-
|
|
60
|
-
| [
|
|
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-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 | π© β
πͺ βοΈ | π§ | | |
|
|
57
|
+
| [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 | π© β
πͺ βοΈ | π§ | | |
|
|
58
|
+
| [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 | π© β
πͺ βοΈ | π§ | | |
|
|
59
|
+
| [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 | πͺ βοΈ | | | |
|
|
60
|
+
| [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 | π© β
πͺ βοΈ | | | |
|
|
61
|
+
| [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 | πͺ βοΈ | | | |
|
|
62
|
+
| [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 | π© β
πͺ βοΈ | | | |
|
|
63
|
+
| [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 | π© β
πͺ βοΈ | | | |
|
|
64
|
+
| [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 | π© β
πͺ βοΈ | | | |
|
|
65
|
+
| [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 | πͺ βοΈ | π§ | | |
|
|
66
|
+
| [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 | π© β
πͺ βοΈ | | π‘ | |
|
|
67
|
+
| [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 | π© β
πͺ βοΈ | | π‘ | |
|
|
68
|
+
| [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` | π© β
πͺ βοΈ | | π‘ | |
|
|
69
|
+
| [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 | βοΈ | | | π |
|
|
61
70
|
|
|
62
71
|
<!-- end auto-generated rules list -->
|
package/dist/configs/index.js
CHANGED
|
@@ -38,7 +38,7 @@ const strictOnly = createConfigWithRules(rules_exports, "strictOnly", (rule) =>
|
|
|
38
38
|
});
|
|
39
39
|
const strict = {
|
|
40
40
|
...baseConfig,
|
|
41
|
-
name:
|
|
41
|
+
name: "wyrm/strict",
|
|
42
42
|
rules: {
|
|
43
43
|
...recommended.rules,
|
|
44
44
|
...strictOnly.rules
|
|
@@ -51,7 +51,7 @@ const recommendedTypeCheckedOnly = createConfigWithRules(rules_exports, "recomme
|
|
|
51
51
|
});
|
|
52
52
|
const recommendedTypeChecked = {
|
|
53
53
|
...baseConfig,
|
|
54
|
-
name:
|
|
54
|
+
name: "wyrm/recommendedTypeChecked",
|
|
55
55
|
rules: {
|
|
56
56
|
...recommended.rules,
|
|
57
57
|
...recommendedTypeCheckedOnly.rules
|
|
@@ -64,7 +64,7 @@ const strictTypeCheckedOnly = createConfigWithRules(rules_exports, "strictTypeCh
|
|
|
64
64
|
});
|
|
65
65
|
const strictTypeChecked = {
|
|
66
66
|
...baseConfig,
|
|
67
|
-
name:
|
|
67
|
+
name: "wyrm/strictTypeChecked",
|
|
68
68
|
rules: {
|
|
69
69
|
...recommendedTypeChecked.rules,
|
|
70
70
|
...strictOnly.rules,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { WyrmPluginDocs } from "../utils/createRule.js";
|
|
2
|
+
import * as _typescript_eslint_utils_ts_eslint1 from "@typescript-eslint/utils/ts-eslint";
|
|
3
|
+
|
|
4
|
+
//#region lib/rules/distribute-boolean-casts.d.ts
|
|
5
|
+
declare const _default: _typescript_eslint_utils_ts_eslint1.RuleModule<"distributeBooleanCast", [], WyrmPluginDocs, _typescript_eslint_utils_ts_eslint1.RuleListener>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _default };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createRule } from "../utils/createRule.js";
|
|
2
|
+
import { None, Some } from "../utils/option.js";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
5
|
+
|
|
6
|
+
//#region lib/rules/distribute-boolean-casts.ts
|
|
7
|
+
const { name } = path.parse(import.meta.filename);
|
|
8
|
+
var distribute_boolean_casts_default = createRule({
|
|
9
|
+
name,
|
|
10
|
+
meta: {
|
|
11
|
+
type: "suggestion",
|
|
12
|
+
docs: {
|
|
13
|
+
description: "Enforce that boolean casts are distributed over logical expressions",
|
|
14
|
+
recommended: true
|
|
15
|
+
},
|
|
16
|
+
fixable: "code",
|
|
17
|
+
schema: [],
|
|
18
|
+
messages: { distributeBooleanCast: "Distribute this boolean cast over logical expressions" }
|
|
19
|
+
},
|
|
20
|
+
defaultOptions: [],
|
|
21
|
+
create(context) {
|
|
22
|
+
return { LogicalExpression(node) {
|
|
23
|
+
if (node.operator === "??") return;
|
|
24
|
+
const parentCast = getParentBooleanCast(node);
|
|
25
|
+
if (!parentCast.some) return;
|
|
26
|
+
context.report({
|
|
27
|
+
node,
|
|
28
|
+
messageId: "distributeBooleanCast",
|
|
29
|
+
fix(fixer) {
|
|
30
|
+
const left = maybeWrapInBooleanCast(node.left);
|
|
31
|
+
const right = maybeWrapInBooleanCast(node.right);
|
|
32
|
+
const newText = `${left} ${node.operator} ${right}`;
|
|
33
|
+
return fixer.replaceText(parentCast.value, newText);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
} };
|
|
37
|
+
function maybeWrapInBooleanCast(expr) {
|
|
38
|
+
const txt = context.sourceCode.getText(expr);
|
|
39
|
+
if (isBooleanLike(expr)) return txt;
|
|
40
|
+
return `!!(${txt})`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
function isBooleanLike(expr) {
|
|
45
|
+
if (expr.type === AST_NODE_TYPES.UnaryExpression) return expr.operator === "!";
|
|
46
|
+
if (expr.type === AST_NODE_TYPES.BinaryExpression) switch (expr.operator) {
|
|
47
|
+
case "&&":
|
|
48
|
+
case "||":
|
|
49
|
+
case "!=":
|
|
50
|
+
case "!==":
|
|
51
|
+
case "==":
|
|
52
|
+
case "===":
|
|
53
|
+
case "<":
|
|
54
|
+
case "<=":
|
|
55
|
+
case ">":
|
|
56
|
+
case ">=":
|
|
57
|
+
case "in":
|
|
58
|
+
case "instanceof": return true;
|
|
59
|
+
default: return false;
|
|
60
|
+
}
|
|
61
|
+
if (expr.type === AST_NODE_TYPES.Literal) return typeof expr.value === "boolean";
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
function getParentBooleanCast(node) {
|
|
65
|
+
if (!node.parent) return None;
|
|
66
|
+
if (node.parent.type === AST_NODE_TYPES.UnaryExpression && isDoubleNegation(node.parent)) return Some(node.parent.parent);
|
|
67
|
+
if (node.parent.type === AST_NODE_TYPES.CallExpression && isBooleanCall(node.parent)) return Some(node.parent);
|
|
68
|
+
return None;
|
|
69
|
+
}
|
|
70
|
+
function isDoubleNegation(node) {
|
|
71
|
+
if (node.operator !== "!") return false;
|
|
72
|
+
if (node.parent.type !== AST_NODE_TYPES.UnaryExpression) return false;
|
|
73
|
+
if (node.parent.operator !== "!") return false;
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
function isBooleanCall(node) {
|
|
77
|
+
if (node.callee.type !== AST_NODE_TYPES.Identifier) return false;
|
|
78
|
+
if (node.callee.name !== "Boolean") return false;
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//#endregion
|
|
83
|
+
export { distribute_boolean_casts_default as default };
|
package/dist/rules/index.d.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
import { _default } from "./
|
|
2
|
-
import { _default as _default$1 } from "./no-
|
|
3
|
-
import { _default as _default$2 } from "./no-
|
|
4
|
-
import { _default as _default$3 } from "./no-
|
|
5
|
-
import { _default as _default$4 } from "./no-
|
|
6
|
-
import { _default as _default$5 } from "./no-
|
|
7
|
-
import { _default as _default$6 } from "./
|
|
1
|
+
import { _default } from "./distribute-boolean-casts.js";
|
|
2
|
+
import { _default as _default$1 } from "./no-constant-template-expression.js";
|
|
3
|
+
import { _default as _default$2 } from "./no-else-break.js";
|
|
4
|
+
import { _default as _default$3 } from "./no-else-continue.js";
|
|
5
|
+
import { _default as _default$4 } from "./no-else-throw.js";
|
|
6
|
+
import { _default as _default$5 } from "./no-empty-comment.js";
|
|
7
|
+
import { _default as _default$6 } from "./no-empty-jsx-expression.js";
|
|
8
|
+
import { _default as _default$7 } from "./no-extra-nested-boolean-cast.js";
|
|
9
|
+
import { _default as _default$8 } from "./no-invalid-date-literal.js";
|
|
10
|
+
import { _default as _default$9 } from "./no-jsx-statement.js";
|
|
11
|
+
import { _default as _default$10 } from "./no-suspicious-jsx-semicolon.js";
|
|
12
|
+
import { _default as _default$11 } from "./no-ternary-return.js";
|
|
13
|
+
import { _default as _default$12 } from "./no-useless-iife.js";
|
|
14
|
+
import { _default as _default$13 } from "./prefer-catch-method.js";
|
|
15
|
+
import { _default as _default$14 } from "./prefer-repeat.js";
|
|
16
|
+
import { _default as _default$15 } from "./unsafe-asserted-chain.js";
|
|
8
17
|
|
|
9
18
|
//#region lib/rules/index.d.ts
|
|
10
19
|
declare namespace index_d_exports {
|
|
11
|
-
export { _default as "no-constant-template-expression", _default$
|
|
20
|
+
export { _default as "distribute-boolean-casts", _default$1 as "no-constant-template-expression", _default$2 as "no-else-break", _default$3 as "no-else-continue", _default$4 as "no-else-throw", _default$5 as "no-empty-comment", _default$6 as "no-empty-jsx-expression", _default$7 as "no-extra-nested-boolean-cast", _default$8 as "no-invalid-date-literal", _default$9 as "no-jsx-statement", _default$10 as "no-suspicious-jsx-semicolon", _default$11 as "no-ternary-return", _default$12 as "no-useless-iife", _default$13 as "prefer-catch-method", _default$14 as "prefer-repeat", _default$15 as "unsafe-asserted-chain" };
|
|
12
21
|
}
|
|
13
22
|
//#endregion
|
|
14
23
|
export { index_d_exports };
|
package/dist/rules/index.js
CHANGED
|
@@ -1,20 +1,38 @@
|
|
|
1
1
|
import { __export } from "../_virtual/rolldown_runtime.js";
|
|
2
|
+
import distribute_boolean_casts_default from "./distribute-boolean-casts.js";
|
|
2
3
|
import no_constant_template_expression_default from "./no-constant-template-expression.js";
|
|
4
|
+
import no_else_break_default from "./no-else-break.js";
|
|
5
|
+
import no_else_continue_default from "./no-else-continue.js";
|
|
6
|
+
import no_else_throw_default from "./no-else-throw.js";
|
|
3
7
|
import no_empty_comment_default from "./no-empty-comment.js";
|
|
4
8
|
import no_empty_jsx_expression_default from "./no-empty-jsx-expression.js";
|
|
5
9
|
import no_extra_nested_boolean_cast_default from "./no-extra-nested-boolean-cast.js";
|
|
10
|
+
import no_invalid_date_literal_default from "./no-invalid-date-literal.js";
|
|
6
11
|
import no_jsx_statement_default from "./no-jsx-statement.js";
|
|
12
|
+
import no_suspicious_jsx_semicolon_default from "./no-suspicious-jsx-semicolon.js";
|
|
7
13
|
import no_ternary_return_default from "./no-ternary-return.js";
|
|
14
|
+
import no_useless_iife_default from "./no-useless-iife.js";
|
|
15
|
+
import prefer_catch_method_default from "./prefer-catch-method.js";
|
|
16
|
+
import prefer_repeat_default from "./prefer-repeat.js";
|
|
8
17
|
import unsafe_asserted_chain_default from "./unsafe-asserted-chain.js";
|
|
9
18
|
|
|
10
19
|
//#region lib/rules/index.ts
|
|
11
20
|
var rules_exports = /* @__PURE__ */ __export({
|
|
21
|
+
"distribute-boolean-casts": () => distribute_boolean_casts_default,
|
|
12
22
|
"no-constant-template-expression": () => no_constant_template_expression_default,
|
|
23
|
+
"no-else-break": () => no_else_break_default,
|
|
24
|
+
"no-else-continue": () => no_else_continue_default,
|
|
25
|
+
"no-else-throw": () => no_else_throw_default,
|
|
13
26
|
"no-empty-comment": () => no_empty_comment_default,
|
|
14
27
|
"no-empty-jsx-expression": () => no_empty_jsx_expression_default,
|
|
15
28
|
"no-extra-nested-boolean-cast": () => no_extra_nested_boolean_cast_default,
|
|
29
|
+
"no-invalid-date-literal": () => no_invalid_date_literal_default,
|
|
16
30
|
"no-jsx-statement": () => no_jsx_statement_default,
|
|
31
|
+
"no-suspicious-jsx-semicolon": () => no_suspicious_jsx_semicolon_default,
|
|
17
32
|
"no-ternary-return": () => no_ternary_return_default,
|
|
33
|
+
"no-useless-iife": () => no_useless_iife_default,
|
|
34
|
+
"prefer-catch-method": () => prefer_catch_method_default,
|
|
35
|
+
"prefer-repeat": () => prefer_repeat_default,
|
|
18
36
|
"unsafe-asserted-chain": () => unsafe_asserted_chain_default
|
|
19
37
|
});
|
|
20
38
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { WyrmPluginDocs } from "../utils/createRule.js";
|
|
2
|
+
import * as _typescript_eslint_utils_ts_eslint0 from "@typescript-eslint/utils/ts-eslint";
|
|
3
|
+
|
|
4
|
+
//#region lib/rules/no-else-break.d.ts
|
|
5
|
+
declare const _default: _typescript_eslint_utils_ts_eslint0.RuleModule<"noElseBreak", [], WyrmPluginDocs, _typescript_eslint_utils_ts_eslint0.RuleListener>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _default };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createRule } from "../utils/createRule.js";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
4
|
+
|
|
5
|
+
//#region lib/rules/no-else-break.ts
|
|
6
|
+
const { name } = path.parse(import.meta.filename);
|
|
7
|
+
var no_else_break_default = createRule({
|
|
8
|
+
name,
|
|
9
|
+
meta: {
|
|
10
|
+
type: "suggestion",
|
|
11
|
+
docs: {
|
|
12
|
+
description: "Forbid unnecessary `else` block after a `break` statement",
|
|
13
|
+
recommended: true
|
|
14
|
+
},
|
|
15
|
+
fixable: "code",
|
|
16
|
+
schema: [],
|
|
17
|
+
messages: { noElseBreak: "Remove this unnecessary else" }
|
|
18
|
+
},
|
|
19
|
+
defaultOptions: [],
|
|
20
|
+
create(context) {
|
|
21
|
+
return { IfStatement(node) {
|
|
22
|
+
const { alternate } = node;
|
|
23
|
+
if (!alternate) return;
|
|
24
|
+
const lastConsequentStatement = getLastStatement(node.consequent);
|
|
25
|
+
if (!lastConsequentStatement) return;
|
|
26
|
+
if (lastConsequentStatement.type === AST_NODE_TYPES.BreakStatement) context.report({
|
|
27
|
+
node: alternate,
|
|
28
|
+
messageId: "noElseBreak",
|
|
29
|
+
*fix(fixer) {
|
|
30
|
+
const firstToken = context.sourceCode.getTokenBefore(alternate);
|
|
31
|
+
if (firstToken) yield fixer.remove(firstToken);
|
|
32
|
+
yield fixer.remove(alternate);
|
|
33
|
+
if (alternate.type === AST_NODE_TYPES.BlockStatement) {
|
|
34
|
+
const bodyText$1 = alternate.body.map((stmt) => context.sourceCode.getText(stmt)).join("\n");
|
|
35
|
+
yield fixer.insertTextAfter(node, bodyText$1);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const bodyText = context.sourceCode.getText(alternate);
|
|
39
|
+
yield fixer.insertTextAfter(node, bodyText);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
} };
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
function getLastStatement(stmt) {
|
|
46
|
+
if (stmt.type === AST_NODE_TYPES.BlockStatement) return stmt.body.at(-1);
|
|
47
|
+
return stmt;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
export { no_else_break_default as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { WyrmPluginDocs } from "../utils/createRule.js";
|
|
2
|
+
import * as _typescript_eslint_utils_ts_eslint5 from "@typescript-eslint/utils/ts-eslint";
|
|
3
|
+
|
|
4
|
+
//#region lib/rules/no-else-continue.d.ts
|
|
5
|
+
declare const _default: _typescript_eslint_utils_ts_eslint5.RuleModule<"noElseContinue", [], WyrmPluginDocs, _typescript_eslint_utils_ts_eslint5.RuleListener>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _default };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createRule } from "../utils/createRule.js";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
4
|
+
|
|
5
|
+
//#region lib/rules/no-else-continue.ts
|
|
6
|
+
const { name } = path.parse(import.meta.filename);
|
|
7
|
+
var no_else_continue_default = createRule({
|
|
8
|
+
name,
|
|
9
|
+
meta: {
|
|
10
|
+
type: "suggestion",
|
|
11
|
+
docs: {
|
|
12
|
+
description: "Forbid unnecessary `else` block after a `continue` statement",
|
|
13
|
+
recommended: true
|
|
14
|
+
},
|
|
15
|
+
fixable: "code",
|
|
16
|
+
schema: [],
|
|
17
|
+
messages: { noElseContinue: "Remove this unnecessary else" }
|
|
18
|
+
},
|
|
19
|
+
defaultOptions: [],
|
|
20
|
+
create(context) {
|
|
21
|
+
return { IfStatement(node) {
|
|
22
|
+
const { alternate } = node;
|
|
23
|
+
if (!alternate) return;
|
|
24
|
+
const lastConsequentStatement = getLastStatement(node.consequent);
|
|
25
|
+
if (!lastConsequentStatement) return;
|
|
26
|
+
if (lastConsequentStatement.type === AST_NODE_TYPES.ContinueStatement) context.report({
|
|
27
|
+
node: alternate,
|
|
28
|
+
messageId: "noElseContinue",
|
|
29
|
+
*fix(fixer) {
|
|
30
|
+
const firstToken = context.sourceCode.getTokenBefore(alternate);
|
|
31
|
+
if (firstToken) yield fixer.remove(firstToken);
|
|
32
|
+
yield fixer.remove(alternate);
|
|
33
|
+
if (alternate.type === AST_NODE_TYPES.BlockStatement) {
|
|
34
|
+
const bodyText$1 = alternate.body.map((stmt) => context.sourceCode.getText(stmt)).join("\n");
|
|
35
|
+
yield fixer.insertTextAfter(node, bodyText$1);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const bodyText = context.sourceCode.getText(alternate);
|
|
39
|
+
yield fixer.insertTextAfter(node, bodyText);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
} };
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
function getLastStatement(stmt) {
|
|
46
|
+
if (stmt.type === AST_NODE_TYPES.BlockStatement) return stmt.body.at(-1);
|
|
47
|
+
return stmt;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
export { no_else_continue_default as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { WyrmPluginDocs } from "../utils/createRule.js";
|
|
2
|
+
import * as _typescript_eslint_utils_ts_eslint7 from "@typescript-eslint/utils/ts-eslint";
|
|
3
|
+
|
|
4
|
+
//#region lib/rules/no-else-throw.d.ts
|
|
5
|
+
declare const _default: _typescript_eslint_utils_ts_eslint7.RuleModule<"noElseThrow", [], WyrmPluginDocs, _typescript_eslint_utils_ts_eslint7.RuleListener>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _default };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createRule } from "../utils/createRule.js";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
4
|
+
|
|
5
|
+
//#region lib/rules/no-else-throw.ts
|
|
6
|
+
const { name } = path.parse(import.meta.filename);
|
|
7
|
+
var no_else_throw_default = createRule({
|
|
8
|
+
name,
|
|
9
|
+
meta: {
|
|
10
|
+
type: "suggestion",
|
|
11
|
+
docs: {
|
|
12
|
+
description: "Forbid unnecessary `else` block after a `throw` statement",
|
|
13
|
+
recommended: true
|
|
14
|
+
},
|
|
15
|
+
fixable: "code",
|
|
16
|
+
schema: [],
|
|
17
|
+
messages: { noElseThrow: "Remove this unnecessary else" }
|
|
18
|
+
},
|
|
19
|
+
defaultOptions: [],
|
|
20
|
+
create(context) {
|
|
21
|
+
return { IfStatement(node) {
|
|
22
|
+
const { alternate } = node;
|
|
23
|
+
if (!alternate) return;
|
|
24
|
+
const lastConsequentStatement = getLastStatement(node.consequent);
|
|
25
|
+
if (!lastConsequentStatement) return;
|
|
26
|
+
if (lastConsequentStatement.type === AST_NODE_TYPES.ThrowStatement) context.report({
|
|
27
|
+
node: alternate,
|
|
28
|
+
messageId: "noElseThrow",
|
|
29
|
+
*fix(fixer) {
|
|
30
|
+
const firstToken = context.sourceCode.getTokenBefore(alternate);
|
|
31
|
+
if (firstToken) yield fixer.remove(firstToken);
|
|
32
|
+
yield fixer.remove(alternate);
|
|
33
|
+
if (alternate.type === AST_NODE_TYPES.BlockStatement) {
|
|
34
|
+
const bodyText$1 = alternate.body.map((stmt) => context.sourceCode.getText(stmt)).join("\n");
|
|
35
|
+
yield fixer.insertTextAfter(node, bodyText$1);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const bodyText = context.sourceCode.getText(alternate);
|
|
39
|
+
yield fixer.insertTextAfter(node, bodyText);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
} };
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
function getLastStatement(stmt) {
|
|
46
|
+
if (stmt.type === AST_NODE_TYPES.BlockStatement) return stmt.body.at(-1);
|
|
47
|
+
return stmt;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
export { no_else_throw_default as default };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { WyrmPluginDocs } from "../utils/createRule.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _typescript_eslint_utils_ts_eslint9 from "@typescript-eslint/utils/ts-eslint";
|
|
3
3
|
|
|
4
4
|
//#region lib/rules/no-empty-comment.d.ts
|
|
5
|
-
declare const _default:
|
|
5
|
+
declare const _default: _typescript_eslint_utils_ts_eslint9.RuleModule<"noEmptyComment", [{
|
|
6
6
|
allowStacked: boolean;
|
|
7
|
-
}], WyrmPluginDocs,
|
|
7
|
+
}], WyrmPluginDocs, _typescript_eslint_utils_ts_eslint9.RuleListener>;
|
|
8
8
|
//#endregion
|
|
9
9
|
export { _default };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { WyrmPluginDocs } from "../utils/createRule.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _typescript_eslint_utils_ts_eslint11 from "@typescript-eslint/utils/ts-eslint";
|
|
3
3
|
|
|
4
4
|
//#region lib/rules/no-empty-jsx-expression.d.ts
|
|
5
|
-
declare const _default:
|
|
5
|
+
declare const _default: _typescript_eslint_utils_ts_eslint11.RuleModule<"noEmptyJsxExpression", [], WyrmPluginDocs, _typescript_eslint_utils_ts_eslint11.RuleListener>;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { _default };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { WyrmPluginDocs } from "../utils/createRule.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _typescript_eslint_utils_ts_eslint15 from "@typescript-eslint/utils/ts-eslint";
|
|
3
3
|
|
|
4
4
|
//#region lib/rules/no-extra-nested-boolean-cast.d.ts
|
|
5
5
|
|
|
6
|
-
declare const _default:
|
|
6
|
+
declare const _default: _typescript_eslint_utils_ts_eslint15.RuleModule<"noExtraBooleanCastInCondition" | "noExtraBooleanCastInPredicate" | "noExtraBooleanCastInsideAnother", [], WyrmPluginDocs, _typescript_eslint_utils_ts_eslint15.RuleListener>;
|
|
7
7
|
//#endregion
|
|
8
8
|
export { _default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { WyrmPluginDocs } from "../utils/createRule.js";
|
|
2
|
+
import * as _typescript_eslint_utils_ts_eslint3 from "@typescript-eslint/utils/ts-eslint";
|
|
3
|
+
|
|
4
|
+
//#region lib/rules/no-invalid-date-literal.d.ts
|
|
5
|
+
declare const _default: _typescript_eslint_utils_ts_eslint3.RuleModule<"noInvalidDateLiteral", [], WyrmPluginDocs, _typescript_eslint_utils_ts_eslint3.RuleListener>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _default };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createRule } from "../utils/createRule.js";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
4
|
+
|
|
5
|
+
//#region lib/rules/no-invalid-date-literal.ts
|
|
6
|
+
const { name } = path.parse(import.meta.filename);
|
|
7
|
+
var no_invalid_date_literal_default = createRule({
|
|
8
|
+
name,
|
|
9
|
+
meta: {
|
|
10
|
+
type: "problem",
|
|
11
|
+
docs: {
|
|
12
|
+
description: "Disallow invalid date literals",
|
|
13
|
+
recommended: true
|
|
14
|
+
},
|
|
15
|
+
schema: [],
|
|
16
|
+
messages: { noInvalidDateLiteral: "This results in an invalid date" }
|
|
17
|
+
},
|
|
18
|
+
defaultOptions: [],
|
|
19
|
+
create(context) {
|
|
20
|
+
return {
|
|
21
|
+
NewExpression(node) {
|
|
22
|
+
if (node.callee.type !== AST_NODE_TYPES.Identifier) return;
|
|
23
|
+
if (node.callee.name !== "Date") return;
|
|
24
|
+
if (node.arguments.length > 1) return;
|
|
25
|
+
const [arg] = node.arguments;
|
|
26
|
+
if (!arg) return;
|
|
27
|
+
if (arg.type === AST_NODE_TYPES.Identifier) {
|
|
28
|
+
if (["NaN", "Infinity"].includes(arg.name)) context.report({
|
|
29
|
+
node,
|
|
30
|
+
messageId: "noInvalidDateLiteral"
|
|
31
|
+
});
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (arg.type !== AST_NODE_TYPES.Literal) return;
|
|
35
|
+
if (typeof arg.value === "string" || typeof arg.value === "number") {
|
|
36
|
+
if (isValidDateLiteral(arg.value)) return;
|
|
37
|
+
context.report({
|
|
38
|
+
node,
|
|
39
|
+
messageId: "noInvalidDateLiteral"
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
CallExpression(node) {
|
|
44
|
+
const { callee } = node;
|
|
45
|
+
if (callee.type !== AST_NODE_TYPES.MemberExpression) return;
|
|
46
|
+
if (callee.object.type !== AST_NODE_TYPES.Identifier) return;
|
|
47
|
+
if (callee.property.type !== AST_NODE_TYPES.Identifier) return;
|
|
48
|
+
if (callee.object.name !== "Date") return;
|
|
49
|
+
if (callee.property.name !== "parse") return;
|
|
50
|
+
const [arg] = node.arguments;
|
|
51
|
+
if (!arg) return;
|
|
52
|
+
if (arg.type !== AST_NODE_TYPES.Literal) return;
|
|
53
|
+
if (typeof arg.value === "string") {
|
|
54
|
+
if (isValidDateLiteral(arg.value)) return;
|
|
55
|
+
context.report({
|
|
56
|
+
node,
|
|
57
|
+
messageId: "noInvalidDateLiteral"
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
function isValidDateLiteral(literal) {
|
|
65
|
+
const value = new Date(literal).valueOf();
|
|
66
|
+
return !Number.isNaN(value);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
export { no_invalid_date_literal_default as default };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { WyrmPluginDocs } from "../utils/createRule.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _typescript_eslint_utils_ts_eslint13 from "@typescript-eslint/utils/ts-eslint";
|
|
3
3
|
|
|
4
4
|
//#region lib/rules/no-jsx-statement.d.ts
|
|
5
|
-
declare const _default:
|
|
5
|
+
declare const _default: _typescript_eslint_utils_ts_eslint13.RuleModule<"noJsxExpressionStatement", [], WyrmPluginDocs, _typescript_eslint_utils_ts_eslint13.RuleListener>;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { _default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { WyrmPluginDocs } from "../utils/createRule.js";
|
|
2
|
+
import * as _typescript_eslint_utils_ts_eslint17 from "@typescript-eslint/utils/ts-eslint";
|
|
3
|
+
|
|
4
|
+
//#region lib/rules/no-suspicious-jsx-semicolon.d.ts
|
|
5
|
+
|
|
6
|
+
declare const _default: _typescript_eslint_utils_ts_eslint17.RuleModule<"noSuspiciousJsxSemicolon" | "noSuspiciousJsxComma", [], WyrmPluginDocs, _typescript_eslint_utils_ts_eslint17.RuleListener>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { _default };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createRule } from "../utils/createRule.js";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
//#region lib/rules/no-suspicious-jsx-semicolon.ts
|
|
5
|
+
const { name } = path.parse(import.meta.filename);
|
|
6
|
+
var no_suspicious_jsx_semicolon_default = createRule({
|
|
7
|
+
name,
|
|
8
|
+
meta: {
|
|
9
|
+
type: "problem",
|
|
10
|
+
docs: {
|
|
11
|
+
description: "Forbid suspicious semicolons in JSX",
|
|
12
|
+
recommended: true
|
|
13
|
+
},
|
|
14
|
+
schema: [],
|
|
15
|
+
messages: {
|
|
16
|
+
noSuspiciousJsxSemicolon: "This semicolon looks suspiciously out of place. Did you add it on purpose?",
|
|
17
|
+
noSuspiciousJsxComma: "This comma looks suspiciously out of place. Did you add it on purpose?"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
defaultOptions: [],
|
|
21
|
+
create(context) {
|
|
22
|
+
return { JSXText(node) {
|
|
23
|
+
if (node.value.trim() === ";") {
|
|
24
|
+
context.report({
|
|
25
|
+
node,
|
|
26
|
+
messageId: "noSuspiciousJsxSemicolon"
|
|
27
|
+
});
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (node.value.trimEnd() === ",") context.report({
|
|
31
|
+
node,
|
|
32
|
+
messageId: "noSuspiciousJsxComma"
|
|
33
|
+
});
|
|
34
|
+
} };
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { no_suspicious_jsx_semicolon_default as default };
|