eslint-plugin-wyrm 0.0.10 → 0.0.13
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 +79 -0
- package/README.md +114 -58
- package/bin/wyrm.mjs +3 -0
- package/dist/_virtual/_rolldown/runtime.mjs +14 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +23 -0
- package/dist/configs/index.d.mts +2 -1
- package/dist/configs/index.mjs +6 -6
- package/dist/index.mjs +1 -4
- package/dist/plugin.mjs +1 -3
- package/dist/rules/array-from-array.d.mts +9 -0
- package/dist/rules/array-from-array.mjs +56 -0
- package/dist/rules/as-unknown-as.d.mts +9 -0
- package/dist/rules/as-unknown-as.mjs +30 -0
- package/dist/rules/await-promise-resolve.d.mts +9 -0
- package/dist/rules/await-promise-resolve.mjs +41 -0
- package/dist/rules/boolean-coalescing.d.mts +9 -0
- package/dist/rules/boolean-coalescing.mjs +141 -0
- package/dist/rules/comment-duplicate-leading-space.d.mts +9 -0
- package/dist/rules/comment-duplicate-leading-space.mjs +34 -0
- package/dist/rules/conditional-boolean.d.mts +9 -0
- package/dist/rules/conditional-boolean.mjs +70 -0
- package/dist/rules/constant-boolean-cast.d.mts +9 -0
- package/dist/rules/constant-boolean-cast.mjs +203 -0
- package/dist/rules/de-morgan.d.mts +2 -2
- package/dist/rules/de-morgan.mjs +1 -3
- package/dist/rules/discarded-expression-statement.d.mts +14 -0
- package/dist/rules/discarded-expression-statement.mjs +243 -0
- package/dist/rules/distribute-boolean-casts.d.mts +2 -2
- package/dist/rules/distribute-boolean-casts.mjs +3 -3
- package/dist/rules/duplicate-destructuring.d.mts +2 -2
- package/dist/rules/duplicate-destructuring.mjs +1 -3
- package/dist/rules/duplicate-object-spread.d.mts +9 -0
- package/dist/rules/duplicate-object-spread.mjs +44 -0
- package/dist/rules/e.d.mts +11 -0
- package/dist/rules/e.mjs +87 -0
- package/dist/rules/empty-for.d.mts +9 -0
- package/dist/rules/empty-for.mjs +34 -0
- package/dist/rules/enum-member.d.mts +9 -0
- package/dist/rules/enum-member.mjs +51 -0
- package/dist/rules/eqeq-null.d.mts +9 -0
- package/dist/rules/eqeq-null.mjs +101 -0
- package/dist/rules/exact-string-regex.d.mts +9 -0
- package/dist/rules/exact-string-regex.mjs +83 -0
- package/dist/rules/export-using.d.mts +9 -0
- package/dist/rules/export-using.mjs +58 -0
- package/dist/rules/generic-constructor-with-hook.d.mts +11 -0
- package/dist/rules/generic-constructor-with-hook.mjs +103 -0
- package/dist/rules/idiomatic-cast.mjs +7 -10
- package/dist/rules/index.d.mts +112 -57
- package/dist/rules/index.mjs +113 -5
- package/dist/rules/inferable-type-predicate.d.mts +9 -0
- package/dist/rules/inferable-type-predicate.mjs +100 -0
- package/dist/rules/inner-as-const.d.mts +9 -0
- package/dist/rules/inner-as-const.mjs +70 -0
- package/dist/rules/jsx-tostring.d.mts +9 -0
- package/dist/rules/jsx-tostring.mjs +120 -0
- package/dist/rules/literal-destructuring.d.mts +9 -0
- package/dist/rules/literal-destructuring.mjs +102 -0
- package/dist/rules/named-export-with-side-effects.d.mts +11 -0
- package/dist/rules/named-export-with-side-effects.mjs +72 -0
- package/dist/rules/nested-reduce.d.mts +9 -0
- package/dist/rules/nested-reduce.mjs +46 -0
- package/dist/rules/nested-try-catch.d.mts +9 -0
- package/dist/rules/nested-try-catch.mjs +37 -0
- package/dist/rules/no-commented-out-comment.d.mts +9 -0
- package/dist/rules/no-commented-out-comment.mjs +31 -0
- package/dist/rules/no-constant-template-expression.d.mts +3 -4
- package/dist/rules/no-constant-template-expression.mjs +12 -9
- package/dist/rules/no-constructed-error-cause.d.mts +9 -0
- package/dist/rules/no-constructed-error-cause.mjs +75 -0
- package/dist/rules/no-convoluted-boolean-expressions.d.mts +9 -0
- package/dist/rules/no-convoluted-boolean-expressions.mjs +130 -0
- package/dist/rules/no-convoluted-logical-expressions.d.mts +2 -2
- package/dist/rules/no-convoluted-logical-expressions.mjs +1 -3
- package/dist/rules/no-custom-url-parsing.d.mts +2 -3
- package/dist/rules/no-custom-url-parsing.mjs +1 -3
- package/dist/rules/no-disallowed-warning-comments.d.mts +2 -2
- package/dist/rules/no-disallowed-warning-comments.mjs +1 -3
- package/dist/rules/no-duplicated-return.d.mts +2 -2
- package/dist/rules/no-duplicated-return.mjs +2 -3
- package/dist/rules/no-else-break.d.mts +2 -2
- package/dist/rules/no-else-break.mjs +3 -5
- package/dist/rules/no-else-continue.d.mts +2 -2
- package/dist/rules/no-else-continue.mjs +3 -5
- package/dist/rules/no-else-never.d.mts +9 -0
- package/dist/rules/no-else-never.mjs +75 -0
- package/dist/rules/no-else-return.d.mts +2 -3
- package/dist/rules/no-else-return.mjs +4 -5
- package/dist/rules/no-else-throw.d.mts +2 -2
- package/dist/rules/no-else-throw.mjs +3 -5
- package/dist/rules/no-empty-attribute.d.mts +3 -3
- package/dist/rules/no-empty-attribute.mjs +1 -3
- package/dist/rules/no-empty-comment.d.mts +3 -3
- package/dist/rules/no-empty-comment.mjs +1 -3
- package/dist/rules/no-empty-jsx-expression.d.mts +2 -2
- package/dist/rules/no-empty-jsx-expression.mjs +1 -3
- package/dist/rules/no-empty-literal-iteration.d.mts +2 -2
- package/dist/rules/no-empty-literal-iteration.mjs +1 -3
- package/dist/rules/no-extra-false-fallback.d.mts +2 -3
- package/dist/rules/no-extra-false-fallback.mjs +1 -3
- package/dist/rules/no-extra-nested-boolean-cast.d.mts +2 -3
- package/dist/rules/no-extra-nested-boolean-cast.mjs +2 -3
- package/dist/rules/no-first-last.d.mts +2 -2
- package/dist/rules/no-first-last.mjs +2 -5
- package/dist/rules/no-float-length-check.d.mts +2 -2
- package/dist/rules/no-float-length-check.mjs +1 -3
- package/dist/rules/no-huge-try-block.d.mts +3 -3
- package/dist/rules/no-huge-try-block.mjs +1 -3
- package/dist/rules/no-huge-useeffect.d.mts +11 -0
- package/dist/rules/no-huge-useeffect.mjs +52 -0
- package/dist/rules/no-if-length-for.d.mts +9 -0
- package/dist/rules/no-if-length-for.mjs +91 -0
- package/dist/rules/no-inline-jsdoc-tag.d.mts +3 -3
- package/dist/rules/no-inline-jsdoc-tag.mjs +1 -3
- package/dist/rules/no-invalid-date-literal.d.mts +2 -2
- package/dist/rules/no-invalid-date-literal.mjs +42 -19
- package/dist/rules/no-jsx-statement.d.mts +2 -2
- package/dist/rules/no-jsx-statement.mjs +1 -3
- package/dist/rules/no-lax-array-type.d.mts +9 -0
- package/dist/rules/no-lax-array-type.mjs +129 -0
- package/dist/rules/no-lax-return-type.d.mts +9 -0
- package/dist/rules/no-lax-return-type.mjs +138 -0
- package/dist/rules/no-mutable-literal-fill.d.mts +2 -3
- package/dist/rules/no-mutable-literal-fill.mjs +1 -3
- package/dist/rules/no-nullish-ternary.d.mts +9 -0
- package/dist/rules/no-nullish-ternary.mjs +121 -0
- package/dist/rules/no-numbered-comments.d.mts +2 -2
- package/dist/rules/no-numbered-comments.mjs +1 -3
- package/dist/rules/no-obvious-any.mjs +35 -27
- package/dist/rules/no-optional-type-guard-param.d.mts +2 -3
- package/dist/rules/no-optional-type-guard-param.mjs +1 -3
- package/dist/rules/no-out-of-order-comments.d.mts +2 -2
- package/dist/rules/no-out-of-order-comments.mjs +4 -8
- package/dist/rules/no-possibly-nullish-equality.d.mts +0 -1
- package/dist/rules/no-possibly-nullish-equality.mjs +6 -13
- package/dist/rules/no-redundant-function-declaration.d.mts +2 -2
- package/dist/rules/no-redundant-function-declaration.mjs +1 -3
- package/dist/rules/no-return-to-void.mjs +2 -4
- package/dist/rules/no-self-object-assign.d.mts +2 -2
- package/dist/rules/no-self-object-assign.mjs +1 -3
- package/dist/rules/no-sloppy-length-check.d.mts +2 -3
- package/dist/rules/no-sloppy-length-check.mjs +35 -37
- package/dist/rules/no-suspicious-jsx-semicolon.d.mts +2 -3
- package/dist/rules/no-suspicious-jsx-semicolon.mjs +2 -4
- package/dist/rules/no-ternary-return.d.mts +3 -4
- package/dist/rules/no-ternary-return.mjs +1 -3
- package/dist/rules/no-type-guard.d.mts +9 -0
- package/dist/rules/no-type-guard.mjs +36 -0
- package/dist/rules/no-unassigned-todo.d.mts +2 -2
- package/dist/rules/no-unassigned-todo.mjs +1 -3
- package/dist/rules/no-unbound-catch-error.d.mts +2 -2
- package/dist/rules/no-unbound-catch-error.mjs +1 -3
- package/dist/rules/no-unused-mutually-referential.d.mts +9 -0
- package/dist/rules/no-unused-mutually-referential.mjs +215 -0
- package/dist/rules/no-unused-param-read.d.mts +2 -2
- package/dist/rules/no-unused-param-read.mjs +1 -3
- package/dist/rules/no-useless-computed-key.d.mts +2 -2
- package/dist/rules/no-useless-computed-key.mjs +1 -3
- package/dist/rules/no-useless-iife.d.mts +2 -2
- package/dist/rules/no-useless-iife.mjs +2 -3
- package/dist/rules/no-useless-logical-fallback.d.mts +0 -1
- package/dist/rules/no-useless-logical-fallback.mjs +32 -24
- package/dist/rules/no-useless-return-undefined.mjs +11 -11
- package/dist/rules/no-useless-ts-check.d.mts +9 -0
- package/dist/rules/no-useless-ts-check.mjs +34 -0
- package/dist/rules/no-useless-use-strict.d.mts +2 -2
- package/dist/rules/no-useless-use-strict.mjs +1 -3
- package/dist/rules/no-useless-usememo.d.mts +2 -2
- package/dist/rules/no-useless-usememo.mjs +8 -6
- package/dist/rules/no-whitespace-property.d.mts +2 -2
- package/dist/rules/no-whitespace-property.mjs +1 -3
- package/dist/rules/nullish-object-spread.d.mts +9 -0
- package/dist/rules/nullish-object-spread.mjs +38 -0
- package/dist/rules/optional-call-expression.d.mts +2 -2
- package/dist/rules/optional-call-expression.mjs +20 -3
- package/dist/rules/prefer-array-from.d.mts +9 -0
- package/dist/rules/prefer-array-from.mjs +87 -0
- package/dist/rules/prefer-catch-method.d.mts +2 -2
- package/dist/rules/prefer-catch-method.mjs +9 -12
- package/dist/rules/prefer-early-return.d.mts +2 -2
- package/dist/rules/prefer-early-return.mjs +23 -20
- package/dist/rules/prefer-eqeq-null.d.mts +9 -0
- package/dist/rules/prefer-eqeq-null.mjs +122 -0
- package/dist/rules/prefer-finally.d.mts +9 -0
- package/dist/rules/prefer-finally.mjs +129 -0
- package/dist/rules/prefer-getorinsert.d.mts +9 -0
- package/dist/rules/prefer-getorinsert.mjs +180 -0
- package/dist/rules/prefer-has.d.mts +9 -0
- package/dist/rules/prefer-has.mjs +69 -0
- package/dist/rules/prefer-in.d.mts +9 -0
- package/dist/rules/prefer-in.mjs +81 -0
- package/dist/rules/prefer-object-keys-values.d.mts +9 -0
- package/dist/rules/prefer-object-keys-values.mjs +78 -0
- package/dist/rules/prefer-repeat.d.mts +2 -2
- package/dist/rules/prefer-repeat.mjs +1 -5
- package/dist/rules/prefer-satisfies.d.mts +9 -0
- package/dist/rules/prefer-satisfies.mjs +86 -0
- package/dist/rules/prefer-string-join.d.mts +9 -0
- package/dist/rules/prefer-string-join.mjs +67 -0
- package/dist/rules/primitive-valueof.mjs +6 -8
- package/dist/rules/slim-try.d.mts +9 -0
- package/dist/rules/slim-try.mjs +150 -0
- package/dist/rules/styled-button-has-type.d.mts +9 -0
- package/dist/rules/styled-button-has-type.mjs +82 -0
- package/dist/rules/styled-transient-props.d.mts +9 -0
- package/dist/rules/styled-transient-props.mjs +52 -0
- package/dist/rules/suspicious-map-length.d.mts +2 -2
- package/dist/rules/suspicious-map-length.mjs +1 -3
- package/dist/rules/template-tostring.d.mts +9 -0
- package/dist/rules/template-tostring.mjs +48 -0
- package/dist/rules/unsafe-asserted-chain.d.mts +0 -1
- package/dist/rules/unsafe-asserted-chain.mjs +5 -8
- package/dist/rules/unused-object-assign.d.mts +2 -2
- package/dist/rules/unused-object-assign.mjs +1 -3
- package/dist/rules/unused-object-freeze.d.mts +9 -0
- package/dist/rules/unused-object-freeze.mjs +37 -0
- package/dist/rules/useless-as-const.d.mts +9 -0
- package/dist/rules/useless-as-const.mjs +59 -0
- package/dist/rules/useless-assign.d.mts +11 -0
- package/dist/rules/useless-assign.mjs +69 -0
- package/dist/rules/useless-conditional-assign.d.mts +9 -0
- package/dist/rules/useless-conditional-assign.mjs +58 -0
- package/dist/rules/useless-intermediary-variable.mjs +18 -21
- package/dist/rules/useless-mock.d.mts +9 -0
- package/dist/rules/useless-mock.mjs +180 -0
- package/dist/rules/useless-required.d.mts +9 -0
- package/dist/rules/useless-required.mjs +257 -0
- package/dist/utils/compareTokens.mjs +1 -3
- package/dist/utils/createRule.mjs +1 -3
- package/dist/utils/negateExpression.mjs +1 -3
- package/dist/utils/option.mjs +5 -2
- package/package.json +30 -23
- package/dist/_virtual/rolldown_runtime.mjs +0 -20
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { createRule } from "../utils/createRule.mjs";
|
|
2
|
+
import { None, Some, getFirstOption } from "../utils/option.mjs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
5
|
+
//#region lib/rules/no-nullish-ternary.ts
|
|
6
|
+
const { name } = path.parse(import.meta.filename);
|
|
7
|
+
var no_nullish_ternary_default = createRule({
|
|
8
|
+
name,
|
|
9
|
+
meta: {
|
|
10
|
+
type: "suggestion",
|
|
11
|
+
docs: {
|
|
12
|
+
description: "Forbid ternary conditions that can be replaced by optional chains",
|
|
13
|
+
recommended: true
|
|
14
|
+
},
|
|
15
|
+
fixable: "code",
|
|
16
|
+
schema: [],
|
|
17
|
+
messages: { noNullishTernary: "Replace this ternary condition by optional chaining" }
|
|
18
|
+
},
|
|
19
|
+
defaultOptions: [],
|
|
20
|
+
create(context) {
|
|
21
|
+
return { ConditionalExpression(node) {
|
|
22
|
+
const maybeTestResult = analyzeTest(node.test);
|
|
23
|
+
if (!maybeTestResult.some) return;
|
|
24
|
+
const testResult = maybeTestResult.value;
|
|
25
|
+
switch (testResult.kind) {
|
|
26
|
+
case TestKind.TRUTHY:
|
|
27
|
+
checkTernary(testResult.ident, node.consequent, node.alternate);
|
|
28
|
+
break;
|
|
29
|
+
case TestKind.FALSY:
|
|
30
|
+
checkTernary(testResult.ident, node.alternate, node.consequent);
|
|
31
|
+
break;
|
|
32
|
+
default: {
|
|
33
|
+
const check = testResult.kind;
|
|
34
|
+
console.error(`[wyrm] Unexpected test kind: ${check}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function checkTernary(ident, consequent, alternate) {
|
|
38
|
+
if (!isUndefinedLiteral(alternate)) return;
|
|
39
|
+
if (consequent.type !== AST_NODE_TYPES.MemberExpression) return;
|
|
40
|
+
if (consequent.object.type !== AST_NODE_TYPES.Identifier) return;
|
|
41
|
+
if (consequent.object.name !== ident.name) return;
|
|
42
|
+
context.report({
|
|
43
|
+
node,
|
|
44
|
+
messageId: "noNullishTernary",
|
|
45
|
+
fix(fixer) {
|
|
46
|
+
const objTxt = context.sourceCode.getText(consequent.object);
|
|
47
|
+
const propTxt = context.sourceCode.getText(consequent.property);
|
|
48
|
+
const txt = consequent.computed ? `${objTxt}?.[${propTxt}]` : `${objTxt}?.${propTxt}`;
|
|
49
|
+
return fixer.replaceText(node, txt);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
} };
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
function isUndefinedLiteral(node) {
|
|
57
|
+
return node.type === AST_NODE_TYPES.Identifier && node.name === "undefined";
|
|
58
|
+
}
|
|
59
|
+
var TestKind = /* @__PURE__ */ function(TestKind) {
|
|
60
|
+
TestKind["TRUTHY"] = "TRUTHY";
|
|
61
|
+
TestKind["FALSY"] = "FALSY";
|
|
62
|
+
return TestKind;
|
|
63
|
+
}(TestKind || {});
|
|
64
|
+
function analyzeTest(test) {
|
|
65
|
+
switch (test.type) {
|
|
66
|
+
case AST_NODE_TYPES.Identifier: return Some({
|
|
67
|
+
kind: TestKind.TRUTHY,
|
|
68
|
+
ident: test
|
|
69
|
+
});
|
|
70
|
+
case AST_NODE_TYPES.BinaryExpression: return getFirstOption([analyzeEqualityCheck(test, test.left, test.right), analyzeEqualityCheck(test, test.right, test.left)]);
|
|
71
|
+
case AST_NODE_TYPES.UnaryExpression:
|
|
72
|
+
if (test.operator !== "!") return None;
|
|
73
|
+
if (test.argument.type === AST_NODE_TYPES.Identifier) return Some({
|
|
74
|
+
kind: TestKind.FALSY,
|
|
75
|
+
ident: test.argument
|
|
76
|
+
});
|
|
77
|
+
return None;
|
|
78
|
+
default: return None;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function analyzeEqualityCheck(node, left, right) {
|
|
82
|
+
switch (node.operator) {
|
|
83
|
+
case "!=":
|
|
84
|
+
case "!==": {
|
|
85
|
+
const kind = TestKind.TRUTHY;
|
|
86
|
+
if (left.type === AST_NODE_TYPES.Identifier && right.type === AST_NODE_TYPES.Literal && right.value === null) return Some({
|
|
87
|
+
ident: left,
|
|
88
|
+
kind
|
|
89
|
+
});
|
|
90
|
+
if (left.type === AST_NODE_TYPES.Identifier && right.type === AST_NODE_TYPES.Identifier && right.name === "undefined") return Some({
|
|
91
|
+
ident: left,
|
|
92
|
+
kind
|
|
93
|
+
});
|
|
94
|
+
if (left.type === AST_NODE_TYPES.UnaryExpression && left.operator === "typeof" && right.type === AST_NODE_TYPES.Literal && right.value === "undefined" && left.argument.type === AST_NODE_TYPES.Identifier) return Some({
|
|
95
|
+
ident: left.argument,
|
|
96
|
+
kind
|
|
97
|
+
});
|
|
98
|
+
return None;
|
|
99
|
+
}
|
|
100
|
+
case "==":
|
|
101
|
+
case "===": {
|
|
102
|
+
const kind = TestKind.FALSY;
|
|
103
|
+
if (left.type === AST_NODE_TYPES.Identifier && right.type === AST_NODE_TYPES.Literal && right.value === null) return Some({
|
|
104
|
+
ident: left,
|
|
105
|
+
kind
|
|
106
|
+
});
|
|
107
|
+
if (left.type === AST_NODE_TYPES.Identifier && right.type === AST_NODE_TYPES.Identifier && right.name === "undefined") return Some({
|
|
108
|
+
ident: left,
|
|
109
|
+
kind
|
|
110
|
+
});
|
|
111
|
+
if (left.type === AST_NODE_TYPES.UnaryExpression && left.operator === "typeof" && right.type === AST_NODE_TYPES.Literal && right.value === "undefined" && left.argument.type === AST_NODE_TYPES.Identifier) return Some({
|
|
112
|
+
ident: left.argument,
|
|
113
|
+
kind
|
|
114
|
+
});
|
|
115
|
+
return None;
|
|
116
|
+
}
|
|
117
|
+
default: return None;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
export { no_nullish_ternary_default as default };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { WyrmPluginDocs } from "../utils/createRule.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _$_typescript_eslint_utils_ts_eslint0 from "@typescript-eslint/utils/ts-eslint";
|
|
3
3
|
|
|
4
4
|
//#region lib/rules/no-numbered-comments.d.ts
|
|
5
|
-
declare const _default:
|
|
5
|
+
declare const _default: _$_typescript_eslint_utils_ts_eslint0.RuleModule<"noNumberedComment", [], WyrmPluginDocs, _$_typescript_eslint_utils_ts_eslint0.RuleListener> & {
|
|
6
6
|
name: string;
|
|
7
7
|
};
|
|
8
8
|
//#endregion
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createRule } from "../utils/createRule.mjs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
|
|
4
3
|
//#region lib/rules/no-numbered-comments.ts
|
|
5
4
|
const { name } = path.parse(import.meta.filename);
|
|
6
5
|
var no_numbered_comments_default = createRule({
|
|
@@ -31,6 +30,5 @@ var no_numbered_comments_default = createRule({
|
|
|
31
30
|
function isNumberedComment(comment) {
|
|
32
31
|
return /^\d+\. /u.test(comment.value.trim());
|
|
33
32
|
}
|
|
34
|
-
|
|
35
33
|
//#endregion
|
|
36
|
-
export { no_numbered_comments_default as default };
|
|
34
|
+
export { no_numbered_comments_default as default };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { createRule } from "../utils/createRule.mjs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { ASTUtils, AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
|
|
4
|
-
import * as ts from "typescript";
|
|
5
|
-
|
|
4
|
+
import * as ts$1 from "typescript";
|
|
6
5
|
//#region lib/rules/no-obvious-any.ts
|
|
7
6
|
const { name } = path.parse(import.meta.filename);
|
|
8
7
|
var no_obvious_any_default = createRule({
|
|
@@ -16,7 +15,7 @@ var no_obvious_any_default = createRule({
|
|
|
16
15
|
},
|
|
17
16
|
fixable: "code",
|
|
18
17
|
schema: [],
|
|
19
|
-
messages: { noObviousAny: "Do not use `any` when a stricter type can be trivially inferred
|
|
18
|
+
messages: { noObviousAny: "Do not use `any` when a stricter type can be trivially inferred: {{inferredType}}" }
|
|
20
19
|
},
|
|
21
20
|
defaultOptions: [],
|
|
22
21
|
create(context) {
|
|
@@ -26,14 +25,14 @@ var no_obvious_any_default = createRule({
|
|
|
26
25
|
const scope = context.sourceCode.getScope(stmt.declaration);
|
|
27
26
|
const variable = ASTUtils.findVariable(scope, stmt.declaration);
|
|
28
27
|
if (!variable) return false;
|
|
29
|
-
if (variable.
|
|
28
|
+
if (variable.identifiers.includes(id)) return true;
|
|
30
29
|
}
|
|
31
30
|
if (stmt.type === AST_NODE_TYPES.ExportNamedDeclaration) {
|
|
32
31
|
const scope = context.sourceCode.getScope(stmt);
|
|
33
|
-
return stmt.specifiers.map((specifier) => specifier.
|
|
34
|
-
const variable = ASTUtils.findVariable(scope,
|
|
32
|
+
return stmt.specifiers.map((specifier) => specifier.local).filter((local) => local.type === AST_NODE_TYPES.Identifier).some((local) => {
|
|
33
|
+
const variable = ASTUtils.findVariable(scope, local);
|
|
35
34
|
if (!variable) return false;
|
|
36
|
-
return variable.
|
|
35
|
+
return variable.identifiers.includes(id);
|
|
37
36
|
});
|
|
38
37
|
}
|
|
39
38
|
return false;
|
|
@@ -49,7 +48,7 @@ var no_obvious_any_default = createRule({
|
|
|
49
48
|
if (isFunctionExported(node, id)) return;
|
|
50
49
|
const scope = context.sourceCode.getScope(node);
|
|
51
50
|
const variable = ASTUtils.findVariable(scope, id);
|
|
52
|
-
|
|
51
|
+
/* v8 ignore next -- @preserve */
|
|
53
52
|
if (!variable) return;
|
|
54
53
|
const allArgs = variable.references.map((ref) => ref.identifier.parent).filter((parent) => parent.type === AST_NODE_TYPES.CallExpression).map((parent) => parent.arguments);
|
|
55
54
|
for (const [i, param] of node.params.entries()) {
|
|
@@ -62,6 +61,7 @@ var no_obvious_any_default = createRule({
|
|
|
62
61
|
context.report({
|
|
63
62
|
node: param,
|
|
64
63
|
messageId: "noObviousAny",
|
|
64
|
+
data: { inferredType },
|
|
65
65
|
fix(fixer) {
|
|
66
66
|
return fixer.replaceText(typeAnnotation, inferredType);
|
|
67
67
|
}
|
|
@@ -72,7 +72,7 @@ var no_obvious_any_default = createRule({
|
|
|
72
72
|
const services = ESLintUtils.getParserServices(context);
|
|
73
73
|
const checker = services.program.getTypeChecker();
|
|
74
74
|
const types = args.map((arg) => services.getTypeAtLocation(arg));
|
|
75
|
-
if (types.some((t) => t.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.Never))) return null;
|
|
75
|
+
if (types.some((t) => t.flags & (ts$1.TypeFlags.Any | ts$1.TypeFlags.Unknown | ts$1.TypeFlags.Never))) return null;
|
|
76
76
|
const typesAsStrings = types.map((widened) => checker.getBaseTypeOfLiteralType(widened)).map((widened) => checker.typeToString(widened));
|
|
77
77
|
return [...new Set(typesAsStrings)].join(" | ");
|
|
78
78
|
}
|
|
@@ -83,43 +83,53 @@ var no_obvious_any_default = createRule({
|
|
|
83
83
|
const { typeAnnotation } = node.id.typeAnnotation;
|
|
84
84
|
if (typeAnnotation.type !== AST_NODE_TYPES.TSAnyKeyword) return;
|
|
85
85
|
if (node.init.type === AST_NODE_TYPES.ArrayExpression) {
|
|
86
|
+
const inferredType = "any[]";
|
|
86
87
|
context.report({
|
|
87
88
|
node,
|
|
88
89
|
messageId: "noObviousAny",
|
|
90
|
+
data: { inferredType },
|
|
89
91
|
fix(fixer) {
|
|
90
|
-
return fixer.replaceText(typeAnnotation,
|
|
92
|
+
return fixer.replaceText(typeAnnotation, inferredType);
|
|
91
93
|
}
|
|
92
94
|
});
|
|
93
95
|
return;
|
|
94
96
|
}
|
|
95
97
|
const type = ESLintUtils.getParserServices(context).getTypeAtLocation(node.init);
|
|
96
|
-
if (type.flags & ts.TypeFlags.NumberLike) {
|
|
98
|
+
if (type.flags & ts$1.TypeFlags.NumberLike) {
|
|
99
|
+
const inferredType = "number";
|
|
97
100
|
context.report({
|
|
98
101
|
node,
|
|
99
102
|
messageId: "noObviousAny",
|
|
103
|
+
data: { inferredType },
|
|
100
104
|
fix(fixer) {
|
|
101
|
-
return fixer.replaceText(typeAnnotation,
|
|
105
|
+
return fixer.replaceText(typeAnnotation, inferredType);
|
|
102
106
|
}
|
|
103
107
|
});
|
|
104
108
|
return;
|
|
105
109
|
}
|
|
106
|
-
if (type.flags & ts.TypeFlags.StringLike) {
|
|
110
|
+
if (type.flags & ts$1.TypeFlags.StringLike) {
|
|
111
|
+
const inferredType = "string";
|
|
107
112
|
context.report({
|
|
108
113
|
node,
|
|
109
114
|
messageId: "noObviousAny",
|
|
115
|
+
data: { inferredType },
|
|
110
116
|
fix(fixer) {
|
|
111
|
-
return fixer.replaceText(typeAnnotation,
|
|
117
|
+
return fixer.replaceText(typeAnnotation, inferredType);
|
|
112
118
|
}
|
|
113
119
|
});
|
|
114
120
|
return;
|
|
115
121
|
}
|
|
116
|
-
if (type.flags & ts.TypeFlags.BooleanLike)
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
122
|
+
if (type.flags & ts$1.TypeFlags.BooleanLike) {
|
|
123
|
+
const inferredType = "boolean";
|
|
124
|
+
context.report({
|
|
125
|
+
node,
|
|
126
|
+
messageId: "noObviousAny",
|
|
127
|
+
data: { inferredType },
|
|
128
|
+
fix(fixer) {
|
|
129
|
+
return fixer.replaceText(typeAnnotation, inferredType);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
123
133
|
},
|
|
124
134
|
FunctionDeclaration: checkFunction,
|
|
125
135
|
FunctionExpression: checkFunction,
|
|
@@ -136,13 +146,11 @@ function getFunctionName(node) {
|
|
|
136
146
|
if (node.parent.type !== AST_NODE_TYPES.VariableDeclarator) return null;
|
|
137
147
|
if (node.parent.id.type !== AST_NODE_TYPES.Identifier) return null;
|
|
138
148
|
return node.parent.id;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
console.error(`Unexpected node type: ${
|
|
149
|
+
/* v8 ignore next -- @preserve */
|
|
150
|
+
default:
|
|
151
|
+
console.error(`[wyrm] Unexpected node type: ${nodeType}`);
|
|
142
152
|
return null;
|
|
143
|
-
}
|
|
144
153
|
}
|
|
145
154
|
}
|
|
146
|
-
|
|
147
155
|
//#endregion
|
|
148
|
-
export { no_obvious_any_default as default };
|
|
156
|
+
export { no_obvious_any_default as default };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { WyrmPluginDocs } from "../utils/createRule.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _$_typescript_eslint_utils_ts_eslint0 from "@typescript-eslint/utils/ts-eslint";
|
|
3
3
|
|
|
4
4
|
//#region lib/rules/no-optional-type-guard-param.d.ts
|
|
5
|
-
|
|
6
|
-
declare const _default: _typescript_eslint_utils_ts_eslint49.RuleModule<"optionalTypeGuardParam", [], WyrmPluginDocs, _typescript_eslint_utils_ts_eslint49.RuleListener> & {
|
|
5
|
+
declare const _default: _$_typescript_eslint_utils_ts_eslint0.RuleModule<"optionalTypeGuardParam", [], WyrmPluginDocs, _$_typescript_eslint_utils_ts_eslint0.RuleListener> & {
|
|
7
6
|
name: string;
|
|
8
7
|
};
|
|
9
8
|
//#endregion
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createRule } from "../utils/createRule.mjs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
4
|
-
|
|
5
4
|
//#region lib/rules/no-optional-type-guard-param.ts
|
|
6
5
|
/**
|
|
7
6
|
* @fileoverview
|
|
@@ -67,6 +66,5 @@ var no_optional_type_guard_param_default = createRule({
|
|
|
67
66
|
};
|
|
68
67
|
}
|
|
69
68
|
});
|
|
70
|
-
|
|
71
69
|
//#endregion
|
|
72
|
-
export { no_optional_type_guard_param_default as default };
|
|
70
|
+
export { no_optional_type_guard_param_default as default };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { WyrmPluginDocs } from "../utils/createRule.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _$_typescript_eslint_utils_ts_eslint0 from "@typescript-eslint/utils/ts-eslint";
|
|
3
3
|
|
|
4
4
|
//#region lib/rules/no-out-of-order-comments.d.ts
|
|
5
|
-
declare const _default:
|
|
5
|
+
declare const _default: _$_typescript_eslint_utils_ts_eslint0.RuleModule<"noOutOfOrderComments", [], WyrmPluginDocs, _$_typescript_eslint_utils_ts_eslint0.RuleListener> & {
|
|
6
6
|
name: string;
|
|
7
7
|
};
|
|
8
8
|
//#endregion
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createRule } from "../utils/createRule.mjs";
|
|
2
2
|
import { None, Some } from "../utils/option.mjs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
|
|
5
4
|
//#region lib/rules/no-out-of-order-comments.ts
|
|
6
5
|
const { name } = path.parse(import.meta.filename);
|
|
7
6
|
var no_out_of_order_comments_default = createRule({
|
|
@@ -37,15 +36,12 @@ var no_out_of_order_comments_default = createRule({
|
|
|
37
36
|
}
|
|
38
37
|
});
|
|
39
38
|
function getCommentNumber(comment) {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
const capture =
|
|
43
|
-
/** v8 ignore if -- @preserve */
|
|
44
|
-
if (capture === void 0) return None;
|
|
39
|
+
const plainBulletPointResult = /^(?<number>\d+)\s*[.:)-] /u.exec(comment.value.trim());
|
|
40
|
+
const prefixResult = /^\w+ (?<number>\d+)\s*[.:)-] /u.exec(comment.value.trim());
|
|
41
|
+
const capture = plainBulletPointResult?.groups?.["number"] ?? prefixResult?.groups?.["number"];
|
|
45
42
|
const n = Number(capture);
|
|
46
43
|
if (!Number.isFinite(n)) return None;
|
|
47
44
|
return Some(n);
|
|
48
45
|
}
|
|
49
|
-
|
|
50
46
|
//#endregion
|
|
51
|
-
export { no_out_of_order_comments_default as default };
|
|
47
|
+
export { no_out_of_order_comments_default as default };
|
|
@@ -2,7 +2,6 @@ import { WyrmPluginDocs } from "../utils/createRule.mjs";
|
|
|
2
2
|
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
3
3
|
|
|
4
4
|
//#region lib/rules/no-possibly-nullish-equality.d.ts
|
|
5
|
-
|
|
6
5
|
declare const _default: ESLintUtils.RuleModule<"noPossiblyNullishEquality" | "noPossiblyNullishLooseEquality" | "noConstantNullishComparison", [], WyrmPluginDocs, ESLintUtils.RuleListener> & {
|
|
7
6
|
name: string;
|
|
8
7
|
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { createRule } from "../utils/createRule.mjs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
|
|
4
|
-
import * as ts from "typescript";
|
|
5
|
-
|
|
4
|
+
import * as ts$1 from "typescript";
|
|
6
5
|
//#region lib/rules/no-possibly-nullish-equality.ts
|
|
7
6
|
/**
|
|
8
7
|
* @fileoverview
|
|
@@ -32,7 +31,6 @@ var no_possibly_nullish_equality_default = createRule({
|
|
|
32
31
|
requiresTypeChecking: true,
|
|
33
32
|
strict: true
|
|
34
33
|
},
|
|
35
|
-
fixable: "code",
|
|
36
34
|
schema: [],
|
|
37
35
|
messages: {
|
|
38
36
|
noPossiblyNullishEquality: "You are comparing two values, but if they are both undefined or both null, they will be considered equal. Make sure this is expected.",
|
|
@@ -82,34 +80,29 @@ var no_possibly_nullish_equality_default = createRule({
|
|
|
82
80
|
});
|
|
83
81
|
function isPossiblyNullish(type) {
|
|
84
82
|
if (type.isUnion() && type.types.some((t) => isPossiblyNullish(t))) return true;
|
|
85
|
-
return (type.flags & (ts.TypeFlags.Undefined | ts.TypeFlags.Null)) !== 0;
|
|
83
|
+
return (type.flags & (ts$1.TypeFlags.Undefined | ts$1.TypeFlags.Null)) !== 0;
|
|
86
84
|
}
|
|
87
85
|
function nullishTypesIntersect(a, b) {
|
|
88
86
|
if (isPossiblyNull(a) && !isPossiblyNull(b)) return false;
|
|
89
87
|
if (isPossiblyUndefined(a) && !isPossiblyUndefined(b)) return false;
|
|
90
|
-
/* v8 ignore if -- @preserve */
|
|
91
|
-
if (!isPossiblyNull(a) && isPossiblyNull(b)) return false;
|
|
92
|
-
/* v8 ignore if -- @preserve */
|
|
93
|
-
if (!isPossiblyUndefined(a) && isPossiblyUndefined(b)) return false;
|
|
94
88
|
return true;
|
|
95
89
|
}
|
|
96
90
|
function isPossiblyNull(type) {
|
|
97
91
|
if (type.isUnion() && type.types.some((t) => isPossiblyNull(t))) return true;
|
|
98
|
-
return (type.flags & ts.TypeFlags.Null) !== 0;
|
|
92
|
+
return (type.flags & ts$1.TypeFlags.Null) !== 0;
|
|
99
93
|
}
|
|
100
94
|
function isPossiblyUndefined(type) {
|
|
101
95
|
if (type.isUnion() && type.types.some((t) => isPossiblyUndefined(t))) return true;
|
|
102
|
-
return (type.flags & ts.TypeFlags.Undefined) !== 0;
|
|
96
|
+
return (type.flags & ts$1.TypeFlags.Undefined) !== 0;
|
|
103
97
|
}
|
|
104
98
|
function isConstantNullish(type) {
|
|
105
99
|
if (type.isUnion() && type.types.every((t) => isConstantNullish(t))) return true;
|
|
106
|
-
return (type.flags & (ts.TypeFlags.Undefined | ts.TypeFlags.Null)) !== 0;
|
|
100
|
+
return (type.flags & (ts$1.TypeFlags.Undefined | ts$1.TypeFlags.Null)) !== 0;
|
|
107
101
|
}
|
|
108
102
|
function isIdentifier(node) {
|
|
109
103
|
if (node.type !== AST_NODE_TYPES.Identifier) return false;
|
|
110
104
|
if (node.name === "undefined") return false;
|
|
111
105
|
return true;
|
|
112
106
|
}
|
|
113
|
-
|
|
114
107
|
//#endregion
|
|
115
|
-
export { no_possibly_nullish_equality_default as default };
|
|
108
|
+
export { no_possibly_nullish_equality_default as default };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { WyrmPluginDocs } from "../utils/createRule.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _$_typescript_eslint_utils_ts_eslint0 from "@typescript-eslint/utils/ts-eslint";
|
|
3
3
|
|
|
4
4
|
//#region lib/rules/no-redundant-function-declaration.d.ts
|
|
5
|
-
declare const _default:
|
|
5
|
+
declare const _default: _$_typescript_eslint_utils_ts_eslint0.RuleModule<"noRedundantFunctionDeclaration", [], WyrmPluginDocs, _$_typescript_eslint_utils_ts_eslint0.RuleListener> & {
|
|
6
6
|
name: string;
|
|
7
7
|
};
|
|
8
8
|
//#endregion
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createRule } from "../utils/createRule.mjs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
4
|
-
|
|
5
4
|
//#region lib/rules/no-redundant-function-declaration.ts
|
|
6
5
|
const { name } = path.parse(import.meta.filename);
|
|
7
6
|
var no_redundant_function_declaration_default = createRule({
|
|
@@ -57,6 +56,5 @@ var no_redundant_function_declaration_default = createRule({
|
|
|
57
56
|
} };
|
|
58
57
|
}
|
|
59
58
|
});
|
|
60
|
-
|
|
61
59
|
//#endregion
|
|
62
|
-
export { no_redundant_function_declaration_default as default };
|
|
60
|
+
export { no_redundant_function_declaration_default as default };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createRule } from "../utils/createRule.mjs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
|
|
4
|
-
|
|
5
4
|
//#region lib/rules/no-return-to-void.ts
|
|
6
5
|
const { name } = path.parse(import.meta.filename);
|
|
7
6
|
var no_return_to_void_default = createRule({
|
|
@@ -70,12 +69,12 @@ function getAllReturnStatements(node) {
|
|
|
70
69
|
case AST_NODE_TYPES.ReturnStatement: return [node];
|
|
71
70
|
case AST_NODE_TYPES.BlockStatement: return node.body.flatMap((stmt) => getAllReturnStatements(stmt));
|
|
72
71
|
case AST_NODE_TYPES.IfStatement: return [...getAllReturnStatements(node.consequent), ...getAllReturnStatements(node.alternate)].flat();
|
|
72
|
+
case AST_NODE_TYPES.CatchClause: return getAllReturnStatements(node.body);
|
|
73
73
|
case AST_NODE_TYPES.TryStatement: return [
|
|
74
74
|
...getAllReturnStatements(node.block),
|
|
75
75
|
...getAllReturnStatements(node.handler),
|
|
76
76
|
...getAllReturnStatements(node.finalizer)
|
|
77
77
|
].flat();
|
|
78
|
-
case AST_NODE_TYPES.CatchClause: return getAllReturnStatements(node.body);
|
|
79
78
|
case AST_NODE_TYPES.DoWhileStatement:
|
|
80
79
|
case AST_NODE_TYPES.WhileStatement:
|
|
81
80
|
case AST_NODE_TYPES.ForStatement:
|
|
@@ -91,6 +90,5 @@ function isFunctionExpression(node) {
|
|
|
91
90
|
if (node.type === AST_NODE_TYPES.ArrowFunctionExpression) return true;
|
|
92
91
|
return false;
|
|
93
92
|
}
|
|
94
|
-
|
|
95
93
|
//#endregion
|
|
96
|
-
export { no_return_to_void_default as default };
|
|
94
|
+
export { no_return_to_void_default as default };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { WyrmPluginDocs } from "../utils/createRule.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _$_typescript_eslint_utils_ts_eslint0 from "@typescript-eslint/utils/ts-eslint";
|
|
3
3
|
|
|
4
4
|
//#region lib/rules/no-self-object-assign.d.ts
|
|
5
|
-
declare const _default:
|
|
5
|
+
declare const _default: _$_typescript_eslint_utils_ts_eslint0.RuleModule<"noSelfObjectAssign" | "noDuplicateSources", [], WyrmPluginDocs, _$_typescript_eslint_utils_ts_eslint0.RuleListener> & {
|
|
6
6
|
name: string;
|
|
7
7
|
};
|
|
8
8
|
//#endregion
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createRule } from "../utils/createRule.mjs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
4
|
-
|
|
5
4
|
//#region lib/rules/no-self-object-assign.ts
|
|
6
5
|
const { name } = path.parse(import.meta.filename);
|
|
7
6
|
var no_self_object_assign_default = createRule({
|
|
@@ -51,6 +50,5 @@ function getDuplicateEntries(entries) {
|
|
|
51
50
|
else seen.add(k);
|
|
52
51
|
return duplicates;
|
|
53
52
|
}
|
|
54
|
-
|
|
55
53
|
//#endregion
|
|
56
|
-
export { no_self_object_assign_default as default };
|
|
54
|
+
export { no_self_object_assign_default as default };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { WyrmPluginDocs } from "../utils/createRule.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _$_typescript_eslint_utils_ts_eslint0 from "@typescript-eslint/utils/ts-eslint";
|
|
3
3
|
|
|
4
4
|
//#region lib/rules/no-sloppy-length-check.d.ts
|
|
5
|
-
|
|
6
|
-
declare const _default: _typescript_eslint_utils_ts_eslint57.RuleModule<"noSloppyLengthCheck" | "noRedundantLengthCheck" | "noConstantLengthCheck", [], WyrmPluginDocs, _typescript_eslint_utils_ts_eslint57.RuleListener> & {
|
|
5
|
+
declare const _default: _$_typescript_eslint_utils_ts_eslint0.RuleModule<"noSloppyLengthCheck" | "noRedundantLengthCheck" | "noConstantLengthCheck", [], WyrmPluginDocs, _$_typescript_eslint_utils_ts_eslint0.RuleListener> & {
|
|
7
6
|
name: string;
|
|
8
7
|
};
|
|
9
8
|
//#endregion
|