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,9 @@
|
|
|
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/as-unknown-as.d.ts
|
|
5
|
+
declare const _default: _$_typescript_eslint_utils_ts_eslint0.RuleModule<"noAsUnknownAs", [], WyrmPluginDocs, _$_typescript_eslint_utils_ts_eslint0.RuleListener> & {
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { _default };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createRule } from "../utils/createRule.mjs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
4
|
+
//#region lib/rules/as-unknown-as.ts
|
|
5
|
+
const { name } = path.parse(import.meta.filename);
|
|
6
|
+
var as_unknown_as_default = createRule({
|
|
7
|
+
name,
|
|
8
|
+
meta: {
|
|
9
|
+
type: "suggestion",
|
|
10
|
+
docs: {
|
|
11
|
+
description: "Forbid `as unknown as`",
|
|
12
|
+
strict: true
|
|
13
|
+
},
|
|
14
|
+
schema: [],
|
|
15
|
+
messages: { noAsUnknownAs: "`as unknown as` is unsafe" }
|
|
16
|
+
},
|
|
17
|
+
defaultOptions: [],
|
|
18
|
+
create(context) {
|
|
19
|
+
return { TSAsExpression(node) {
|
|
20
|
+
if (node.parent.type !== AST_NODE_TYPES.TSAsExpression) return;
|
|
21
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES.TSUnknownKeyword) return;
|
|
22
|
+
context.report({
|
|
23
|
+
node,
|
|
24
|
+
messageId: "noAsUnknownAs"
|
|
25
|
+
});
|
|
26
|
+
} };
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
//#endregion
|
|
30
|
+
export { as_unknown_as_default as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
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/await-promise-resolve.d.ts
|
|
5
|
+
declare const _default: _$_typescript_eslint_utils_ts_eslint0.RuleModule<"noAwaitPromiseResolve", [], WyrmPluginDocs, _$_typescript_eslint_utils_ts_eslint0.RuleListener> & {
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { _default };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createRule } from "../utils/createRule.mjs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
4
|
+
//#region lib/rules/await-promise-resolve.ts
|
|
5
|
+
const { name } = path.parse(import.meta.filename);
|
|
6
|
+
var await_promise_resolve_default = createRule({
|
|
7
|
+
name,
|
|
8
|
+
meta: {
|
|
9
|
+
type: "suggestion",
|
|
10
|
+
docs: {
|
|
11
|
+
description: "Forbid `await Promise.resolve()`",
|
|
12
|
+
recommended: true
|
|
13
|
+
},
|
|
14
|
+
fixable: "code",
|
|
15
|
+
schema: [],
|
|
16
|
+
messages: { noAwaitPromiseResolve: "`await Promise.resolve()` is most likely pointless" }
|
|
17
|
+
},
|
|
18
|
+
defaultOptions: [],
|
|
19
|
+
create(context) {
|
|
20
|
+
return { AwaitExpression(node) {
|
|
21
|
+
if (node.argument.type !== AST_NODE_TYPES.CallExpression) return;
|
|
22
|
+
if (node.argument.callee.type !== AST_NODE_TYPES.MemberExpression) return;
|
|
23
|
+
if (node.argument.callee.object.type !== AST_NODE_TYPES.Identifier) return;
|
|
24
|
+
if (node.argument.callee.property.type !== AST_NODE_TYPES.Identifier) return;
|
|
25
|
+
if (node.argument.callee.object.name !== "Promise") return;
|
|
26
|
+
if (node.argument.callee.property.name !== "resolve") return;
|
|
27
|
+
const args = node.argument.arguments;
|
|
28
|
+
context.report({
|
|
29
|
+
node,
|
|
30
|
+
messageId: "noAwaitPromiseResolve",
|
|
31
|
+
fix(fixer) {
|
|
32
|
+
if (args[0]) return fixer.replaceText(node.argument, context.sourceCode.getText(args[0]));
|
|
33
|
+
if (node.parent.type === AST_NODE_TYPES.ExpressionStatement) return fixer.remove(node.parent);
|
|
34
|
+
return fixer.replaceText(node, "undefined");
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
} };
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
//#endregion
|
|
41
|
+
export { await_promise_resolve_default as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WyrmPluginDocs } from "../utils/createRule.mjs";
|
|
2
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
3
|
+
|
|
4
|
+
//#region lib/rules/boolean-coalescing.d.ts
|
|
5
|
+
declare const _default: ESLintUtils.RuleModule<"booleanCoalescing", [], WyrmPluginDocs, ESLintUtils.RuleListener> & {
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { _default };
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { createRule } from "../utils/createRule.mjs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
|
|
4
|
+
import * as ts$1 from "typescript";
|
|
5
|
+
//#region lib/rules/boolean-coalescing.ts
|
|
6
|
+
const { name } = path.parse(import.meta.filename);
|
|
7
|
+
var boolean_coalescing_default = createRule({
|
|
8
|
+
name,
|
|
9
|
+
meta: {
|
|
10
|
+
type: "problem",
|
|
11
|
+
docs: {
|
|
12
|
+
description: "Prefer distributing boolean casts over nullish coalescing expressions",
|
|
13
|
+
strict: true,
|
|
14
|
+
requiresTypeChecking: true
|
|
15
|
+
},
|
|
16
|
+
fixable: "code",
|
|
17
|
+
schema: [],
|
|
18
|
+
messages: { booleanCoalescing: "Distribute boolean casts over this nullish coalescing expression" }
|
|
19
|
+
},
|
|
20
|
+
defaultOptions: [],
|
|
21
|
+
create(context) {
|
|
22
|
+
let services;
|
|
23
|
+
function getServices() {
|
|
24
|
+
services ??= ESLintUtils.getParserServices(context);
|
|
25
|
+
return services;
|
|
26
|
+
}
|
|
27
|
+
return { LogicalExpression(node) {
|
|
28
|
+
if (node.operator !== "??") return;
|
|
29
|
+
if (!(isInSimpleNegation(node) || isInBooleanCast(node) || isInCondition(node) || isReturnedFromPredicate(node))) return;
|
|
30
|
+
if (!isSafeLeftType(getServices().getTypeAtLocation(node.left))) return;
|
|
31
|
+
context.report({
|
|
32
|
+
node,
|
|
33
|
+
messageId: "booleanCoalescing",
|
|
34
|
+
*fix(fixer) {
|
|
35
|
+
const range = [node.left.range[1], node.right.range[0]];
|
|
36
|
+
yield fixer.replaceTextRange(range, " || ");
|
|
37
|
+
const leftText = context.sourceCode.getText(node.left);
|
|
38
|
+
yield fixer.replaceText(node.left, `!!(${leftText})`);
|
|
39
|
+
const rightText = context.sourceCode.getText(node.right);
|
|
40
|
+
yield fixer.replaceText(node.right, `!!(${rightText})`);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
} };
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
function isSafeLeftType(type) {
|
|
47
|
+
if (type.isUnion()) return type.types.every((t) => !isFalsyNotNullish(t));
|
|
48
|
+
return !isFalsyNotNullish(type);
|
|
49
|
+
}
|
|
50
|
+
function isPossiblyFalsy(type) {
|
|
51
|
+
return (type.flags & ts$1.TypeFlags.PossiblyFalsy) !== 0;
|
|
52
|
+
}
|
|
53
|
+
function isNullish(type) {
|
|
54
|
+
return (type.flags & (ts$1.TypeFlags.Null | ts$1.TypeFlags.Undefined)) !== 0;
|
|
55
|
+
}
|
|
56
|
+
function isFalsyNotNullish(type) {
|
|
57
|
+
return isPossiblyFalsy(type) && !isNullish(type);
|
|
58
|
+
}
|
|
59
|
+
function isInBooleanCast(node) {
|
|
60
|
+
/* v8 ignore if -- @preserve */
|
|
61
|
+
if (!node.parent) return false;
|
|
62
|
+
switch (node.parent.type) {
|
|
63
|
+
case AST_NODE_TYPES.LogicalExpression:
|
|
64
|
+
case AST_NODE_TYPES.TSAsExpression:
|
|
65
|
+
case AST_NODE_TYPES.TSNonNullExpression:
|
|
66
|
+
case AST_NODE_TYPES.TSSatisfiesExpression: return isInBooleanCast(node.parent);
|
|
67
|
+
case AST_NODE_TYPES.UnaryExpression: return isDoubleNegation(node.parent);
|
|
68
|
+
case AST_NODE_TYPES.CallExpression: return isBooleanCall(node.parent);
|
|
69
|
+
default: return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function isInSimpleNegation(node) {
|
|
73
|
+
if (!node.parent) return false;
|
|
74
|
+
if (node.parent.type !== AST_NODE_TYPES.UnaryExpression) return false;
|
|
75
|
+
if (node.parent.operator !== "!") return false;
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
function isDoubleNegation(node) {
|
|
79
|
+
if (node.operator !== "!") return false;
|
|
80
|
+
if (node.parent.type !== AST_NODE_TYPES.UnaryExpression) return false;
|
|
81
|
+
if (node.parent.operator !== "!") return false;
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
function isBooleanCall(node) {
|
|
85
|
+
if (node.callee.type !== AST_NODE_TYPES.Identifier) return false;
|
|
86
|
+
if (node.callee.name !== "Boolean") return false;
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
function isInCondition(node) {
|
|
90
|
+
/* v8 ignore if -- @preserve */
|
|
91
|
+
if (!node.parent) return false;
|
|
92
|
+
switch (node.parent.type) {
|
|
93
|
+
case AST_NODE_TYPES.LogicalExpression:
|
|
94
|
+
case AST_NODE_TYPES.TSAsExpression:
|
|
95
|
+
case AST_NODE_TYPES.TSNonNullExpression:
|
|
96
|
+
case AST_NODE_TYPES.TSSatisfiesExpression: return isInCondition(node.parent);
|
|
97
|
+
case AST_NODE_TYPES.IfStatement:
|
|
98
|
+
case AST_NODE_TYPES.ConditionalExpression:
|
|
99
|
+
case AST_NODE_TYPES.DoWhileStatement:
|
|
100
|
+
case AST_NODE_TYPES.WhileStatement: return node === node.parent.test;
|
|
101
|
+
default: return false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function isPredicate(fn) {
|
|
105
|
+
if (fn.parent.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
106
|
+
if (fn.parent.arguments[0] !== fn) return false;
|
|
107
|
+
if (fn.parent.callee.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
108
|
+
if (fn.parent.callee.property.type !== AST_NODE_TYPES.Identifier) return false;
|
|
109
|
+
if (![
|
|
110
|
+
"every",
|
|
111
|
+
"some",
|
|
112
|
+
"filter",
|
|
113
|
+
"find",
|
|
114
|
+
"findIndex",
|
|
115
|
+
"findLast",
|
|
116
|
+
"findLastIndex"
|
|
117
|
+
].includes(fn.parent.callee.property.name)) return false;
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
function isReturnedFromPredicate(node) {
|
|
121
|
+
/* v8 ignore if -- @preserve */
|
|
122
|
+
if (!node.parent) return false;
|
|
123
|
+
switch (node.parent.type) {
|
|
124
|
+
case AST_NODE_TYPES.LogicalExpression:
|
|
125
|
+
case AST_NODE_TYPES.TSAsExpression:
|
|
126
|
+
case AST_NODE_TYPES.TSNonNullExpression:
|
|
127
|
+
case AST_NODE_TYPES.TSSatisfiesExpression:
|
|
128
|
+
case AST_NODE_TYPES.ReturnStatement: return isReturnedFromPredicate(node.parent);
|
|
129
|
+
case AST_NODE_TYPES.BlockStatement:
|
|
130
|
+
if (node.parent.parent.type === AST_NODE_TYPES.FunctionExpression || node.parent.parent.type === AST_NODE_TYPES.ArrowFunctionExpression) return isPredicate(node.parent.parent);
|
|
131
|
+
return false;
|
|
132
|
+
case AST_NODE_TYPES.ArrowFunctionExpression: return isPredicate(node.parent);
|
|
133
|
+
case AST_NODE_TYPES.IfStatement:
|
|
134
|
+
case AST_NODE_TYPES.ConditionalExpression:
|
|
135
|
+
if (node === node.parent.test) return false;
|
|
136
|
+
return isReturnedFromPredicate(node.parent);
|
|
137
|
+
default: return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
//#endregion
|
|
141
|
+
export { boolean_coalescing_default as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
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/comment-duplicate-leading-space.d.ts
|
|
5
|
+
declare const _default: _$_typescript_eslint_utils_ts_eslint0.RuleModule<"duplicateSpace", [], WyrmPluginDocs, _$_typescript_eslint_utils_ts_eslint0.RuleListener> & {
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { _default };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createRule } from "../utils/createRule.mjs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
//#region lib/rules/comment-duplicate-leading-space.ts
|
|
4
|
+
const { name } = path.parse(import.meta.filename);
|
|
5
|
+
var comment_duplicate_leading_space_default = createRule({
|
|
6
|
+
name,
|
|
7
|
+
meta: {
|
|
8
|
+
type: "suggestion",
|
|
9
|
+
docs: {
|
|
10
|
+
description: "Forbid duplicate leading space in comments",
|
|
11
|
+
recommended: true
|
|
12
|
+
},
|
|
13
|
+
fixable: "code",
|
|
14
|
+
schema: [],
|
|
15
|
+
messages: { duplicateSpace: "Remove this duplicate leading space" }
|
|
16
|
+
},
|
|
17
|
+
defaultOptions: [],
|
|
18
|
+
create(context) {
|
|
19
|
+
if (typeof context.sourceCode.getAllComments === "undefined") return {};
|
|
20
|
+
const comments = context.sourceCode.getAllComments();
|
|
21
|
+
for (const comment of comments) if (/^ {2}\w/u.test(comment.value)) context.report({
|
|
22
|
+
node: comment,
|
|
23
|
+
messageId: "duplicateSpace",
|
|
24
|
+
fix(fixer) {
|
|
25
|
+
const start = comment.range[0];
|
|
26
|
+
const range = [start + 2, start + 3];
|
|
27
|
+
return fixer.removeRange(range);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
//#endregion
|
|
34
|
+
export { comment_duplicate_leading_space_default as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
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/conditional-boolean.d.ts
|
|
5
|
+
declare const _default: _$_typescript_eslint_utils_ts_eslint0.RuleModule<"noConditionalBoolean", [], WyrmPluginDocs, _$_typescript_eslint_utils_ts_eslint0.RuleListener> & {
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { _default };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createRule } from "../utils/createRule.mjs";
|
|
2
|
+
import { areTokensEqual } from "../utils/compareTokens.mjs";
|
|
3
|
+
import { None, Option, Some } from "../utils/option.mjs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { AST_NODE_TYPES, AST_TOKEN_TYPES } from "@typescript-eslint/utils";
|
|
6
|
+
//#region lib/rules/conditional-boolean.ts
|
|
7
|
+
const { name } = path.parse(import.meta.filename);
|
|
8
|
+
var conditional_boolean_default = createRule({
|
|
9
|
+
name,
|
|
10
|
+
meta: {
|
|
11
|
+
type: "suggestion",
|
|
12
|
+
docs: {
|
|
13
|
+
description: "Forbid if/else branches where the only difference is a boolean literal",
|
|
14
|
+
recommended: true
|
|
15
|
+
},
|
|
16
|
+
fixable: "code",
|
|
17
|
+
schema: [],
|
|
18
|
+
messages: { noConditionalBoolean: "Collapse this condition to a single statement by using the test as a boolean" }
|
|
19
|
+
},
|
|
20
|
+
defaultOptions: [],
|
|
21
|
+
create(context) {
|
|
22
|
+
return { IfStatement(node) {
|
|
23
|
+
const { consequent, alternate } = node;
|
|
24
|
+
if (!alternate) return;
|
|
25
|
+
const maybeConsequentStmt = getUniqueStatement(consequent);
|
|
26
|
+
if (!maybeConsequentStmt.some) return;
|
|
27
|
+
const consequentStmt = maybeConsequentStmt.value;
|
|
28
|
+
const maybeAlternateStmt = getUniqueStatement(alternate);
|
|
29
|
+
if (!maybeAlternateStmt.some) return;
|
|
30
|
+
const alternateStmt = maybeAlternateStmt.value;
|
|
31
|
+
const consequentTokens = context.sourceCode.getTokens(consequentStmt);
|
|
32
|
+
const alternateTokens = context.sourceCode.getTokens(alternateStmt);
|
|
33
|
+
if (consequentTokens.length !== alternateTokens.length) return;
|
|
34
|
+
const booleanTokens = /* @__PURE__ */ new Set();
|
|
35
|
+
for (const [i, consequentTok] of consequentTokens.entries()) {
|
|
36
|
+
const alternateTok = alternateTokens[i];
|
|
37
|
+
if (!alternateTok) return;
|
|
38
|
+
if (consequentTok.type !== alternateTok.type) return;
|
|
39
|
+
if (consequentTok.type === AST_TOKEN_TYPES.Boolean && alternateTok.type === AST_TOKEN_TYPES.Boolean && consequentTok.value !== alternateTok.value) {
|
|
40
|
+
booleanTokens.add(consequentTok);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (!areTokensEqual(consequentTok, alternateTok)) return;
|
|
44
|
+
}
|
|
45
|
+
if (!booleanTokens.size) return;
|
|
46
|
+
context.report({
|
|
47
|
+
node,
|
|
48
|
+
messageId: "noConditionalBoolean",
|
|
49
|
+
*fix(fixer) {
|
|
50
|
+
const testTxt = context.sourceCode.getText(node.test);
|
|
51
|
+
for (const tok of booleanTokens) {
|
|
52
|
+
const replacement = tok.value === "true" ? `!!(${testTxt})` : `!(${testTxt})`;
|
|
53
|
+
yield fixer.replaceTextRange(tok.range, replacement);
|
|
54
|
+
}
|
|
55
|
+
const ifRange = [node.range[0], consequentStmt.range[0]];
|
|
56
|
+
yield fixer.removeRange(ifRange);
|
|
57
|
+
const elseRange = [consequentStmt.range[1], node.range[1]];
|
|
58
|
+
yield fixer.removeRange(elseRange);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
} };
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
function getUniqueStatement(stmt) {
|
|
65
|
+
if (stmt.type !== AST_NODE_TYPES.BlockStatement) return Some(stmt);
|
|
66
|
+
if (stmt.body.length !== 1) return None;
|
|
67
|
+
return Option.fromUndef(stmt.body[0]);
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { conditional_boolean_default as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WyrmPluginDocs } from "../utils/createRule.mjs";
|
|
2
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
3
|
+
|
|
4
|
+
//#region lib/rules/constant-boolean-cast.d.ts
|
|
5
|
+
declare const _default: ESLintUtils.RuleModule<"alwaysFalsy" | "alwaysTruthy" | "truthyPredicate" | "falsyPredicate" | "useFalse" | "useTrue", [], WyrmPluginDocs, ESLintUtils.RuleListener> & {
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { _default };
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { createRule } from "../utils/createRule.mjs";
|
|
2
|
+
import { None, Option, Some } from "../utils/option.mjs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
|
|
5
|
+
import ts from "typescript";
|
|
6
|
+
//#region lib/rules/constant-boolean-cast.ts
|
|
7
|
+
/**
|
|
8
|
+
* @fileoverview
|
|
9
|
+
*
|
|
10
|
+
* This rule only makes sense if you have `strictNullChecks` enabled in your `tsconfig.json` (this is the default for `strict: true`).
|
|
11
|
+
*/
|
|
12
|
+
const { name } = path.parse(import.meta.filename);
|
|
13
|
+
var constant_boolean_cast_default = createRule({
|
|
14
|
+
name,
|
|
15
|
+
meta: {
|
|
16
|
+
type: "suggestion",
|
|
17
|
+
docs: {
|
|
18
|
+
description: "Forbid boolean casts on values with constant truthiness",
|
|
19
|
+
recommended: true,
|
|
20
|
+
requiresTypeChecking: true
|
|
21
|
+
},
|
|
22
|
+
hasSuggestions: true,
|
|
23
|
+
schema: [],
|
|
24
|
+
messages: {
|
|
25
|
+
alwaysFalsy: "This value will always be false",
|
|
26
|
+
alwaysTruthy: "This value will always be true",
|
|
27
|
+
truthyPredicate: "This always returns a truthy value",
|
|
28
|
+
falsyPredicate: "This always returns a falsy value",
|
|
29
|
+
useFalse: "Replace by `false`",
|
|
30
|
+
useTrue: "Replace by `true`"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
defaultOptions: [],
|
|
34
|
+
create(context) {
|
|
35
|
+
let services;
|
|
36
|
+
function getServices() {
|
|
37
|
+
services ??= ESLintUtils.getParserServices(context);
|
|
38
|
+
return services;
|
|
39
|
+
}
|
|
40
|
+
let checker;
|
|
41
|
+
function getChecker() {
|
|
42
|
+
checker ??= getServices().program.getTypeChecker();
|
|
43
|
+
return checker;
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
UnaryExpression(node) {
|
|
47
|
+
if (isDoubleNegation(node)) {
|
|
48
|
+
checkConstantTruthiness(node.parent, node.argument);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (node.operator !== "!") return;
|
|
52
|
+
if (node.argument.type === AST_NODE_TYPES.UnaryExpression && node.argument.operator === "!") return;
|
|
53
|
+
checkConstantTruthiness(node, node.argument, true);
|
|
54
|
+
},
|
|
55
|
+
CallExpression(node) {
|
|
56
|
+
if (!isBooleanCall(node)) return;
|
|
57
|
+
const [arg] = node.arguments;
|
|
58
|
+
if (!arg) return;
|
|
59
|
+
checkConstantTruthiness(node, arg);
|
|
60
|
+
},
|
|
61
|
+
ArrowFunctionExpression: checkFunctionExpression,
|
|
62
|
+
FunctionExpression: checkFunctionExpression
|
|
63
|
+
};
|
|
64
|
+
function checkFunctionExpression(fn) {
|
|
65
|
+
if (!isPredicate(fn)) return;
|
|
66
|
+
const maybeReturnValue = getReturnValue(fn.body);
|
|
67
|
+
if (!maybeReturnValue.some) {
|
|
68
|
+
const stmts = getAllReturnStatements(fn.body);
|
|
69
|
+
if (!stmts.length) return;
|
|
70
|
+
const returnValues = stmts.map((stmt) => stmt.argument);
|
|
71
|
+
if (returnValues.every((val) => {
|
|
72
|
+
if (!val) return false;
|
|
73
|
+
return isTypeAlwaysTruthy(getServices().getTypeAtLocation(val));
|
|
74
|
+
})) {
|
|
75
|
+
context.report({
|
|
76
|
+
node: fn,
|
|
77
|
+
messageId: "truthyPredicate"
|
|
78
|
+
});
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (returnValues.every((val) => {
|
|
82
|
+
if (!val) return true;
|
|
83
|
+
return isTypeAlwaysFalsy(getServices().getTypeAtLocation(val));
|
|
84
|
+
})) context.report({
|
|
85
|
+
node: fn,
|
|
86
|
+
messageId: "falsyPredicate"
|
|
87
|
+
});
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const returnValue = maybeReturnValue.value;
|
|
91
|
+
if (isSimpleNegation(returnValue)) return;
|
|
92
|
+
checkConstantTruthiness(returnValue, returnValue);
|
|
93
|
+
}
|
|
94
|
+
function checkConstantTruthiness(node, value, negated = false) {
|
|
95
|
+
const type = getServices().getTypeAtLocation(value);
|
|
96
|
+
const alwaysFalsy = isTypeAlwaysFalsy(type);
|
|
97
|
+
const alwaysTruthy = isTypeAlwaysTruthy(type);
|
|
98
|
+
const nodeText = context.sourceCode.getText(node);
|
|
99
|
+
if (alwaysFalsy && !negated || alwaysTruthy && negated) context.report({
|
|
100
|
+
node,
|
|
101
|
+
messageId: "alwaysFalsy",
|
|
102
|
+
suggest: nodeText === "false" ? [] : [{
|
|
103
|
+
messageId: "useFalse",
|
|
104
|
+
fix(fixer) {
|
|
105
|
+
return fixer.replaceText(node, "false");
|
|
106
|
+
}
|
|
107
|
+
}]
|
|
108
|
+
});
|
|
109
|
+
if (alwaysTruthy && !negated || alwaysFalsy && negated) context.report({
|
|
110
|
+
node,
|
|
111
|
+
messageId: "alwaysTruthy",
|
|
112
|
+
suggest: nodeText === "true" ? [] : [{
|
|
113
|
+
messageId: "useTrue",
|
|
114
|
+
fix(fixer) {
|
|
115
|
+
return fixer.replaceText(node, "true");
|
|
116
|
+
}
|
|
117
|
+
}]
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
function isTypeAlwaysFalsy(type) {
|
|
121
|
+
if (type.isUnionOrIntersection()) return type.types.every((t) => isTypeAlwaysFalsy(t));
|
|
122
|
+
const flags = ts.TypeFlags.Undefined | ts.TypeFlags.Null | ts.TypeFlags.Void;
|
|
123
|
+
if ((type.getFlags() & flags) !== 0) return true;
|
|
124
|
+
if (type.isStringLiteral() || type.isNumberLiteral()) return !type.value;
|
|
125
|
+
if (type.isLiteral() && typeof type.value === "object") return type.value.base10Value === "0";
|
|
126
|
+
if (type.getFlags() & ts.TypeFlags.BooleanLiteral) return type !== getChecker().getTrueType();
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
function isTypeAlwaysTruthy(type) {
|
|
130
|
+
if (type.isUnionOrIntersection()) return type.types.every((t) => isTypeAlwaysTruthy(t));
|
|
131
|
+
const flags = ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.Never;
|
|
132
|
+
if ((type.getFlags() & flags) !== 0) return false;
|
|
133
|
+
if ((type.getFlags() & ts.TypeFlags.PossiblyFalsy) === 0) return true;
|
|
134
|
+
if (type.isStringLiteral() || type.isNumberLiteral()) return !!type.value;
|
|
135
|
+
if (type.isLiteral() && typeof type.value === "object") return type.value.base10Value !== "0";
|
|
136
|
+
if (type.getFlags() & ts.TypeFlags.BooleanLiteral) return type !== getChecker().getFalseType();
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
function isSimpleNegation(node) {
|
|
142
|
+
if (node.type !== AST_NODE_TYPES.UnaryExpression) return false;
|
|
143
|
+
if (node.operator !== "!") return false;
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
function isDoubleNegation(node) {
|
|
147
|
+
if (node.operator !== "!") return false;
|
|
148
|
+
if (!isSimpleNegation(node.parent)) return false;
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
function isBooleanCall(node) {
|
|
152
|
+
if (node.callee.type !== AST_NODE_TYPES.Identifier) return false;
|
|
153
|
+
if (node.callee.name !== "Boolean") return false;
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
function getReturnValue(body) {
|
|
157
|
+
if (body.type !== AST_NODE_TYPES.BlockStatement) return Some(body);
|
|
158
|
+
if (body.body.length !== 1) return None;
|
|
159
|
+
const returnStatement = body.body.find((stmt) => stmt.type === AST_NODE_TYPES.ReturnStatement);
|
|
160
|
+
if (!returnStatement) return None;
|
|
161
|
+
if (!returnStatement.argument) return None;
|
|
162
|
+
return Option.fromUndef(returnStatement.argument);
|
|
163
|
+
}
|
|
164
|
+
function isPredicate(fn) {
|
|
165
|
+
if (fn.parent.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
166
|
+
if (fn.parent.arguments[0] !== fn) return false;
|
|
167
|
+
if (fn.parent.callee.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
168
|
+
if (fn.parent.callee.property.type !== AST_NODE_TYPES.Identifier) return false;
|
|
169
|
+
if (![
|
|
170
|
+
"every",
|
|
171
|
+
"some",
|
|
172
|
+
"filter",
|
|
173
|
+
"find",
|
|
174
|
+
"findIndex",
|
|
175
|
+
"findLast",
|
|
176
|
+
"findLastIndex"
|
|
177
|
+
].includes(fn.parent.callee.property.name)) return false;
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
function getAllReturnStatements(node) {
|
|
181
|
+
if (!node) return [];
|
|
182
|
+
switch (node.type) {
|
|
183
|
+
case AST_NODE_TYPES.ReturnStatement: return [node];
|
|
184
|
+
case AST_NODE_TYPES.BlockStatement: return node.body.flatMap((stmt) => getAllReturnStatements(stmt));
|
|
185
|
+
case AST_NODE_TYPES.IfStatement: return [...getAllReturnStatements(node.consequent), ...getAllReturnStatements(node.alternate)].flat();
|
|
186
|
+
case AST_NODE_TYPES.CatchClause: return getAllReturnStatements(node.body);
|
|
187
|
+
case AST_NODE_TYPES.TryStatement: return [
|
|
188
|
+
...getAllReturnStatements(node.block),
|
|
189
|
+
...getAllReturnStatements(node.handler),
|
|
190
|
+
...getAllReturnStatements(node.finalizer)
|
|
191
|
+
].flat();
|
|
192
|
+
case AST_NODE_TYPES.DoWhileStatement:
|
|
193
|
+
case AST_NODE_TYPES.WhileStatement:
|
|
194
|
+
case AST_NODE_TYPES.ForStatement:
|
|
195
|
+
case AST_NODE_TYPES.ForInStatement:
|
|
196
|
+
case AST_NODE_TYPES.ForOfStatement: return getAllReturnStatements(node.body);
|
|
197
|
+
case AST_NODE_TYPES.SwitchCase: return node.consequent.flatMap((stmt) => getAllReturnStatements(stmt));
|
|
198
|
+
case AST_NODE_TYPES.SwitchStatement: return node.cases.flatMap((c) => getAllReturnStatements(c));
|
|
199
|
+
default: return [];
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
//#endregion
|
|
203
|
+
export { constant_boolean_cast_default as default };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { WyrmPluginDocs } from "../utils/createRule.mjs";
|
|
2
|
-
import * as _typescript_eslint_utils_ts_eslint0 from "@typescript-eslint/utils/ts-eslint";
|
|
2
|
+
import * as _$_typescript_eslint_utils_ts_eslint0 from "@typescript-eslint/utils/ts-eslint";
|
|
3
3
|
|
|
4
4
|
//#region lib/rules/de-morgan.d.ts
|
|
5
|
-
declare const _default: _typescript_eslint_utils_ts_eslint0.RuleModule<"deMorgan", [], WyrmPluginDocs, _typescript_eslint_utils_ts_eslint0.RuleListener> & {
|
|
5
|
+
declare const _default: _$_typescript_eslint_utils_ts_eslint0.RuleModule<"deMorgan", [], WyrmPluginDocs, _$_typescript_eslint_utils_ts_eslint0.RuleListener> & {
|
|
6
6
|
name: string;
|
|
7
7
|
};
|
|
8
8
|
//#endregion
|
package/dist/rules/de-morgan.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import { createRule } from "../utils/createRule.mjs";
|
|
|
2
2
|
import { isNegatableOperator, negateExpression } from "../utils/negateExpression.mjs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
5
|
-
|
|
6
5
|
//#region lib/rules/de-morgan.ts
|
|
7
6
|
const { name } = path.parse(import.meta.filename);
|
|
8
7
|
var de_morgan_default = createRule({
|
|
@@ -47,6 +46,5 @@ var de_morgan_default = createRule({
|
|
|
47
46
|
} };
|
|
48
47
|
}
|
|
49
48
|
});
|
|
50
|
-
|
|
51
49
|
//#endregion
|
|
52
|
-
export { de_morgan_default as default };
|
|
50
|
+
export { de_morgan_default as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { WyrmPluginDocs } from "../utils/createRule.mjs";
|
|
2
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
3
|
+
|
|
4
|
+
//#region lib/rules/discarded-expression-statement.d.ts
|
|
5
|
+
declare const _default: ESLintUtils.RuleModule<"unusedExpression", [{
|
|
6
|
+
ignorePromises: boolean;
|
|
7
|
+
ignoredFunctions: string[];
|
|
8
|
+
ignoredObjects: string[];
|
|
9
|
+
ignoredMethods: string[];
|
|
10
|
+
}], WyrmPluginDocs, ESLintUtils.RuleListener> & {
|
|
11
|
+
name: string;
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { _default };
|