@sshkeda/check 2.1.0 → 3.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/README.md +52 -22
- package/docs/how-to-make-check-pass.md +3 -0
- package/package.json +7 -10
- package/scripts/check.ts +10 -0
- package/src/internal/ban-abbreviated-words-in-declared-names.ts +4 -5
- package/src/internal/ban-deadlines-inside-tests.ts +4 -5
- package/src/internal/ban-dropped-failures-detached-fibers-sleeps-and-untraced-functions.ts +4 -5
- package/src/internal/ban-failures-collected-as-results.ts +4 -5
- package/src/internal/ban-fallbacks-of-named-recoveries.ts +6 -7
- package/src/internal/ban-fixed-values-in-recoveries.ts +331 -0
- package/src/internal/ban-re-exports.ts +14 -1
- package/src/internal/ban-reading-the-clock-and-sleeping-outside-effect.ts +4 -5
- package/src/internal/ban-recovering-file-system-exists.ts +12 -79
- package/src/internal/ban-timer-schedules-without-deadlines.ts +5 -6
- package/src/internal/ban-type-predicates.ts +4 -5
- package/src/internal/ban-what-a-file-is-not-granted.ts +9 -9
- package/src/internal/define-the-lint-plugin-and-configs.ts +6 -2
- package/src/internal/follow-the-steps-applied-to-an-effect.ts +100 -0
- package/src/internal/recognize-fixed-values.ts +318 -0
- package/src/internal/recognize-whole-library-error-tags.ts +6 -0
- package/src/internal/report-code-grants-nothing-uses.ts +122 -0
- package/src/lib/project-directory/index.ts +5 -0
- package/src/lib/project-directory/internal/read-the-project-directory.ts +13 -0
- package/src/lib/tasks/internal/declare-the-check-task.ts +18 -10
- package/src/lib/tasks/internal/declare-the-checker-queries-task.ts +3 -1
- package/src/lib/tasks/internal/verify-where-check-was-started.ts +50 -0
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/index.ts +1 -1
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/read-effect-tsgo-json-report.ts +13 -9
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/find-layer-provides-outside-program-starts.ts +6 -36
- package/src/lib/tasks/lib/detect-duplicate-functions/internal/find-duplicate-functions.ts +2 -3
- package/src/lib/tasks/lib/enforce-file-layout/internal/check-the-layout-of-each-package.ts +1 -1
- package/src/lib/tasks/lib/enforce-file-layout/internal/file-layout-errors.ts +19 -2
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +53 -19
- package/src/lib/tasks/lib/enforce-file-types/internal/find-file-type-violations.ts +1 -1
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/check-formatting-with-bun-fmt.ts +17 -16
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/declare-the-formatting-task.ts +22 -14
- package/src/lib/tasks/lib/lint-with-oxlint/index.ts +1 -1
- package/src/lib/tasks/lib/lint-with-oxlint/internal/check-lint-rules-with-oxlint.ts +7 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/find-shebangs-outside-bin.ts +38 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/shebang-errors.ts +22 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-export-placement-violations.ts +9 -1
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-the-importer-graph.ts +21 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/recognise-task-default-exports.ts +76 -0
- package/src/lib/tasks/lib/refuse-disable-directives/index.ts +1 -1
- package/src/lib/tasks/lib/refuse-forks-whose-failures-nothing-observes/index.ts +1 -0
- package/src/lib/tasks/lib/refuse-forks-whose-failures-nothing-observes/internal/find-unobserved-fork-failures.ts +402 -0
- package/src/lib/tasks/lib/refuse-forks-whose-failures-nothing-observes/internal/fork-failure-errors.ts +28 -0
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/find-linted-files-not-type-checked.ts +15 -9
- package/src/lib/tasks/lib/type-check-with-bun-check/index.ts +1 -1
- package/src/lib/tasks/shared/check-each-nested-package.ts +13 -5
- package/src/lib/tasks/shared/declare-lint-config-task.ts +1 -1
- package/src/lib/tasks/shared/declare-typescript-config-task.ts +1 -1
- package/src/lib/tasks/shared/find-installed-package-binaries.ts +10 -0
- package/src/lib/tasks/shared/list-package-files.ts +15 -2
- package/src/lib/tasks/shared/read-piped-steps-through-wrappers.ts +41 -0
- package/src/lib/tasks/shared/report-paths-from-the-project.ts +56 -0
- package/src/shared/bans-each-permission-lifts.ts +3 -0
- package/src/shared/format-reported-failures.ts +8 -6
- package/src/shared/record-and-grant-permissions-by-path.ts +63 -7
- package/src/internal/ban-shebang-lines.ts +0 -22
- /package/src/lib/tasks/{lib/format-with-bun-fmt/internal → shared}/find-symbolic-links.ts +0 -0
|
@@ -17,9 +17,11 @@ import {
|
|
|
17
17
|
grantPermissions,
|
|
18
18
|
permissionBanRuleId,
|
|
19
19
|
FAILURES_AS_RESULTS_RULE,
|
|
20
|
+
FIXED_FALLBACKS_RULE,
|
|
20
21
|
STDIO_SERVICE_RULE,
|
|
21
22
|
TEST_TIMEOUTS_RULE,
|
|
22
23
|
TYPE_PREDICATES_RULE,
|
|
24
|
+
UNUSED_CODE_GRANTS_RULE,
|
|
23
25
|
} from "../shared/record-and-grant-permissions-by-path.ts";
|
|
24
26
|
import { noAbbreviations } from "./ban-abbreviated-words-in-declared-names.ts";
|
|
25
27
|
import { noUncalledMembers } from "./ban-checked-members-outside-calls.ts";
|
|
@@ -30,6 +32,7 @@ import { noDeclaredValues } from "./ban-declared-values.ts";
|
|
|
30
32
|
import { effectOperationRule } from "./ban-dropped-failures-detached-fibers-sleeps-and-untraced-functions.ts";
|
|
31
33
|
import { noFailuresAsResults } from "./ban-failures-collected-as-results.ts";
|
|
32
34
|
import { noUnnamedFallbacks } from "./ban-fallbacks-of-named-recoveries.ts";
|
|
35
|
+
import { noFixedFallbacks } from "./ban-fixed-values-in-recoveries.ts";
|
|
33
36
|
import { noOverloads } from "./ban-function-overloads.ts";
|
|
34
37
|
import { noPlainErrorFailures } from "./ban-global-error-in-failure-types.ts";
|
|
35
38
|
import { noErrorInstanceof } from "./ban-instanceof-in-effect-recovery-callbacks.ts";
|
|
@@ -47,7 +50,6 @@ import { noExistsRecovery } from "./ban-recovering-file-system-exists.ts";
|
|
|
47
50
|
import { noRetiredWords } from "./ban-retired-words-in-names.ts";
|
|
48
51
|
import { noInstantRetries } from "./ban-retries-without-a-wait.ts";
|
|
49
52
|
import { noGlobScan } from "./ban-scanning-directories-with-bun-glob.ts";
|
|
50
|
-
import { noShebang } from "./ban-shebang-lines.ts";
|
|
51
53
|
import { globalRule } from "./ban-timer-globals-and-the-global-object.ts";
|
|
52
54
|
import { noSchedules } from "./ban-timer-schedules-without-deadlines.ts";
|
|
53
55
|
import { noTypeDeclarations } from "./ban-type-and-interface-declarations.ts";
|
|
@@ -69,6 +71,7 @@ import {
|
|
|
69
71
|
} from "./keep-assertions-in-the-test-home-and-ban-test-runners.ts";
|
|
70
72
|
import { noTestingHelpers } from "./keep-effect-testing-helpers-in-test-files.ts";
|
|
71
73
|
import { bansByKind } from "./match-banned-modules-and-globals.ts";
|
|
74
|
+
import { noUnusedCodeGrants } from "./report-code-grants-nothing-uses.ts";
|
|
72
75
|
import { noUnnamedCompoundConditions } from "./require-a-named-const-for-compound-conditions.ts";
|
|
73
76
|
import { noLooseLiteralConstants } from "./require-capital-snake-case-and-as-const-on-literal-constants.ts";
|
|
74
77
|
import { noMismatchedServiceKeys } from "./require-service-keys-to-end-with-their-class-name.ts";
|
|
@@ -136,6 +139,7 @@ const NAMED_RULES = {
|
|
|
136
139
|
"no-instant-retries": noInstantRetries,
|
|
137
140
|
"no-service-declarations": noServiceDeclarations,
|
|
138
141
|
"no-unused-service-grants": noUnusedServiceGrants,
|
|
142
|
+
[UNUSED_CODE_GRANTS_RULE]: noUnusedCodeGrants,
|
|
139
143
|
"no-glob-scan": noGlobScan,
|
|
140
144
|
"no-unknown-boundaries": noUnknownBoundaries,
|
|
141
145
|
"no-loose-literal-constants": noLooseLiteralConstants,
|
|
@@ -153,11 +157,11 @@ const NAMED_RULES = {
|
|
|
153
157
|
"no-let": noLet,
|
|
154
158
|
"no-mutable-ref": noMutableRef,
|
|
155
159
|
"no-while": noWhile,
|
|
156
|
-
"no-shebang": noShebang,
|
|
157
160
|
"no-shared-holders": noSharedHolders,
|
|
158
161
|
"no-uncalled-members": noUncalledMembers,
|
|
159
162
|
"no-unnamed-fallbacks": noUnnamedFallbacks,
|
|
160
163
|
"no-exists-recovery": noExistsRecovery,
|
|
164
|
+
[FIXED_FALLBACKS_RULE]: noFixedFallbacks,
|
|
161
165
|
"no-namespace-aliases": noNamespaceAliases(
|
|
162
166
|
new Set([
|
|
163
167
|
...RESTRICTED_PROPERTIES.map(({ object }) => object),
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { ESTree, SourceCode } from "@oxlint/plugins";
|
|
2
|
+
import { Array as Arrays, Option } from "effect";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
constantValue,
|
|
6
|
+
effectOperation,
|
|
7
|
+
isPipeFunction,
|
|
8
|
+
memberName,
|
|
9
|
+
} from "./resolve-what-an-expression-imports.ts";
|
|
10
|
+
|
|
11
|
+
const PIPE = "pipe";
|
|
12
|
+
|
|
13
|
+
export const stepOf = (step: ESTree.Node, sourceCode: SourceCode) => {
|
|
14
|
+
const node = constantValue(step, sourceCode);
|
|
15
|
+
if (node.type === "CallExpression") {
|
|
16
|
+
return {
|
|
17
|
+
operation: effectOperation(node.callee, sourceCode),
|
|
18
|
+
callArguments: node.arguments,
|
|
19
|
+
isDataFirst: false,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return { operation: effectOperation(node, sourceCode), callArguments: [], isDataFirst: false };
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const stepsOf = (steps: readonly ESTree.Node[], sourceCode: SourceCode) =>
|
|
26
|
+
steps.map((step) => stepOf(step, sourceCode));
|
|
27
|
+
|
|
28
|
+
const isPipeMethodCall = (call: ESTree.Node | null | undefined) =>
|
|
29
|
+
call?.type === "CallExpression" &&
|
|
30
|
+
call.callee.type === "MemberExpression" &&
|
|
31
|
+
memberName(call.callee) === PIPE;
|
|
32
|
+
|
|
33
|
+
export const stepsAppliedTo = (
|
|
34
|
+
effect: ESTree.Node,
|
|
35
|
+
sourceCode: SourceCode,
|
|
36
|
+
): readonly ReturnType<typeof stepOf>[] => {
|
|
37
|
+
const { parent } = effect;
|
|
38
|
+
const isWrappedByTypeScript =
|
|
39
|
+
parent?.type === "TSAsExpression" ||
|
|
40
|
+
parent?.type === "TSSatisfiesExpression" ||
|
|
41
|
+
parent?.type === "TSNonNullExpression";
|
|
42
|
+
if (isWrappedByTypeScript) {
|
|
43
|
+
return stepsAppliedTo(parent, sourceCode);
|
|
44
|
+
}
|
|
45
|
+
const call = parent?.parent;
|
|
46
|
+
const isPipeMethod =
|
|
47
|
+
parent?.type === "MemberExpression" &&
|
|
48
|
+
parent.object === effect &&
|
|
49
|
+
call?.type === "CallExpression" &&
|
|
50
|
+
call.callee === parent &&
|
|
51
|
+
isPipeMethodCall(call);
|
|
52
|
+
if (isPipeMethod) {
|
|
53
|
+
return [...stepsOf(call.arguments, sourceCode), ...stepsAppliedTo(call, sourceCode)];
|
|
54
|
+
}
|
|
55
|
+
const isFirstArgument = parent?.type === "CallExpression" && parent.arguments[0] === effect;
|
|
56
|
+
if (!isFirstArgument) {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
const isAppliedStep =
|
|
60
|
+
constantValue(parent.callee, sourceCode).type === "CallExpression" &&
|
|
61
|
+
parent.arguments.length === 1;
|
|
62
|
+
if (isAppliedStep) {
|
|
63
|
+
return [stepOf(parent.callee, sourceCode), ...stepsAppliedTo(parent, sourceCode)];
|
|
64
|
+
}
|
|
65
|
+
if (isPipeFunction(parent.callee, sourceCode)) {
|
|
66
|
+
return [
|
|
67
|
+
...stepsOf(parent.arguments.slice(1), sourceCode),
|
|
68
|
+
...stepsAppliedTo(parent, sourceCode),
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
return [
|
|
72
|
+
{
|
|
73
|
+
operation: effectOperation(parent.callee, sourceCode),
|
|
74
|
+
callArguments: parent.arguments.slice(1),
|
|
75
|
+
isDataFirst: true,
|
|
76
|
+
},
|
|
77
|
+
...stepsAppliedTo(parent, sourceCode),
|
|
78
|
+
];
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const stepsAfter = (step: ESTree.Node, sourceCode: SourceCode) => {
|
|
82
|
+
const { parent } = step;
|
|
83
|
+
if (parent?.type !== "CallExpression") {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
const position = Option.getOrUndefined(
|
|
87
|
+
Arrays.findFirstIndex(parent.arguments, (argument) => argument === step),
|
|
88
|
+
);
|
|
89
|
+
if (position === undefined) {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
const isPipeStep =
|
|
93
|
+
isPipeMethodCall(parent) || (position > 0 && isPipeFunction(parent.callee, sourceCode));
|
|
94
|
+
return isPipeStep
|
|
95
|
+
? [
|
|
96
|
+
...stepsOf(parent.arguments.slice(position + 1), sourceCode),
|
|
97
|
+
...stepsAppliedTo(parent, sourceCode),
|
|
98
|
+
]
|
|
99
|
+
: [];
|
|
100
|
+
};
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import type { ESTree, SourceCode } from "@oxlint/plugins";
|
|
2
|
+
|
|
3
|
+
import { stepOf } from "./follow-the-steps-applied-to-an-effect.ts";
|
|
4
|
+
import {
|
|
5
|
+
constantValue,
|
|
6
|
+
effectModuleOperation,
|
|
7
|
+
importedExpression,
|
|
8
|
+
isGlobalReference,
|
|
9
|
+
isPipeFunction,
|
|
10
|
+
memberName,
|
|
11
|
+
resolvedVariable,
|
|
12
|
+
unwrappedExpression,
|
|
13
|
+
} from "./resolve-what-an-expression-imports.ts";
|
|
14
|
+
|
|
15
|
+
const PIPE = "pipe";
|
|
16
|
+
|
|
17
|
+
const EFFECT_MODULES = ["Effect", "Stream", "Channel"] as const;
|
|
18
|
+
|
|
19
|
+
const FIXED_EFFECTS: ReadonlySet<string> = new Set(["void", "succeedNone", "empty"]);
|
|
20
|
+
|
|
21
|
+
const SUCCEEDING_OPERATIONS: ReadonlySet<string> = new Set(["succeed", "succeedSome"]);
|
|
22
|
+
|
|
23
|
+
const SIGN_OPERATORS: ReadonlySet<string> = new Set(["-", "+", "void"]);
|
|
24
|
+
|
|
25
|
+
const CONSTRUCTED_GLOBALS = ["Map", "Set", "Date", "Uint8Array"] as const;
|
|
26
|
+
|
|
27
|
+
const PRIMITIVE_GLOBAL_CALLS = [
|
|
28
|
+
{ object: "Date", member: "now" },
|
|
29
|
+
{ object: "process", member: "cwd" },
|
|
30
|
+
] as const;
|
|
31
|
+
|
|
32
|
+
const GLOBAL_CALLS = [...PRIMITIVE_GLOBAL_CALLS, { object: "Uint8Array", member: "of" }] as const;
|
|
33
|
+
|
|
34
|
+
const MODULE_SCOPES: ReadonlySet<string> = new Set(["module", "global"]);
|
|
35
|
+
|
|
36
|
+
const OS_MODULES: ReadonlySet<string> = new Set(["node:os", "os"]);
|
|
37
|
+
|
|
38
|
+
const HOME_DIRECTORY = "homedir";
|
|
39
|
+
|
|
40
|
+
const CURRENT_TIME = [
|
|
41
|
+
{ moduleName: "Clock", member: "currentTimeMillis" },
|
|
42
|
+
{ moduleName: "DateTime", member: "now" },
|
|
43
|
+
] as const;
|
|
44
|
+
|
|
45
|
+
const branchesOf = (expression: ESTree.Node): readonly ESTree.Node[] => {
|
|
46
|
+
const value = unwrappedExpression(expression);
|
|
47
|
+
if (value.type === "ConditionalExpression") {
|
|
48
|
+
return [...branchesOf(value.consequent), ...branchesOf(value.alternate)];
|
|
49
|
+
}
|
|
50
|
+
if (value.type === "SequenceExpression") {
|
|
51
|
+
const last = value.expressions.at(-1);
|
|
52
|
+
return last === undefined ? [] : branchesOf(last);
|
|
53
|
+
}
|
|
54
|
+
return [value];
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const returnedValuesIn = (statement: ESTree.Node | null): readonly ESTree.Node[] => {
|
|
58
|
+
if (statement === null) {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
if (statement.type === "ReturnStatement") {
|
|
62
|
+
return statement.argument === null ? [] : branchesOf(statement.argument);
|
|
63
|
+
}
|
|
64
|
+
if (statement.type === "BlockStatement") {
|
|
65
|
+
return statement.body.flatMap((inner) => returnedValuesIn(inner));
|
|
66
|
+
}
|
|
67
|
+
if (statement.type === "IfStatement") {
|
|
68
|
+
return [...returnedValuesIn(statement.consequent), ...returnedValuesIn(statement.alternate)];
|
|
69
|
+
}
|
|
70
|
+
if (statement.type === "TryStatement") {
|
|
71
|
+
return [
|
|
72
|
+
...returnedValuesIn(statement.block),
|
|
73
|
+
...returnedValuesIn(statement.handler?.body ?? null),
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
if (statement.type === "SwitchStatement") {
|
|
77
|
+
return statement.cases.flatMap((switchCase) =>
|
|
78
|
+
switchCase.consequent.flatMap((inner) => returnedValuesIn(inner)),
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
return statement.type === "LabeledStatement" ? returnedValuesIn(statement.body) : [];
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const FUNCTION_WRAPPERS: ReadonlySet<string> = new Set(["fn", "fnUntraced"]);
|
|
85
|
+
|
|
86
|
+
const isFunctionWrapper = (callee: ESTree.Node, sourceCode: SourceCode) => {
|
|
87
|
+
const operation = effectModuleOperation(callee, sourceCode, "Effect");
|
|
88
|
+
return operation !== undefined && FUNCTION_WRAPPERS.has(operation);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const wrappedFunction = (call: ESTree.CallExpression, sourceCode: SourceCode) => {
|
|
92
|
+
const isNamedWrapper =
|
|
93
|
+
call.callee.type === "CallExpression" && isFunctionWrapper(call.callee.callee, sourceCode);
|
|
94
|
+
const isWrapped = isNamedWrapper || isFunctionWrapper(call.callee, sourceCode);
|
|
95
|
+
const [wrapped] = call.arguments;
|
|
96
|
+
const isWrappingAFunction = isWrapped && wrapped !== undefined;
|
|
97
|
+
return isWrappingAFunction ? constantValue(wrapped, sourceCode) : undefined;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export const handlerFunction = (handler: ESTree.Node, sourceCode: SourceCode) => {
|
|
101
|
+
const resolved = constantValue(handler, sourceCode);
|
|
102
|
+
const unwrapped =
|
|
103
|
+
resolved.type === "CallExpression" ? wrappedFunction(resolved, sourceCode) : resolved;
|
|
104
|
+
const isFunction =
|
|
105
|
+
unwrapped?.type === "ArrowFunctionExpression" ||
|
|
106
|
+
unwrapped?.type === "FunctionExpression" ||
|
|
107
|
+
unwrapped?.type === "FunctionDeclaration";
|
|
108
|
+
return isFunction ? unwrapped : undefined;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export const returnedBranches = (handler: ESTree.Node, sourceCode: SourceCode) => {
|
|
112
|
+
const body = handlerFunction(handler, sourceCode)?.body ?? null;
|
|
113
|
+
if (body === null) {
|
|
114
|
+
return [];
|
|
115
|
+
}
|
|
116
|
+
return body.type === "BlockStatement" ? returnedValuesIn(body) : branchesOf(body);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const isGlobalCall = (
|
|
120
|
+
callee: ESTree.Node,
|
|
121
|
+
sourceCode: SourceCode,
|
|
122
|
+
calls: readonly { readonly object: string; readonly member: string }[] = GLOBAL_CALLS,
|
|
123
|
+
) =>
|
|
124
|
+
callee.type === "MemberExpression" &&
|
|
125
|
+
calls.some(
|
|
126
|
+
({ object, member }) =>
|
|
127
|
+
memberName(callee) === member && isGlobalReference(callee.object, sourceCode, object),
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const isHomeDirectoryCall = (callee: ESTree.Node, sourceCode: SourceCode) => {
|
|
131
|
+
const imported = importedExpression(callee, sourceCode);
|
|
132
|
+
return (
|
|
133
|
+
imported !== undefined &&
|
|
134
|
+
OS_MODULES.has(imported.module) &&
|
|
135
|
+
imported.members.at(-1) === HOME_DIRECTORY
|
|
136
|
+
);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const isFixedOptionOrResult = (call: ESTree.CallExpression, sourceCode: SourceCode) => {
|
|
140
|
+
const optionOperation = effectModuleOperation(call.callee, sourceCode, "Option");
|
|
141
|
+
const resultOperation = effectModuleOperation(call.callee, sourceCode, "Result");
|
|
142
|
+
const isNone = optionOperation === "none" && call.arguments.length === 0;
|
|
143
|
+
const wrapsOneValue =
|
|
144
|
+
(optionOperation === "some" || resultOperation === "succeed") && call.arguments.length === 1;
|
|
145
|
+
return isNone || wrapsOneValue;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const isImmutableByNature = (value: ESTree.Node, sourceCode: SourceCode): boolean => {
|
|
149
|
+
if (value.type === "Literal") {
|
|
150
|
+
return typeof value.value !== "object" || value.value === null;
|
|
151
|
+
}
|
|
152
|
+
if (value.type === "TemplateLiteral") {
|
|
153
|
+
return value.expressions.length === 0;
|
|
154
|
+
}
|
|
155
|
+
if (value.type === "Identifier") {
|
|
156
|
+
return isGlobalReference(value, sourceCode, "undefined");
|
|
157
|
+
}
|
|
158
|
+
if (value.type === "UnaryExpression") {
|
|
159
|
+
return (
|
|
160
|
+
SIGN_OPERATORS.has(value.operator) &&
|
|
161
|
+
isImmutableByNature(constantValue(value.argument, sourceCode), sourceCode)
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
if (value.type !== "CallExpression") {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
const isPrimitiveCall =
|
|
168
|
+
isGlobalCall(value.callee, sourceCode, PRIMITIVE_GLOBAL_CALLS) ||
|
|
169
|
+
isHomeDirectoryCall(value.callee, sourceCode);
|
|
170
|
+
const isImmutableCall = isPrimitiveCall || isFixedOptionOrResult(value, sourceCode);
|
|
171
|
+
return (
|
|
172
|
+
isImmutableCall &&
|
|
173
|
+
value.arguments.every(
|
|
174
|
+
(argument) =>
|
|
175
|
+
argument.type !== "SpreadElement" &&
|
|
176
|
+
isImmutableByNature(constantValue(argument, sourceCode), sourceCode),
|
|
177
|
+
)
|
|
178
|
+
);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const valueOfAnUnchangeableBinding = (node: ESTree.Node, sourceCode: SourceCode) => {
|
|
182
|
+
const value = constantValue(node, sourceCode);
|
|
183
|
+
const variable = resolvedVariable(unwrappedExpression(node), sourceCode);
|
|
184
|
+
const isDeclaredAtModuleScope =
|
|
185
|
+
variable === undefined || MODULE_SCOPES.has(variable.scope.variableScope.type);
|
|
186
|
+
const isResolvable = isDeclaredAtModuleScope || isImmutableByNature(value, sourceCode);
|
|
187
|
+
return isResolvable ? value : unwrappedExpression(node);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
export const isFixedValue = (node: ESTree.Node, sourceCode: SourceCode): boolean => {
|
|
191
|
+
const value = valueOfAnUnchangeableBinding(node, sourceCode);
|
|
192
|
+
const areFixedArguments = (callArguments: readonly ESTree.Node[]) =>
|
|
193
|
+
callArguments.every(
|
|
194
|
+
(argument) => argument.type !== "SpreadElement" && isFixedValue(argument, sourceCode),
|
|
195
|
+
);
|
|
196
|
+
const isFixedProperty = (property: ESTree.Node) =>
|
|
197
|
+
property.type === "Property" &&
|
|
198
|
+
!property.computed &&
|
|
199
|
+
!property.method &&
|
|
200
|
+
property.kind === "init" &&
|
|
201
|
+
isFixedValue(property.value, sourceCode);
|
|
202
|
+
if (value.type === "Literal") {
|
|
203
|
+
return typeof value.value !== "object" || value.value === null;
|
|
204
|
+
}
|
|
205
|
+
if (value.type === "TemplateLiteral") {
|
|
206
|
+
return value.expressions.length === 0;
|
|
207
|
+
}
|
|
208
|
+
if (value.type === "Identifier") {
|
|
209
|
+
return isGlobalReference(value, sourceCode, "undefined");
|
|
210
|
+
}
|
|
211
|
+
if (value.type === "UnaryExpression") {
|
|
212
|
+
return SIGN_OPERATORS.has(value.operator) && isFixedValue(value.argument, sourceCode);
|
|
213
|
+
}
|
|
214
|
+
if (value.type === "ArrayExpression") {
|
|
215
|
+
return value.elements.every(
|
|
216
|
+
(element) =>
|
|
217
|
+
element !== null && element.type !== "SpreadElement" && isFixedValue(element, sourceCode),
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
if (value.type === "ObjectExpression") {
|
|
221
|
+
return value.properties.every((property) => isFixedProperty(property));
|
|
222
|
+
}
|
|
223
|
+
if (value.type === "NewExpression") {
|
|
224
|
+
const isConstructedGlobal = CONSTRUCTED_GLOBALS.some((name) =>
|
|
225
|
+
isGlobalReference(value.callee, sourceCode, name),
|
|
226
|
+
);
|
|
227
|
+
return isConstructedGlobal && areFixedArguments(value.arguments);
|
|
228
|
+
}
|
|
229
|
+
if (value.type !== "CallExpression") {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
const isFixedCall =
|
|
233
|
+
isGlobalCall(value.callee, sourceCode) ||
|
|
234
|
+
isHomeDirectoryCall(value.callee, sourceCode) ||
|
|
235
|
+
isFixedOptionOrResult(value, sourceCode);
|
|
236
|
+
return isFixedCall && areFixedArguments(value.arguments);
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const isCurrentTime = (node: ESTree.Node, sourceCode: SourceCode) =>
|
|
240
|
+
CURRENT_TIME.some(
|
|
241
|
+
({ moduleName, member }) => effectModuleOperation(node, sourceCode, moduleName) === member,
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
const isFixedEffectMember = (node: ESTree.Node, sourceCode: SourceCode) =>
|
|
245
|
+
isCurrentTime(node, sourceCode) ||
|
|
246
|
+
EFFECT_MODULES.some((moduleName) => {
|
|
247
|
+
const operation = effectModuleOperation(node, sourceCode, moduleName);
|
|
248
|
+
return operation !== undefined && FIXED_EFFECTS.has(operation);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
const fixedValueAfterTheLastStep = (steps: readonly ESTree.Node[], sourceCode: SourceCode) => {
|
|
252
|
+
const last = steps.at(-1);
|
|
253
|
+
if (last === undefined) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const { operation, callArguments } = stepOf(last, sourceCode);
|
|
257
|
+
const [value] = callArguments;
|
|
258
|
+
if (operation === "asVoid") {
|
|
259
|
+
return callArguments.length === 0 ? last : undefined;
|
|
260
|
+
}
|
|
261
|
+
const isFixedReplacement =
|
|
262
|
+
operation === "as" && value !== undefined && isFixedValue(value, sourceCode);
|
|
263
|
+
return isFixedReplacement ? value : undefined;
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
const fixedReturnedValue = (
|
|
267
|
+
callArguments: readonly ESTree.Node[],
|
|
268
|
+
sourceCode: SourceCode,
|
|
269
|
+
): ESTree.Node | undefined =>
|
|
270
|
+
callArguments
|
|
271
|
+
.flatMap((argument) => returnedBranches(argument, sourceCode))
|
|
272
|
+
.find((branch) => isFixedValue(branch, sourceCode));
|
|
273
|
+
|
|
274
|
+
const fixedValueOfEffectCall = (
|
|
275
|
+
call: ESTree.CallExpression,
|
|
276
|
+
sourceCode: SourceCode,
|
|
277
|
+
): ESTree.Node | undefined => {
|
|
278
|
+
const { callee, arguments: callArguments } = call;
|
|
279
|
+
const isPipeMethod = callee.type === "MemberExpression" && memberName(callee) === PIPE;
|
|
280
|
+
if (isPipeMethod) {
|
|
281
|
+
return fixedValueAfterTheLastStep(callArguments, sourceCode);
|
|
282
|
+
}
|
|
283
|
+
if (isPipeFunction(callee, sourceCode)) {
|
|
284
|
+
return fixedValueAfterTheLastStep(callArguments.slice(1), sourceCode);
|
|
285
|
+
}
|
|
286
|
+
const operation = EFFECT_MODULES.map((moduleName) =>
|
|
287
|
+
effectModuleOperation(callee, sourceCode, moduleName),
|
|
288
|
+
).find((found) => found !== undefined);
|
|
289
|
+
const [first, second] = callArguments;
|
|
290
|
+
if (operation === undefined) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (SUCCEEDING_OPERATIONS.has(operation)) {
|
|
294
|
+
const isFixedSuccess =
|
|
295
|
+
callArguments.length === 1 && first !== undefined && isFixedValue(first, sourceCode);
|
|
296
|
+
return isFixedSuccess ? first : undefined;
|
|
297
|
+
}
|
|
298
|
+
if (operation === "as") {
|
|
299
|
+
const isFixedReplacement = second !== undefined && isFixedValue(second, sourceCode);
|
|
300
|
+
return isFixedReplacement ? second : undefined;
|
|
301
|
+
}
|
|
302
|
+
if (operation === "asVoid") {
|
|
303
|
+
return callArguments.length === 1 ? call : undefined;
|
|
304
|
+
}
|
|
305
|
+
const computesItsValue = operation === "sync" || operation === "gen";
|
|
306
|
+
return computesItsValue ? fixedReturnedValue(callArguments, sourceCode) : undefined;
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
export const fixedOutcomeOf = (node: ESTree.Node, sourceCode: SourceCode) => {
|
|
310
|
+
if (isFixedValue(node, sourceCode)) {
|
|
311
|
+
return node;
|
|
312
|
+
}
|
|
313
|
+
const value = constantValue(node, sourceCode);
|
|
314
|
+
if (value.type === "CallExpression") {
|
|
315
|
+
return fixedValueOfEffectCall(value, sourceCode);
|
|
316
|
+
}
|
|
317
|
+
return isFixedEffectMember(value, sourceCode) ? node : undefined;
|
|
318
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const LIBRARY_ERROR_SUFFIX = "Error";
|
|
2
|
+
|
|
3
|
+
const LIBRARY_ERROR_TAGS_WITHOUT_THE_SUFFIX: ReadonlySet<string> = new Set(["CommandFailed"]);
|
|
4
|
+
|
|
5
|
+
export const isWholeLibraryErrorTag = (tag: string) =>
|
|
6
|
+
tag.endsWith(LIBRARY_ERROR_SUFFIX) || LIBRARY_ERROR_TAGS_WITHOUT_THE_SUFFIX.has(tag);
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { Context, CreateRule, Visitor } from "@oxlint/plugins";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
HANDLES_EVERY_FAILURE,
|
|
6
|
+
PERMISSION_BANS,
|
|
7
|
+
RULES_EACH_PERMISSION_LIFTS,
|
|
8
|
+
SHORT_NAMES,
|
|
9
|
+
TRUSTS_UNVERIFIED_TYPES,
|
|
10
|
+
unusedGrantMessage,
|
|
11
|
+
} from "../shared/bans-each-permission-lifts.ts";
|
|
12
|
+
import {
|
|
13
|
+
CLOCK_RULE,
|
|
14
|
+
CODE_GRANTS,
|
|
15
|
+
FAILURES_AS_RESULTS_RULE,
|
|
16
|
+
INSIDE_THE_TEST_HOME,
|
|
17
|
+
rulesACodeGrantChanges,
|
|
18
|
+
SCHEDULES_RULE,
|
|
19
|
+
SLEEP_RULE,
|
|
20
|
+
TEST_TIMEOUTS_RULE,
|
|
21
|
+
TYPE_PREDICATES_RULE,
|
|
22
|
+
UNNAMED_FALLBACKS_RULE,
|
|
23
|
+
} from "../shared/record-and-grant-permissions-by-path.ts";
|
|
24
|
+
import { noAbbreviations } from "./ban-abbreviated-words-in-declared-names.ts";
|
|
25
|
+
import { noTestTimeouts } from "./ban-deadlines-inside-tests.ts";
|
|
26
|
+
import { effectOperationRule } from "./ban-dropped-failures-detached-fibers-sleeps-and-untraced-functions.ts";
|
|
27
|
+
import { noFailuresAsResults } from "./ban-failures-collected-as-results.ts";
|
|
28
|
+
import { noUnnamedFallbacks } from "./ban-fallbacks-of-named-recoveries.ts";
|
|
29
|
+
import { noClockReadsAndSleeps } from "./ban-reading-the-clock-and-sleeping-outside-effect.ts";
|
|
30
|
+
import { noSchedules } from "./ban-timer-schedules-without-deadlines.ts";
|
|
31
|
+
import { noTypePredicates } from "./ban-type-predicates.ts";
|
|
32
|
+
import { mergedVisitors, permissionBanRule } from "./ban-what-a-file-is-not-granted.ts";
|
|
33
|
+
import { decodeRuleOptions, ruleOptionsJsonSchema } from "./describe-and-decode-rule-options.ts";
|
|
34
|
+
|
|
35
|
+
const RULES_CODE_GRANTS_CHANGE: ReadonlyMap<
|
|
36
|
+
string,
|
|
37
|
+
{
|
|
38
|
+
readonly create: (context: Pick<Context, "options" | "report" | "sourceCode">) => Visitor;
|
|
39
|
+
}
|
|
40
|
+
> = new Map(
|
|
41
|
+
Object.entries({
|
|
42
|
+
[PERMISSION_BANS[HANDLES_EVERY_FAILURE].ruleName]: permissionBanRule(HANDLES_EVERY_FAILURE),
|
|
43
|
+
[PERMISSION_BANS[TRUSTS_UNVERIFIED_TYPES].ruleName]: permissionBanRule(TRUSTS_UNVERIFIED_TYPES),
|
|
44
|
+
[FAILURES_AS_RESULTS_RULE]: noFailuresAsResults,
|
|
45
|
+
[UNNAMED_FALLBACKS_RULE]: noUnnamedFallbacks,
|
|
46
|
+
[SLEEP_RULE]: effectOperationRule(SLEEP_RULE),
|
|
47
|
+
[CLOCK_RULE]: noClockReadsAndSleeps,
|
|
48
|
+
[SCHEDULES_RULE]: noSchedules,
|
|
49
|
+
[TEST_TIMEOUTS_RULE]: noTestTimeouts,
|
|
50
|
+
[RULES_EACH_PERMISSION_LIFTS[SHORT_NAMES]]: noAbbreviations,
|
|
51
|
+
[TYPE_PREDICATES_RULE]: noTypePredicates,
|
|
52
|
+
}).map(([name, rule]) => [`sshkeda/${name}`, rule] as const),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const UNUSED_CODE_GRANT_OPTIONS = Schema.Struct({
|
|
56
|
+
permissions: Schema.optionalKey(Schema.Array(Schema.Literals(CODE_GRANTS))),
|
|
57
|
+
testHome: Schema.optionalKey(Schema.Literal(INSIDE_THE_TEST_HOME)),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export const noUnusedCodeGrants = {
|
|
61
|
+
meta: {
|
|
62
|
+
type: "problem",
|
|
63
|
+
messages: { unusedGrant: unusedGrantMessage("{{permission}}") },
|
|
64
|
+
schema: ruleOptionsJsonSchema(UNUSED_CODE_GRANT_OPTIONS),
|
|
65
|
+
},
|
|
66
|
+
create(context) {
|
|
67
|
+
const { sourceCode } = context;
|
|
68
|
+
const options = decodeRuleOptions(UNUSED_CODE_GRANT_OPTIONS, context.options);
|
|
69
|
+
const isInTheTestHome = options?.testHome === INSIDE_THE_TEST_HOME;
|
|
70
|
+
const runUnder = (ruleId: string, ruleOptions: Context["options"]) => {
|
|
71
|
+
const rule = RULES_CODE_GRANTS_CHANGE.get(ruleId);
|
|
72
|
+
if (rule === undefined) {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
const reported = new Set<unknown>();
|
|
76
|
+
const visitor = rule.create({
|
|
77
|
+
sourceCode,
|
|
78
|
+
options: ruleOptions,
|
|
79
|
+
report: (diagnostic) => {
|
|
80
|
+
reported.add(diagnostic.node ?? diagnostic);
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
return [{ visitor, reported }];
|
|
84
|
+
};
|
|
85
|
+
const watched = (options?.permissions ?? []).map((permission) => {
|
|
86
|
+
const changed = rulesACodeGrantChanges(permission, isInTheTestHome);
|
|
87
|
+
return {
|
|
88
|
+
permission,
|
|
89
|
+
withoutTheGrant: changed
|
|
90
|
+
.filter(({ isOnWithoutTheGrant }) => isOnWithoutTheGrant)
|
|
91
|
+
.flatMap(({ ruleId }) => runUnder(ruleId, [])),
|
|
92
|
+
withTheGrant: changed.flatMap(({ ruleId, granted }) =>
|
|
93
|
+
granted === "off" ? [] : runUnder(ruleId, [granted[1]]),
|
|
94
|
+
),
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
const isUsed = ({ withoutTheGrant, withTheGrant }: (typeof watched)[number]) => {
|
|
98
|
+
const stillReported = new Set(withTheGrant.flatMap(({ reported }) => [...reported]));
|
|
99
|
+
return withoutTheGrant.some(({ reported }) =>
|
|
100
|
+
[...reported].some((node) => !stillReported.has(node)),
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
return mergedVisitors([
|
|
104
|
+
...watched.flatMap(({ withoutTheGrant, withTheGrant }) =>
|
|
105
|
+
[...withoutTheGrant, ...withTheGrant].map(({ visitor }) => visitor),
|
|
106
|
+
),
|
|
107
|
+
{
|
|
108
|
+
"Program:exit"(node) {
|
|
109
|
+
for (const grant of watched) {
|
|
110
|
+
if (!isUsed(grant)) {
|
|
111
|
+
context.report({
|
|
112
|
+
node,
|
|
113
|
+
messageId: "unusedGrant",
|
|
114
|
+
data: { permission: grant.permission },
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
]);
|
|
121
|
+
},
|
|
122
|
+
} satisfies CreateRule;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Config, Effect } from "effect";
|
|
2
|
+
|
|
3
|
+
export const PROJECT_DIRECTORY_VARIABLE = "SSHKEDA_CHECK_PROJECT_DIRECTORY";
|
|
4
|
+
|
|
5
|
+
const THE_PACKAGE_THAT_RUNS_THE_TASK = ".";
|
|
6
|
+
|
|
7
|
+
const FIRST_SCRIPT_ARGUMENT = 2;
|
|
8
|
+
|
|
9
|
+
export const projectDirectory = Config.String(PROJECT_DIRECTORY_VARIABLE).pipe(
|
|
10
|
+
Config.withDefault(THE_PACKAGE_THAT_RUNS_THE_TASK),
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export const givenArguments = Effect.sync(() => process.argv.slice(FIRST_SCRIPT_ARGUMENT));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Task } from "@sshkeda/task";
|
|
2
2
|
import { Effect, Path } from "effect";
|
|
3
3
|
|
|
4
|
+
import { projectDirectory } from "../../project-directory/index.ts";
|
|
4
5
|
import { duplicateFunctions } from "../lib/detect-duplicate-functions/index.ts";
|
|
5
6
|
import { layout } from "../lib/enforce-file-layout/index.ts";
|
|
6
7
|
import { fileTypes } from "../lib/enforce-file-types/index.ts";
|
|
@@ -8,24 +9,31 @@ import { formatting } from "../lib/format-with-bun-fmt/index.ts";
|
|
|
8
9
|
import { lintConfigFile } from "../shared/declare-lint-config-task.ts";
|
|
9
10
|
import { typeScriptConfig } from "../shared/declare-typescript-config-task.ts";
|
|
10
11
|
import { typedChecks } from "./declare-the-typed-checks-task.ts";
|
|
12
|
+
import { verifyWhereCheckWasStarted } from "./verify-where-check-was-started.ts";
|
|
11
13
|
|
|
12
14
|
const GUIDE_FILE = new URL("../../../../docs/how-to-make-check-pass.md", import.meta.url);
|
|
13
15
|
|
|
14
16
|
const pointAtTheGuide = Effect.gen(function* () {
|
|
15
17
|
const path = yield* Path.Path;
|
|
16
|
-
const guide = path.relative(
|
|
18
|
+
const guide = path.relative(
|
|
19
|
+
path.resolve(yield* projectDirectory),
|
|
20
|
+
yield* path.fromFileUrl(GUIDE_FILE),
|
|
21
|
+
);
|
|
17
22
|
yield* Effect.logError(`read ${guide} before you change the code`);
|
|
18
23
|
});
|
|
19
24
|
|
|
20
25
|
export const check: Task.Task<void> = Task.make(
|
|
21
26
|
"check",
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
Effect.andThen(
|
|
28
|
+
verifyWhereCheckWasStarted,
|
|
29
|
+
Task.allSettled([
|
|
30
|
+
typeScriptConfig,
|
|
31
|
+
lintConfigFile,
|
|
32
|
+
typedChecks,
|
|
33
|
+
formatting,
|
|
34
|
+
layout,
|
|
35
|
+
fileTypes,
|
|
36
|
+
duplicateFunctions,
|
|
37
|
+
]).pipe(Effect.tapError(() => pointAtTheGuide)),
|
|
38
|
+
),
|
|
31
39
|
);
|