@sshkeda/check 0.0.0-stage → 1.0.0
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/LICENSE +21 -0
- package/README.md +156 -2
- package/docs/how-to-make-check-pass.md +71 -0
- package/package.json +51 -4
- package/src/index.ts +8 -0
- package/src/internal/ban-abbreviated-words-in-declared-names.ts +165 -0
- package/src/internal/ban-checked-members-outside-calls.ts +151 -0
- package/src/internal/ban-comments.ts +23 -0
- package/src/internal/ban-comparing-or-switching-on-tag.ts +114 -0
- package/src/internal/ban-deadlines-inside-tests.ts +41 -0
- package/src/internal/ban-declared-values.ts +70 -0
- package/src/internal/ban-dropped-failures-detached-fibers-sleeps-and-untraced-functions.ts +67 -0
- package/src/internal/ban-failures-collected-as-results.ts +57 -0
- package/src/internal/ban-fallbacks-of-named-recoveries.ts +118 -0
- package/src/internal/ban-function-overloads.ts +107 -0
- package/src/internal/ban-global-error-in-failure-types.ts +146 -0
- package/src/internal/ban-instanceof-in-effect-recovery-callbacks.ts +63 -0
- package/src/internal/ban-let-and-effect-mutable-ref.ts +79 -0
- package/src/internal/ban-logic-in-index-files.ts +178 -0
- package/src/internal/ban-namespaces-used-without-a-member.ts +176 -0
- package/src/internal/ban-node-builtins-that-effect-replaces.ts +42 -0
- package/src/internal/ban-parsing-outside-data-without-a-schema.ts +299 -0
- package/src/internal/ban-re-exports.ts +172 -0
- package/src/internal/ban-reading-the-clock-and-sleeping-outside-effect.ts +239 -0
- package/src/internal/ban-retired-words-in-names.ts +49 -0
- package/src/internal/ban-scanning-directories-with-bun-glob.ts +79 -0
- package/src/internal/ban-shebang-lines.ts +26 -0
- package/src/internal/ban-timer-globals-and-the-global-object.ts +34 -0
- package/src/internal/ban-timer-schedules-without-deadlines.ts +240 -0
- package/src/internal/ban-type-and-interface-declarations.ts +48 -0
- package/src/internal/ban-type-predicates.ts +82 -0
- package/src/internal/ban-unknown-in-function-signatures.ts +143 -0
- package/src/internal/ban-vague-error-class-names.ts +28 -0
- package/src/internal/ban-vague-file-names.ts +51 -0
- package/src/internal/ban-what-a-file-is-not-granted.ts +512 -0
- package/src/internal/ban-while-do-while-and-for-loops.ts +27 -0
- package/src/internal/confine-service-declarations-to-granted-files.ts +116 -0
- package/src/internal/confine-the-stdio-service-to-terminal-output.ts +190 -0
- package/src/internal/define-the-lint-plugin-and-configs.ts +361 -0
- package/src/internal/describe-and-decode-rule-options.ts +22 -0
- package/src/internal/keep-assertions-in-the-test-home-and-ban-test-runners.ts +128 -0
- package/src/internal/keep-effect-testing-helpers-in-test-files.ts +157 -0
- package/src/internal/match-banned-modules-and-globals.ts +71 -0
- package/src/internal/match-effect-service-factories.ts +20 -0
- package/src/internal/require-a-named-const-for-compound-conditions.ts +44 -0
- package/src/internal/require-capital-snake-case-and-as-const-on-literal-constants.ts +141 -0
- package/src/internal/require-service-keys-to-end-with-their-class-name.ts +64 -0
- package/src/internal/resolve-what-an-expression-imports.ts +295 -0
- package/src/internal/sort-type-constituents.ts +82 -0
- package/src/internal/split-names-into-words.ts +12 -0
- package/src/internal/visit-every-declared-name.ts +264 -0
- package/src/lib/tasks/index.ts +1 -0
- package/src/lib/tasks/internal/declare-the-check-task.ts +29 -0
- package/src/lib/tasks/internal/declare-the-checker-queries-task.ts +41 -0
- package/src/lib/tasks/internal/declare-the-typed-checks-task.ts +25 -0
- package/src/lib/tasks/internal/run-checks-over-one-typescript-project.ts +68 -0
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/index.ts +15 -0
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/check-effect-diagnostics-with-effect-tsgo.ts +211 -0
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/read-effect-tsgo-json-report.ts +39 -0
- package/src/lib/tasks/lib/check-import-boundaries/index.ts +1 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/find-import-boundary-violations.ts +415 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/find-subpath-import-targets.ts +117 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/find-what-hides-an-import.ts +65 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/import-boundary-errors.ts +176 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/index.ts +1 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/declared-use-errors.ts +32 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/find-declared-use-violations.ts +38 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/find-sync-calls.ts +23 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/find-type-only-schemas.ts +375 -0
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/index.ts +1 -0
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/find-layer-provides-outside-program-starts.ts +648 -0
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/layer-provide-errors.ts +27 -0
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/resolve-imported-package-apis.ts +262 -0
- package/src/lib/tasks/lib/confine-stdio-to-granted-files/index.ts +1 -0
- package/src/lib/tasks/lib/confine-stdio-to-granted-files/internal/find-ungranted-stdio-uses.ts +219 -0
- package/src/lib/tasks/lib/confine-stdio-to-granted-files/internal/stdio-use-errors.ts +31 -0
- package/src/lib/tasks/lib/detect-inferrable-annotations/index.ts +1 -0
- package/src/lib/tasks/lib/detect-inferrable-annotations/internal/find-inferrable-annotations.ts +357 -0
- package/src/lib/tasks/lib/detect-inferrable-annotations/internal/inferrable-annotation-errors.ts +33 -0
- package/src/lib/tasks/lib/detect-repeated-service-yields/index.ts +1 -0
- package/src/lib/tasks/lib/detect-repeated-service-yields/internal/find-repeated-service-yields.ts +162 -0
- package/src/lib/tasks/lib/detect-repeated-service-yields/internal/repeated-service-yield-errors.ts +25 -0
- package/src/lib/tasks/lib/enforce-file-layout/index.ts +5 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/check-the-layout-of-each-package.ts +9 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/file-layout-errors.ts +417 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-export-path-mismatches.ts +83 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +827 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-module-layout-violations.ts +82 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/resolve-task-imports.ts +178 -0
- package/src/lib/tasks/lib/enforce-file-types/index.ts +5 -0
- package/src/lib/tasks/lib/enforce-file-types/internal/file-type-errors.ts +21 -0
- package/src/lib/tasks/lib/enforce-file-types/internal/find-file-type-violations.ts +78 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/index.ts +1 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/check-formatting-with-bun-fmt.ts +157 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/declare-the-formatting-task.ts +66 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/find-format-config-violations.ts +16 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/find-format-input-violations.ts +74 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/find-symbolic-links.ts +14 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/unformatted-file-errors.ts +12 -0
- package/src/lib/tasks/lib/judge-index-re-exports/index.ts +1 -0
- package/src/lib/tasks/lib/judge-index-re-exports/internal/find-index-re-export-violations.ts +353 -0
- package/src/lib/tasks/lib/judge-index-re-exports/internal/index-re-export-errors.ts +21 -0
- package/src/lib/tasks/lib/lint-with-oxlint/index.ts +15 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/check-lint-rules-with-oxlint.ts +123 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/check-unsafe-enum-assignments.ts +152 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/find-tsgolint-executable.ts +21 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/read-oxlint-json-report.ts +82 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/read-tsgolint-rule-messages.ts +68 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/index.ts +1 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/export-placement-errors.ts +135 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-export-placement-violations.ts +507 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-misplaced-files.ts +116 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-subdivided-directories.ts +29 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-the-importer-graph.ts +451 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/list-binding-names.ts +49 -0
- package/src/lib/tasks/lib/refuse-disable-directives/index.ts +15 -0
- package/src/lib/tasks/lib/refuse-disable-directives/internal/disable-directive-errors.ts +45 -0
- package/src/lib/tasks/lib/refuse-disable-directives/internal/find-disable-directives.ts +66 -0
- package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/index.ts +1 -0
- package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/internal/error-mapping-errors.ts +21 -0
- package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/internal/find-error-mappings-to-done.ts +135 -0
- package/src/lib/tasks/lib/require-separate-service-layers/index.ts +1 -0
- package/src/lib/tasks/lib/require-separate-service-layers/internal/find-service-layer-violations.ts +170 -0
- package/src/lib/tasks/lib/require-separate-service-layers/internal/service-layer-errors.ts +21 -0
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/index.ts +14 -0
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/find-linted-files-not-type-checked.ts +117 -0
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/linted-file-errors.ts +51 -0
- package/src/lib/tasks/lib/type-check-with-bun-check/index.ts +11 -0
- package/src/lib/tasks/lib/type-check-with-bun-check/internal/check-types-with-bun-check.ts +54 -0
- package/src/lib/tasks/lib/type-check-with-bun-check/internal/read-bun-check-output.ts +73 -0
- package/src/lib/tasks/lib/type-check-with-bun-check/internal/type-check-errors.ts +10 -0
- package/src/lib/tasks/shared/check-each-nested-package.ts +79 -0
- package/src/lib/tasks/shared/classify-files-by-role.ts +115 -0
- package/src/lib/tasks/shared/count-the-line-of-an-offset.ts +2 -0
- package/src/lib/tasks/shared/create-the-module-resolver.ts +38 -0
- package/src/lib/tasks/shared/declare-lint-config-task.ts +13 -0
- package/src/lib/tasks/shared/declare-typescript-config-task.ts +18 -0
- package/src/lib/tasks/shared/encode-compact-json.ts +5 -0
- package/src/lib/tasks/shared/find-installed-package-binaries.ts +62 -0
- package/src/lib/tasks/shared/find-module-requests.ts +482 -0
- package/src/lib/tasks/shared/find-named-package-manifests.ts +94 -0
- package/src/lib/tasks/shared/find-unmet-typescript-config-requirements.ts +60 -0
- package/src/lib/tasks/shared/list-ignored-files-imported-by-source.ts +79 -0
- package/src/lib/tasks/shared/list-linted-files.ts +28 -0
- package/src/lib/tasks/shared/list-owned-files.ts +13 -0
- package/src/lib/tasks/shared/list-package-files.ts +66 -0
- package/src/lib/tasks/shared/load-the-lint-config.ts +176 -0
- package/src/lib/tasks/shared/match-granted-patch-files.ts +88 -0
- package/src/lib/tasks/shared/parse-config-files-that-import-from-check.ts +310 -0
- package/src/lib/tasks/shared/print-failures-and-keep-detail-in-the-trace.ts +99 -0
- package/src/lib/tasks/shared/project-config-and-tool-errors.ts +485 -0
- package/src/lib/tasks/shared/query-the-typescript-project.ts +635 -0
- package/src/lib/tasks/shared/read-named-package-manifests.ts +53 -0
- package/src/lib/tasks/shared/read-package-manifest-object.ts +28 -0
- package/src/lib/tasks/shared/resolve-absolute-paths.ts +4 -0
- package/src/lib/tasks/shared/resolve-module-requests.ts +121 -0
- package/src/lib/tasks/shared/run-tools-and-decode-their-reports.ts +98 -0
- package/src/lib/tasks/shared/tool-file-locations.ts +38 -0
- package/src/shared/bans-each-permission-lifts.ts +454 -0
- package/src/shared/config-file-names.ts +3 -0
- package/src/shared/find-retired-words.ts +17 -0
- package/src/shared/format-reported-failures.ts +31 -0
- package/src/shared/lint-rule-messages-and-patterns.ts +104 -0
- package/src/shared/match-file-names-and-path-prefixes.ts +18 -0
- package/src/shared/permission-grant-errors.ts +42 -0
- package/src/shared/record-and-grant-permissions-by-path.ts +419 -0
- package/src/shared/test-home-directories.ts +4 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import type { ESTree, SourceCode } from "@oxlint/plugins";
|
|
3
|
+
|
|
4
|
+
import { importedExpression } from "./resolve-what-an-expression-imports.ts";
|
|
5
|
+
|
|
6
|
+
const COMPARISONS: ReadonlySet<string> = new Set(["===", "!==", "==", "!="]);
|
|
7
|
+
|
|
8
|
+
const isTagKey = (key: ESTree.Node, computed: boolean) =>
|
|
9
|
+
computed
|
|
10
|
+
? key.type === "Literal" && key.value === "_tag"
|
|
11
|
+
: (key.type === "Identifier" && key.name === "_tag") ||
|
|
12
|
+
(key.type === "Literal" && key.value === "_tag");
|
|
13
|
+
|
|
14
|
+
const isTagRead = (node: ESTree.Node) =>
|
|
15
|
+
node.type === "MemberExpression" && isTagKey(node.property, node.computed);
|
|
16
|
+
|
|
17
|
+
const memberOf = (node: ESTree.Node, owner: string) => {
|
|
18
|
+
const isNamedMemberOfOwner =
|
|
19
|
+
node.type === "MemberExpression" &&
|
|
20
|
+
!node.computed &&
|
|
21
|
+
node.object.type === "Identifier" &&
|
|
22
|
+
node.object.name === owner &&
|
|
23
|
+
node.property.type === "Identifier";
|
|
24
|
+
return isNamedMemberOfOwner ? node.property.name : null;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const isEffectCatch = (node: ESTree.Node) =>
|
|
28
|
+
node.type === "CallExpression" && (memberOf(node.callee, "Effect")?.startsWith("catch") ?? false);
|
|
29
|
+
|
|
30
|
+
const insideEffectCatch = (node: ESTree.Node): boolean =>
|
|
31
|
+
node.parent === null ? false : isEffectCatch(node.parent) || insideEffectCatch(node.parent);
|
|
32
|
+
|
|
33
|
+
const isMatchPattern = (node: ESTree.Node) =>
|
|
34
|
+
node.parent?.type === "CallExpression" && memberOf(node.parent.callee, "Match") !== null;
|
|
35
|
+
|
|
36
|
+
const isPlatformSystemErrorOptions = (node: ESTree.Node, sourceCode: SourceCode) => {
|
|
37
|
+
const call = node.parent;
|
|
38
|
+
if (call?.type !== "CallExpression") {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
if (call.arguments[0] !== node) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const imported = importedExpression(call.callee, sourceCode);
|
|
45
|
+
return (
|
|
46
|
+
imported !== undefined &&
|
|
47
|
+
((imported.module === "effect" && imported.members.join(".") === "PlatformError.systemError") ||
|
|
48
|
+
(imported.module === "effect/PlatformError" && imported.members.join(".") === "systemError"))
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const noManualTag = defineRule({
|
|
53
|
+
meta: {
|
|
54
|
+
type: "problem",
|
|
55
|
+
docs: {
|
|
56
|
+
description:
|
|
57
|
+
"Disallow hand-written `_tag` values, except the reason tag Effect's PlatformError.systemError takes.",
|
|
58
|
+
},
|
|
59
|
+
messages: {
|
|
60
|
+
construction: "`_tag` is written by hand",
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
create(context) {
|
|
64
|
+
return {
|
|
65
|
+
ObjectExpression(node) {
|
|
66
|
+
if (isMatchPattern(node)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (isPlatformSystemErrorOptions(node, context.sourceCode)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
for (const property of node.properties) {
|
|
73
|
+
const writesTagByHand =
|
|
74
|
+
property.type === "Property" && isTagKey(property.key, property.computed);
|
|
75
|
+
if (writesTagByHand) {
|
|
76
|
+
context.report({ node: property, messageId: "construction" });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
export const noTagBranching = defineRule({
|
|
85
|
+
meta: {
|
|
86
|
+
type: "problem",
|
|
87
|
+
docs: { description: "Disallow comparing or switching on `_tag`." },
|
|
88
|
+
messages: {
|
|
89
|
+
comparison: "`_tag` is compared",
|
|
90
|
+
switch: "`_tag` is switched on",
|
|
91
|
+
catchTag: "`_tag` is branched on inside an Effect catch",
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
create(context) {
|
|
95
|
+
const branch = (node: ESTree.Node, messageId: "comparison" | "switch") => {
|
|
96
|
+
context.report({ node, messageId: insideEffectCatch(node) ? "catchTag" : messageId });
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
BinaryExpression(node) {
|
|
101
|
+
const comparesTag =
|
|
102
|
+
COMPARISONS.has(node.operator) && (isTagRead(node.left) || isTagRead(node.right));
|
|
103
|
+
if (comparesTag) {
|
|
104
|
+
branch(node, "comparison");
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
SwitchStatement(node) {
|
|
108
|
+
if (isTagRead(node.discriminant)) {
|
|
109
|
+
branch(node.discriminant, "switch");
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import type { ESTree } from "@oxlint/plugins";
|
|
3
|
+
|
|
4
|
+
import { SCHEDULE_MESSAGES } from "../shared/lint-rule-messages-and-patterns.ts";
|
|
5
|
+
import { TEST_HOME } from "../shared/test-home-directories.ts";
|
|
6
|
+
import { scheduleVisitors } from "./ban-timer-schedules-without-deadlines.ts";
|
|
7
|
+
import { effectModuleReference } from "./resolve-what-an-expression-imports.ts";
|
|
8
|
+
|
|
9
|
+
const TIMEOUT = "timeout";
|
|
10
|
+
|
|
11
|
+
export const noTestTimeouts = defineRule({
|
|
12
|
+
meta: {
|
|
13
|
+
type: "problem",
|
|
14
|
+
docs: {
|
|
15
|
+
description: `Bound tests in ${TEST_HOME} only with the timeout option of their task and wait on signals or TestClock instead of timers; Effect timeouts and timed schedules put a second clock inside the test. A test file granted pollsWithADeadline may poll an outside system with Schedule.spaced under a deadline.`,
|
|
16
|
+
},
|
|
17
|
+
messages: { ...SCHEDULE_MESSAGES, timeout: "{{usage}} sets a deadline inside a test" },
|
|
18
|
+
},
|
|
19
|
+
create(context) {
|
|
20
|
+
const schedules = scheduleVisitors({ context, timedSchedules: "banned" });
|
|
21
|
+
const reportEffectTimeout = (node: ESTree.Node) => {
|
|
22
|
+
const usage = effectModuleReference(node, context.sourceCode, "Effect");
|
|
23
|
+
if (usage?.split(".")[1]?.startsWith(TIMEOUT) === true) {
|
|
24
|
+
context.report({ node, messageId: "timeout", data: { usage } });
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
CallExpression(node) {
|
|
29
|
+
schedules.CallExpression(node);
|
|
30
|
+
},
|
|
31
|
+
Identifier(node) {
|
|
32
|
+
schedules.Identifier(node);
|
|
33
|
+
reportEffectTimeout(node);
|
|
34
|
+
},
|
|
35
|
+
MemberExpression(node) {
|
|
36
|
+
schedules.MemberExpression(node);
|
|
37
|
+
reportEffectTimeout(node);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import type { ESTree } from "@oxlint/plugins";
|
|
3
|
+
|
|
4
|
+
const DECLARATION_FILE = /\.d(?:\.[^./]+)?\.[cm]?ts$/u;
|
|
5
|
+
|
|
6
|
+
const isInsideAnAmbientBlock = (node: ESTree.Node): boolean => {
|
|
7
|
+
const { parent } = node;
|
|
8
|
+
if (parent === null) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const isAmbientBlock =
|
|
12
|
+
parent.type === "TSModuleDeclaration" && (parent.declare || parent.kind === "global");
|
|
13
|
+
return isAmbientBlock || isInsideAnAmbientBlock(parent);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const propertyName = (key: ESTree.Node) => {
|
|
17
|
+
const isNamedKey = key.type === "Identifier" || key.type === "PrivateIdentifier";
|
|
18
|
+
if (isNamedKey) {
|
|
19
|
+
return key.name;
|
|
20
|
+
}
|
|
21
|
+
return key.type === "Literal" ? String(key.value) : undefined;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const bindingNames = (declaration: ESTree.VariableDeclaration) =>
|
|
25
|
+
declaration.declarations
|
|
26
|
+
.map(({ id }) => (id.type === "Identifier" ? id.name : "a destructured binding"))
|
|
27
|
+
.join(", ");
|
|
28
|
+
|
|
29
|
+
export const noDeclaredValues = defineRule({
|
|
30
|
+
meta: {
|
|
31
|
+
type: "problem",
|
|
32
|
+
docs: {
|
|
33
|
+
description:
|
|
34
|
+
"Give every value and class field an implementation; anything declared with declare has a type nothing checks.",
|
|
35
|
+
},
|
|
36
|
+
messages: {
|
|
37
|
+
declaredValue: "{{name}} is declared without an implementation",
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
create(context) {
|
|
41
|
+
const isDeclarationFile = DECLARATION_FILE.test(context.filename);
|
|
42
|
+
const isAmbient = (node: ESTree.Node, declared: boolean | undefined) =>
|
|
43
|
+
declared === true || isDeclarationFile || isInsideAnAmbientBlock(node);
|
|
44
|
+
const report = (node: ESTree.Node, name: string) => {
|
|
45
|
+
context.report({ node, messageId: "declaredValue", data: { name } });
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
VariableDeclaration(node) {
|
|
49
|
+
if (isAmbient(node, node.declare)) {
|
|
50
|
+
report(node, bindingNames(node));
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
TSDeclareFunction(node) {
|
|
54
|
+
if (isAmbient(node, node.declare)) {
|
|
55
|
+
report(node, node.id?.name ?? "the default export");
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
PropertyDefinition(node) {
|
|
59
|
+
if (node.declare === true) {
|
|
60
|
+
report(node, propertyName(node.key) ?? "a computed class field");
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
ClassDeclaration(node) {
|
|
64
|
+
if (isAmbient(node, node.declare)) {
|
|
65
|
+
report(node, node.id?.name ?? "the default export");
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import type { ESTree } from "@oxlint/plugins";
|
|
3
|
+
|
|
4
|
+
import { EFFECT_OPERATION_RULES } from "../shared/lint-rule-messages-and-patterns.ts";
|
|
5
|
+
import { effectModuleOperation, moduleExportName } from "./resolve-what-an-expression-imports.ts";
|
|
6
|
+
|
|
7
|
+
const EFFECT_SUBPATH = "effect/";
|
|
8
|
+
|
|
9
|
+
const operationsByModule = (operations: Readonly<Record<string, readonly string[]>>) =>
|
|
10
|
+
new Map(
|
|
11
|
+
Object.entries(operations).map(([moduleName, names]) => [moduleName, new Set(names)] as const),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export const effectOperationRule = (ruleName: keyof typeof EFFECT_OPERATION_RULES) => {
|
|
15
|
+
const rule = EFFECT_OPERATION_RULES[ruleName];
|
|
16
|
+
const { description } = rule;
|
|
17
|
+
const bannedOperations = [["operation", operationsByModule(rule.operations)]] as const;
|
|
18
|
+
const bannedModules: ReadonlySet<string> = new Set(
|
|
19
|
+
bannedOperations.flatMap(([, operations]) => [...operations.keys()]),
|
|
20
|
+
);
|
|
21
|
+
return defineRule({
|
|
22
|
+
meta: {
|
|
23
|
+
type: "problem",
|
|
24
|
+
docs: { description },
|
|
25
|
+
messages: {
|
|
26
|
+
operation: "{{moduleName}}.{{operation}} is banned",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
create(context) {
|
|
30
|
+
const report = (node: ESTree.Node, moduleName: string, operation: string | undefined) => {
|
|
31
|
+
if (operation === undefined) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const banned = bannedOperations.find(
|
|
35
|
+
([, operations]) => operations.get(moduleName)?.has(operation) === true,
|
|
36
|
+
);
|
|
37
|
+
if (banned !== undefined) {
|
|
38
|
+
context.report({ node, messageId: banned[0], data: { moduleName, operation } });
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
MemberExpression(node) {
|
|
43
|
+
for (const moduleName of bannedModules) {
|
|
44
|
+
report(node, moduleName, effectModuleOperation(node, context.sourceCode, moduleName));
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
ImportDeclaration(node) {
|
|
48
|
+
const moduleName = node.source.value.startsWith(EFFECT_SUBPATH)
|
|
49
|
+
? node.source.value.slice(EFFECT_SUBPATH.length)
|
|
50
|
+
: undefined;
|
|
51
|
+
const isValueImportOfABannedModule =
|
|
52
|
+
node.importKind !== "type" && moduleName !== undefined && bannedModules.has(moduleName);
|
|
53
|
+
if (!isValueImportOfABannedModule) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
for (const specifier of node.specifiers) {
|
|
57
|
+
const isValueSpecifier =
|
|
58
|
+
specifier.type === "ImportSpecifier" && specifier.importKind !== "type";
|
|
59
|
+
if (isValueSpecifier) {
|
|
60
|
+
report(specifier, moduleName, moduleExportName(specifier.imported));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import type { ESTree } from "@oxlint/plugins";
|
|
3
|
+
|
|
4
|
+
import { effectModuleOperation, propertyKeyName } from "./resolve-what-an-expression-imports.ts";
|
|
5
|
+
|
|
6
|
+
const COLLECTING_OPERATION = "all";
|
|
7
|
+
const MODE = "mode";
|
|
8
|
+
const DEFAULT_MODE = "default";
|
|
9
|
+
|
|
10
|
+
const unsafeOptionsMessage = (options: ESTree.Node | undefined) => {
|
|
11
|
+
if (options === undefined) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (options.type !== "ObjectExpression") {
|
|
15
|
+
return "opaqueOptions";
|
|
16
|
+
}
|
|
17
|
+
const hasKeyItCannotName = options.properties.some(
|
|
18
|
+
(property) => property.type === "SpreadElement" || propertyKeyName(property) === undefined,
|
|
19
|
+
);
|
|
20
|
+
if (hasKeyItCannotName) {
|
|
21
|
+
return "opaqueOptions";
|
|
22
|
+
}
|
|
23
|
+
const mode = options.properties.find((property) => propertyKeyName(property) === MODE);
|
|
24
|
+
if (mode?.type !== "Property") {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const isDefaultMode = mode.value.type === "Literal" && mode.value.value === DEFAULT_MODE;
|
|
28
|
+
return isDefaultMode ? undefined : "results";
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const noFailuresAsResults = defineRule({
|
|
32
|
+
meta: {
|
|
33
|
+
type: "problem",
|
|
34
|
+
docs: {
|
|
35
|
+
description:
|
|
36
|
+
"Let Effect.all fail on the first failure, and collect failures as results only in files allowed handlesEveryFailure.",
|
|
37
|
+
},
|
|
38
|
+
messages: {
|
|
39
|
+
results: "Effect.all turns each failure into a result",
|
|
40
|
+
opaqueOptions: "Effect.all is given options that are not written inline",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
create(context) {
|
|
44
|
+
return {
|
|
45
|
+
CallExpression(node) {
|
|
46
|
+
const operation = effectModuleOperation(node.callee, context.sourceCode, "Effect");
|
|
47
|
+
if (operation !== COLLECTING_OPERATION) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const messageId = unsafeOptionsMessage(node.arguments[1]);
|
|
51
|
+
if (messageId !== undefined) {
|
|
52
|
+
context.report({ node: node.arguments[1] ?? node, messageId });
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import type { ESTree, SourceCode } from "@oxlint/plugins";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
effectModuleOperation,
|
|
6
|
+
resolvedVariable,
|
|
7
|
+
unwrappedExpression,
|
|
8
|
+
} from "./resolve-what-an-expression-imports.ts";
|
|
9
|
+
|
|
10
|
+
const NAMED_RECOVERY_MODULES = ["Effect", "Stream", "Channel"] as const;
|
|
11
|
+
|
|
12
|
+
const constantValue = (
|
|
13
|
+
node: ESTree.Node,
|
|
14
|
+
sourceCode: SourceCode,
|
|
15
|
+
seen: ReadonlySet<ESTree.Node> = new Set(),
|
|
16
|
+
): ESTree.Node => {
|
|
17
|
+
const expression = unwrappedExpression(node);
|
|
18
|
+
const definitions = resolvedVariable(expression, sourceCode)?.defs ?? [];
|
|
19
|
+
const declarator = definitions.length === 1 ? definitions[0]?.node : undefined;
|
|
20
|
+
const isConstantDeclarator =
|
|
21
|
+
declarator?.type === "VariableDeclarator" &&
|
|
22
|
+
declarator.id.type === "Identifier" &&
|
|
23
|
+
declarator.parent.type === "VariableDeclaration" &&
|
|
24
|
+
declarator.parent.kind === "const" &&
|
|
25
|
+
!seen.has(expression);
|
|
26
|
+
const value = isConstantDeclarator ? declarator.init : null;
|
|
27
|
+
return value === null
|
|
28
|
+
? expression
|
|
29
|
+
: constantValue(value, sourceCode, new Set([...seen, expression]));
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const isTagText = (node: ESTree.Node) =>
|
|
33
|
+
(node.type === "Literal" && typeof node.value === "string") || node.type === "TemplateLiteral";
|
|
34
|
+
|
|
35
|
+
const isTagList = (node: ESTree.Node) => isTagText(node) || node.type === "ArrayExpression";
|
|
36
|
+
|
|
37
|
+
const isHandlerObject = (node: ESTree.Node) => node.type === "ObjectExpression";
|
|
38
|
+
|
|
39
|
+
const NAMED_RECOVERIES: ReadonlyMap<
|
|
40
|
+
string,
|
|
41
|
+
{ readonly arity: number; readonly isNamingArgument: (node: ESTree.Node) => boolean }
|
|
42
|
+
> = new Map([
|
|
43
|
+
["catchTag", { arity: 2, isNamingArgument: isTagList }],
|
|
44
|
+
["catchTags", { arity: 1, isNamingArgument: isHandlerObject }],
|
|
45
|
+
["catchReason", { arity: 3, isNamingArgument: isTagText }],
|
|
46
|
+
["catchReasons", { arity: 2, isNamingArgument: isTagText }],
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
const namesFailures = (
|
|
50
|
+
isNamingArgument: (node: ESTree.Node) => boolean,
|
|
51
|
+
argument: ESTree.Node | undefined,
|
|
52
|
+
sourceCode: SourceCode,
|
|
53
|
+
) => argument !== undefined && isNamingArgument(constantValue(argument, sourceCode));
|
|
54
|
+
|
|
55
|
+
const hasFallback = (
|
|
56
|
+
call: ESTree.CallExpression,
|
|
57
|
+
recovery: {
|
|
58
|
+
readonly arity: number;
|
|
59
|
+
readonly isNamingArgument: (node: ESTree.Node) => boolean;
|
|
60
|
+
},
|
|
61
|
+
sourceCode: SourceCode,
|
|
62
|
+
) => {
|
|
63
|
+
const { arguments: callArguments } = call;
|
|
64
|
+
const hasSpread = callArguments.some((argument) => argument.type === "SpreadElement");
|
|
65
|
+
if (hasSpread) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
if (callArguments.length <= recovery.arity) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
const isFallbackAfterTheSelf = callArguments.length > recovery.arity + 1;
|
|
72
|
+
if (isFallbackAfterTheSelf) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
const isDataLastWithFallback = namesFailures(
|
|
76
|
+
recovery.isNamingArgument,
|
|
77
|
+
callArguments[0],
|
|
78
|
+
sourceCode,
|
|
79
|
+
);
|
|
80
|
+
const isDataFirstWithoutFallback = namesFailures(
|
|
81
|
+
recovery.isNamingArgument,
|
|
82
|
+
callArguments[1],
|
|
83
|
+
sourceCode,
|
|
84
|
+
);
|
|
85
|
+
return isDataLastWithFallback || !isDataFirstWithoutFallback;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const noUnnamedFallbacks = defineRule({
|
|
89
|
+
meta: {
|
|
90
|
+
type: "problem",
|
|
91
|
+
docs: {
|
|
92
|
+
description:
|
|
93
|
+
"Recover by name with catchTag, catchTags, catchReason and catchReasons without their fallback for every failure they do not name.",
|
|
94
|
+
},
|
|
95
|
+
messages: {
|
|
96
|
+
fallback: "{{member}} is given a fallback for failures it does not name",
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
create(context) {
|
|
100
|
+
return {
|
|
101
|
+
CallExpression(node) {
|
|
102
|
+
for (const moduleName of NAMED_RECOVERY_MODULES) {
|
|
103
|
+
const operation = effectModuleOperation(node.callee, context.sourceCode, moduleName);
|
|
104
|
+
const recovery = operation === undefined ? undefined : NAMED_RECOVERIES.get(operation);
|
|
105
|
+
const isFallbackGiven =
|
|
106
|
+
recovery !== undefined && hasFallback(node, recovery, context.sourceCode);
|
|
107
|
+
if (isFallbackGiven) {
|
|
108
|
+
context.report({
|
|
109
|
+
node,
|
|
110
|
+
messageId: "fallback",
|
|
111
|
+
data: { member: `${moduleName}.${operation}` },
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import type { ESTree } from "@oxlint/plugins";
|
|
3
|
+
|
|
4
|
+
const unexported = (member: ESTree.Node) => {
|
|
5
|
+
const isExport =
|
|
6
|
+
member.type === "ExportNamedDeclaration" || member.type === "ExportDefaultDeclaration";
|
|
7
|
+
if (!isExport) {
|
|
8
|
+
return member;
|
|
9
|
+
}
|
|
10
|
+
return member.declaration ?? member;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const methodName = (
|
|
14
|
+
method: {
|
|
15
|
+
readonly kind: ESTree.MethodDefinition["kind"] | ESTree.TSMethodSignature["kind"];
|
|
16
|
+
readonly key: ESTree.Node;
|
|
17
|
+
},
|
|
18
|
+
nameOf: (key: ESTree.Node) => string,
|
|
19
|
+
) => {
|
|
20
|
+
if (method.kind === "constructor") {
|
|
21
|
+
return "the constructor";
|
|
22
|
+
}
|
|
23
|
+
return method.kind === "method" ? nameOf(method.key) : `${method.kind} ${nameOf(method.key)}`;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const namedFunctionMember = (
|
|
27
|
+
member: ESTree.Node,
|
|
28
|
+
nameOf: (key: ESTree.Node) => string,
|
|
29
|
+
): { readonly name: string; readonly isSignature: boolean } | undefined => {
|
|
30
|
+
const declaration = unexported(member);
|
|
31
|
+
const isFunction =
|
|
32
|
+
declaration.type === "TSDeclareFunction" || declaration.type === "FunctionDeclaration";
|
|
33
|
+
if (isFunction) {
|
|
34
|
+
return {
|
|
35
|
+
name: declaration.id?.name ?? "the default export",
|
|
36
|
+
isSignature: declaration.type === "TSDeclareFunction",
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const isClassMethod =
|
|
40
|
+
declaration.type === "MethodDefinition" || declaration.type === "TSAbstractMethodDefinition";
|
|
41
|
+
if (isClassMethod) {
|
|
42
|
+
return {
|
|
43
|
+
name: `${declaration.static ? "static " : ""}${methodName(declaration, nameOf)}`,
|
|
44
|
+
isSignature: declaration.value.type === "TSEmptyBodyFunctionExpression",
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
if (declaration.type === "TSMethodSignature") {
|
|
48
|
+
return { name: methodName(declaration, nameOf), isSignature: true };
|
|
49
|
+
}
|
|
50
|
+
if (declaration.type === "TSCallSignatureDeclaration") {
|
|
51
|
+
return { name: "the call signature", isSignature: true };
|
|
52
|
+
}
|
|
53
|
+
return declaration.type === "TSConstructSignatureDeclaration"
|
|
54
|
+
? { name: "the construct signature", isSignature: true }
|
|
55
|
+
: undefined;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const noOverloads = defineRule({
|
|
59
|
+
meta: {
|
|
60
|
+
type: "suggestion",
|
|
61
|
+
docs: {
|
|
62
|
+
description:
|
|
63
|
+
"Give each function one signature, written on its implementation, so ReturnType and Parameters see the signature callers use instead of only the last overload.",
|
|
64
|
+
},
|
|
65
|
+
messages: {
|
|
66
|
+
overload: "{{name}} is overloaded",
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
create(context) {
|
|
70
|
+
const reportOverloads = (members: readonly ESTree.Node[]) => {
|
|
71
|
+
const declarationsByName = Map.groupBy(
|
|
72
|
+
members.flatMap((member) => {
|
|
73
|
+
const named = namedFunctionMember(member, (key) => context.sourceCode.getText(key));
|
|
74
|
+
return named === undefined ? [] : [{ member, ...named }];
|
|
75
|
+
}),
|
|
76
|
+
(declaration) => declaration.name,
|
|
77
|
+
);
|
|
78
|
+
for (const [name, declarations] of declarationsByName) {
|
|
79
|
+
if (declarations.length > 1) {
|
|
80
|
+
for (const { member } of declarations.filter((declaration) => declaration.isSignature)) {
|
|
81
|
+
context.report({ node: member, messageId: "overload", data: { name } });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
Program: (node) => {
|
|
88
|
+
reportOverloads(node.body);
|
|
89
|
+
},
|
|
90
|
+
TSModuleBlock: (node) => {
|
|
91
|
+
reportOverloads(node.body);
|
|
92
|
+
},
|
|
93
|
+
BlockStatement: (node) => {
|
|
94
|
+
reportOverloads(node.body);
|
|
95
|
+
},
|
|
96
|
+
ClassBody: (node) => {
|
|
97
|
+
reportOverloads(node.body);
|
|
98
|
+
},
|
|
99
|
+
TSInterfaceBody: (node) => {
|
|
100
|
+
reportOverloads(node.body);
|
|
101
|
+
},
|
|
102
|
+
TSTypeLiteral: (node) => {
|
|
103
|
+
reportOverloads(node.members);
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
});
|