@sshkeda/check 1.1.0 → 2.1.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 +7 -6
- package/docs/how-to-make-check-pass.md +4 -14
- package/package.json +4 -4
- package/src/internal/ban-abbreviated-words-in-declared-names.ts +0 -4
- package/src/internal/ban-checked-members-outside-calls.ts +8 -8
- package/src/internal/ban-comments.ts +0 -1
- package/src/internal/ban-comparing-or-switching-on-tag.ts +50 -10
- package/src/internal/ban-deadlines-inside-tests.ts +3 -4
- package/src/internal/ban-declared-values.ts +2 -5
- package/src/internal/ban-dropped-failures-detached-fibers-sleeps-and-untraced-functions.ts +0 -2
- package/src/internal/ban-failures-collected-as-results.ts +0 -4
- package/src/internal/ban-fallbacks-of-named-recoveries.ts +1 -29
- package/src/internal/ban-function-overloads.ts +0 -4
- package/src/internal/ban-global-error-in-failure-types.ts +10 -15
- package/src/internal/ban-instanceof-in-effect-recovery-callbacks.ts +17 -26
- package/src/internal/ban-let-and-effect-mutable-ref.ts +0 -8
- package/src/internal/ban-logic-in-index-files.ts +0 -3
- package/src/internal/ban-namespaces-used-without-a-member.ts +0 -3
- package/src/internal/ban-node-builtins-that-effect-replaces.ts +0 -3
- package/src/internal/ban-parsing-outside-data-without-a-schema.ts +0 -4
- package/src/internal/ban-re-exports.ts +54 -18
- package/src/internal/ban-reading-the-clock-and-sleeping-outside-effect.ts +88 -4
- package/src/internal/ban-recovering-file-system-exists.ts +300 -0
- package/src/internal/ban-retired-words-in-names.ts +1 -4
- package/src/internal/ban-retries-without-a-wait.ts +292 -0
- package/src/internal/ban-scanning-directories-with-bun-glob.ts +0 -3
- package/src/internal/ban-shebang-lines.ts +0 -4
- package/src/internal/ban-timer-globals-and-the-global-object.ts +0 -1
- package/src/internal/ban-timer-schedules-without-deadlines.ts +129 -45
- package/src/internal/ban-type-and-interface-declarations.ts +0 -4
- package/src/internal/ban-type-predicates.ts +0 -4
- package/src/internal/ban-unknown-in-function-signatures.ts +49 -13
- package/src/internal/ban-vague-error-class-names.ts +0 -4
- package/src/internal/ban-vague-file-names.ts +3 -7
- package/src/internal/ban-what-a-file-is-not-granted.ts +37 -14
- package/src/internal/ban-while-do-while-and-for-loops.ts +0 -4
- package/src/internal/ban-writing-captured-objects-inside-effect-callbacks.ts +210 -0
- package/src/internal/confine-service-declarations-to-granted-files.ts +0 -7
- package/src/internal/confine-the-stdio-service-to-terminal-output.ts +2 -16
- package/src/internal/define-the-lint-plugin-and-configs.ts +6 -0
- package/src/internal/keep-assertions-in-the-test-home-and-ban-test-runners.ts +0 -6
- package/src/internal/keep-effect-testing-helpers-in-test-files.ts +2 -14
- package/src/internal/require-a-named-const-for-compound-conditions.ts +0 -4
- package/src/internal/require-capital-snake-case-and-as-const-on-literal-constants.ts +0 -4
- package/src/internal/require-service-keys-to-end-with-their-class-name.ts +5 -2
- package/src/internal/resolve-what-an-expression-imports.ts +115 -28
- package/src/internal/visit-every-declared-name.ts +13 -0
- package/src/lib/tasks/internal/declare-the-check-task.ts +2 -0
- package/src/lib/tasks/internal/declare-the-checker-queries-task.ts +2 -1
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/index.ts +2 -1
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/check-effect-diagnostics-with-effect-tsgo.ts +17 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/decide-what-each-home-may-import.ts +62 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/find-import-boundary-violations.ts +215 -187
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/find-layer-provides-outside-program-starts.ts +13 -16
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/layer-provide-errors.ts +2 -1
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/resolve-imported-package-apis.ts +3 -1
- package/src/lib/tasks/lib/detect-duplicate-functions/index.ts +10 -0
- package/src/lib/tasks/lib/detect-duplicate-functions/internal/duplicate-function-errors.ts +23 -0
- package/src/lib/tasks/lib/detect-duplicate-functions/internal/find-duplicate-functions.ts +150 -0
- package/src/lib/tasks/lib/detect-duplicate-functions/internal/list-named-functions.ts +416 -0
- package/src/lib/tasks/lib/detect-inferrable-annotations/internal/find-inferrable-annotations.ts +31 -12
- package/src/lib/tasks/lib/enforce-file-layout/index.ts +6 -1
- package/src/lib/tasks/lib/enforce-file-layout/internal/file-layout-errors.ts +11 -1
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-export-path-mismatches.ts +39 -7
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +11 -4
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-module-layout-violations.ts +6 -4
- package/src/lib/tasks/lib/enforce-file-types/index.ts +6 -1
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/declare-the-formatting-task.ts +3 -2
- package/src/lib/tasks/lib/judge-index-re-exports/internal/find-index-re-export-violations.ts +27 -21
- package/src/lib/tasks/lib/lint-with-oxlint/index.ts +2 -1
- package/src/lib/tasks/lib/lint-with-oxlint/internal/check-lint-rules-with-oxlint.ts +11 -8
- package/src/lib/tasks/lib/lint-with-oxlint/internal/read-oxlint-json-report.ts +18 -2
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/export-placement-errors.ts +12 -1
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-export-placement-violations.ts +75 -21
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-package-entry-sources.ts +146 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-the-importer-graph.ts +24 -190
- package/src/lib/tasks/lib/refuse-disable-directives/index.ts +2 -1
- package/src/lib/tasks/lib/refuse-disable-directives/internal/find-disable-directives.ts +9 -3
- package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/internal/find-error-mappings-to-done.ts +108 -9
- package/src/lib/tasks/lib/require-separate-service-layers/internal/find-service-layer-violations.ts +1 -5
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/index.ts +2 -1
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/find-linted-files-not-type-checked.ts +2 -4
- package/src/lib/tasks/shared/check-each-nested-package.ts +13 -1
- package/src/lib/tasks/shared/classify-files-by-role.ts +12 -2
- package/src/lib/tasks/shared/count-the-line-of-an-offset.ts +20 -2
- package/src/lib/tasks/shared/create-the-module-resolver.ts +39 -23
- package/src/lib/tasks/shared/declare-lint-config-task.ts +2 -1
- package/src/lib/tasks/shared/declare-typescript-config-task.ts +30 -2
- package/src/lib/tasks/shared/find-unmet-typescript-config-requirements.ts +19 -6
- package/src/lib/tasks/shared/list-ignored-files-imported-by-source.ts +25 -16
- package/src/lib/tasks/shared/load-the-lint-config.ts +14 -12
- package/src/lib/tasks/shared/parse-config-files-that-import-from-check.ts +6 -7
- package/src/lib/tasks/shared/project-config-and-tool-errors.ts +46 -2
- package/src/lib/tasks/shared/provide-project-query-caches.ts +11 -0
- package/src/lib/tasks/shared/query-the-typescript-project.ts +108 -43
- package/src/lib/tasks/shared/resolve-absolute-paths.ts +4 -1
- package/src/lib/tasks/shared/resolve-module-requests.ts +131 -90
- package/src/lib/tasks/shared/run-tools-and-decode-their-reports.ts +15 -11
- package/src/shared/bans-each-permission-lifts.ts +4 -21
- package/src/shared/find-retired-words.ts +1 -1
- package/src/shared/lint-rule-messages-and-patterns.ts +7 -12
- package/src/shared/record-and-grant-permissions-by-path.ts +41 -65
|
@@ -2,33 +2,24 @@ import { defineRule } from "@oxlint/plugins";
|
|
|
2
2
|
import type { ESTree } from "@oxlint/plugins";
|
|
3
3
|
|
|
4
4
|
import { FORMAT_CONFIG_BINDING, FORMAT_CONFIG_FILE } from "../shared/config-file-names.ts";
|
|
5
|
-
import {
|
|
6
|
-
fileNameOf,
|
|
7
|
-
INTERNAL_DIRECTORY_NAME,
|
|
8
|
-
isEntryFileName,
|
|
9
|
-
LIBRARY_DIRECTORY_NAME,
|
|
10
|
-
SHARED_DIRECTORY_NAME,
|
|
11
|
-
} from "../shared/match-file-names-and-path-prefixes.ts";
|
|
5
|
+
import { fileNameOf, isEntryFileName } from "../shared/match-file-names-and-path-prefixes.ts";
|
|
12
6
|
import {
|
|
13
7
|
DEFAULT_EXPORT,
|
|
14
8
|
importedBindingOf,
|
|
15
9
|
importedExpression,
|
|
10
|
+
propertyKeyName,
|
|
16
11
|
resolvedVariable,
|
|
12
|
+
textOnOneLine,
|
|
17
13
|
unwrappedExpression,
|
|
18
14
|
} from "./resolve-what-an-expression-imports.ts";
|
|
19
15
|
|
|
20
|
-
const OWN_LAYOUT_DIRECTORIES = `${INTERNAL_DIRECTORY_NAME}/ and ${SHARED_DIRECTORY_NAME}/`;
|
|
21
|
-
const RE_EXPORTABLE_EXTENSIONS = ".ts or .tsx";
|
|
22
|
-
|
|
23
16
|
export const noReExports = defineRule({
|
|
24
17
|
meta: {
|
|
25
18
|
type: "suggestion",
|
|
26
|
-
docs: {
|
|
27
|
-
description: `Define each export where it is written; an exception is an index.ts or index.tsx that re-exports names, unrenamed, with export { … } from or export type { … } from a path that resolves to a ${RE_EXPORTABLE_EXTENSIONS} file, not an index or a .d.ts, directly in its own ${OWN_LAYOUT_DIRECTORIES}. An index.ts may also export * as Name from the index.ts of a module directly in its own ${LIBRARY_DIRECTORY_NAME}/ that only re-exports unrenamed names from its own internal files. export { … } or export default naming an imported binding, or export default of a direct static member of an imported binding, is a re-export too, and so is an exported declaration initialized to one of them. ${FORMAT_CONFIG_FILE} may export default the imported ${FORMAT_CONFIG_BINDING}, which the format-config check requires. The re-exports check judges where an index's export from and export * as resolve.`,
|
|
28
|
-
},
|
|
29
19
|
messages: {
|
|
30
20
|
fromModule: "export from {{source}} re-exports another module",
|
|
31
21
|
everything: "export * from {{source}} re-exports another module",
|
|
22
|
+
namespace: "export * as {{name}} from {{source}} re-exports another module",
|
|
32
23
|
importedValue: "export {{exported}} re-exports {{binding}}, imported from {{source}}",
|
|
33
24
|
importedMember:
|
|
34
25
|
"export {{exported}} re-exports {{member}}, a member of {{binding}} imported from {{source}}",
|
|
@@ -90,6 +81,37 @@ export const noReExports = defineRule({
|
|
|
90
81
|
);
|
|
91
82
|
}
|
|
92
83
|
};
|
|
84
|
+
const reportDestructuredImport = (
|
|
85
|
+
pattern: ESTree.ObjectPattern,
|
|
86
|
+
imported: NonNullable<ReturnType<typeof importedBindingOf>>,
|
|
87
|
+
) => {
|
|
88
|
+
const object = imported.member ?? imported.name;
|
|
89
|
+
for (const property of pattern.properties) {
|
|
90
|
+
const key = propertyKeyName(property);
|
|
91
|
+
if (property.type !== "Property") {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (key === undefined) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const isNamedKey = !property.computed && property.key.type === "Identifier";
|
|
98
|
+
const member = isNamedKey
|
|
99
|
+
? `${object}.${key}`
|
|
100
|
+
: `${object}[${textOnOneLine(property.key, context.sourceCode)}]`;
|
|
101
|
+
const { value } = property;
|
|
102
|
+
if (value.type === "Identifier") {
|
|
103
|
+
reportImport(
|
|
104
|
+
property,
|
|
105
|
+
value.name,
|
|
106
|
+
{ ...imported, member },
|
|
107
|
+
"initializedToImport",
|
|
108
|
+
"initializedToMember",
|
|
109
|
+
);
|
|
110
|
+
} else if (value.type === "ObjectPattern") {
|
|
111
|
+
reportDestructuredImport(value, { ...imported, member });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
93
115
|
const reportImported = (node: ESTree.Node, exported: string, value: ESTree.Node) => {
|
|
94
116
|
const imported = importedBindingOf(value, context.sourceCode);
|
|
95
117
|
if (imported !== undefined) {
|
|
@@ -105,15 +127,20 @@ export const noReExports = defineRule({
|
|
|
105
127
|
Program(program) {
|
|
106
128
|
for (const statement of program.body) {
|
|
107
129
|
if (statement.type === "ExportAllDeclaration") {
|
|
130
|
+
const source = statement.source.value;
|
|
108
131
|
const isLeftToTheReExportsCheck = isIndexFile && statement.exported !== null;
|
|
109
132
|
if (isLeftToTheReExportsCheck) {
|
|
110
133
|
continue;
|
|
111
134
|
}
|
|
112
|
-
context.report(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
135
|
+
context.report(
|
|
136
|
+
statement.exported === null
|
|
137
|
+
? { node: statement, messageId: "everything", data: { source } }
|
|
138
|
+
: {
|
|
139
|
+
node: statement,
|
|
140
|
+
messageId: "namespace",
|
|
141
|
+
data: { name: context.sourceCode.getText(statement.exported), source },
|
|
142
|
+
},
|
|
143
|
+
);
|
|
117
144
|
} else if (statement.type === "ExportNamedDeclaration") {
|
|
118
145
|
if (statement.source !== null) {
|
|
119
146
|
if (!isIndexFile) {
|
|
@@ -140,6 +167,15 @@ export const noReExports = defineRule({
|
|
|
140
167
|
if (isInitializedName) {
|
|
141
168
|
reportInitializedToImport(declarator, id.name, initializer);
|
|
142
169
|
}
|
|
170
|
+
if (id.type === "ObjectPattern") {
|
|
171
|
+
const destructured =
|
|
172
|
+
initializer === null
|
|
173
|
+
? undefined
|
|
174
|
+
: importedBindingOf(initializer, context.sourceCode);
|
|
175
|
+
if (destructured !== undefined) {
|
|
176
|
+
reportDestructuredImport(id, destructured);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
143
179
|
}
|
|
144
180
|
}
|
|
145
181
|
const importsAModule =
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { defineRule } from "@oxlint/plugins";
|
|
2
2
|
import type { ESTree, SourceCode } from "@oxlint/plugins";
|
|
3
|
+
import { Schema } from "effect";
|
|
3
4
|
|
|
4
5
|
import { moduleSpecifiersOfGlobalObject } from "../shared/bans-each-permission-lifts.ts";
|
|
6
|
+
import { decodeRuleOptions, ruleOptionsJsonSchema } from "./describe-and-decode-rule-options.ts";
|
|
5
7
|
import {
|
|
6
8
|
effectModuleReference,
|
|
7
9
|
effectOperation,
|
|
@@ -18,6 +20,7 @@ export const CLOCK_PROPERTIES = [
|
|
|
18
20
|
{ object: "Bun", property: "nanoseconds" },
|
|
19
21
|
{ object: "AbortSignal", property: "timeout" },
|
|
20
22
|
{ object: "Bun", property: "sleepSync" },
|
|
23
|
+
{ object: "Temporal", property: "Now" },
|
|
21
24
|
] as const;
|
|
22
25
|
|
|
23
26
|
const CLOCK_READS = new Set([
|
|
@@ -25,6 +28,8 @@ const CLOCK_READS = new Set([
|
|
|
25
28
|
"DateTime.isFutureUnsafe",
|
|
26
29
|
"DateTime.isPastUnsafe",
|
|
27
30
|
]);
|
|
31
|
+
const CRON_STEPS = new Set(["Cron.next", "Cron.prev", "Cron.sequence"]);
|
|
32
|
+
const ARGUMENTS_OF_A_CRON_STEP_FROM_A_TIME = 2;
|
|
28
33
|
const DATE_FORMATS = new Set(["format", "formatToParts"]);
|
|
29
34
|
export const DATE_TIME_FORMAT = "DateTimeFormat";
|
|
30
35
|
export const TIMED_WAITS = new Set(["wait", "waitAsync"]);
|
|
@@ -55,6 +60,60 @@ const isDateTimeFormatter = (node: ESTree.Node, sourceCode: SourceCode) => {
|
|
|
55
60
|
return isDateTimeFormatConstruction(initializer ?? node, sourceCode);
|
|
56
61
|
};
|
|
57
62
|
|
|
63
|
+
const CLOCK_SERVICE = "Clock.Clock";
|
|
64
|
+
const CLOCK_CALLBACK_OPERATIONS = new Set(["Effect.clockWith", "Clock.clockWith"]);
|
|
65
|
+
const CLOCK_SLEEP = "sleep";
|
|
66
|
+
const CLOCK_SERVICE_SLEEPS = ["banned", "allowed"] as const;
|
|
67
|
+
|
|
68
|
+
const CLOCK_OPTIONS = Schema.Struct({
|
|
69
|
+
clockServiceSleeps: Schema.optionalKey(Schema.Literals(CLOCK_SERVICE_SLEEPS)),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const isYieldedClockService = (node: ESTree.Node | null | undefined, sourceCode: SourceCode) =>
|
|
73
|
+
node?.type === "YieldExpression" &&
|
|
74
|
+
node.delegate &&
|
|
75
|
+
node.argument !== null &&
|
|
76
|
+
effectModuleReference(node.argument, sourceCode, "Clock") === CLOCK_SERVICE;
|
|
77
|
+
|
|
78
|
+
const isClockCallbackParameter = (parameter: ESTree.Node, sourceCode: SourceCode) => {
|
|
79
|
+
const callback = parameter.parent;
|
|
80
|
+
const call = callback?.parent;
|
|
81
|
+
const isFirstParameterOfACallback =
|
|
82
|
+
(callback?.type === "ArrowFunctionExpression" || callback?.type === "FunctionExpression") &&
|
|
83
|
+
callback.params[0] === parameter &&
|
|
84
|
+
call?.type === "CallExpression" &&
|
|
85
|
+
call.arguments[0] === callback;
|
|
86
|
+
if (!isFirstParameterOfACallback) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
const operation =
|
|
90
|
+
effectModuleReference(call.callee, sourceCode, "Effect") ??
|
|
91
|
+
effectModuleReference(call.callee, sourceCode, "Clock");
|
|
92
|
+
return operation !== undefined && CLOCK_CALLBACK_OPERATIONS.has(operation);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const isClockService = (node: ESTree.Node, sourceCode: SourceCode) => {
|
|
96
|
+
const isTheClockService =
|
|
97
|
+
isYieldedClockService(node, sourceCode) || isClockCallbackParameter(node, sourceCode);
|
|
98
|
+
if (isTheClockService) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
const variable = resolvedVariable(node, sourceCode);
|
|
102
|
+
if (variable?.references.some((reference) => reference.isWrite() && !reference.init) === true) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
const definition = variable?.defs[0];
|
|
106
|
+
if (definition?.type === "Parameter") {
|
|
107
|
+
return isClockCallbackParameter(definition.name, sourceCode);
|
|
108
|
+
}
|
|
109
|
+
const declarator = definition?.node;
|
|
110
|
+
return (
|
|
111
|
+
declarator?.type === "VariableDeclarator" &&
|
|
112
|
+
declarator.id === definition?.name &&
|
|
113
|
+
isYieldedClockService(declarator.init, sourceCode)
|
|
114
|
+
);
|
|
115
|
+
};
|
|
116
|
+
|
|
58
117
|
const isPipeFunction = (node: ESTree.Node, sourceCode: SourceCode) => {
|
|
59
118
|
const imported = importedExpression(node, sourceCode);
|
|
60
119
|
return imported?.module.startsWith("effect") === true && imported.members.at(-1) === PIPE;
|
|
@@ -63,10 +122,6 @@ const isPipeFunction = (node: ESTree.Node, sourceCode: SourceCode) => {
|
|
|
63
122
|
export const noClockReadsAndSleeps = defineRule({
|
|
64
123
|
meta: {
|
|
65
124
|
type: "problem",
|
|
66
|
-
docs: {
|
|
67
|
-
description:
|
|
68
|
-
"Read the current time through Effect Clock or DateTime, and wait on signals instead of sleeping.",
|
|
69
|
-
},
|
|
70
125
|
messages: {
|
|
71
126
|
dateCall: "calling the Date constructor is banned",
|
|
72
127
|
currentDate: "new Date() reads the current time",
|
|
@@ -76,9 +131,12 @@ export const noClockReadsAndSleeps = defineRule({
|
|
|
76
131
|
timedWait: "Atomics.{{method}} with a timeout sleeps",
|
|
77
132
|
neverTimeout: "{{usage}} on Effect.never sleeps",
|
|
78
133
|
},
|
|
134
|
+
schema: ruleOptionsJsonSchema(CLOCK_OPTIONS),
|
|
79
135
|
},
|
|
80
136
|
create(context) {
|
|
81
137
|
const { sourceCode } = context;
|
|
138
|
+
const clockServiceSleeps =
|
|
139
|
+
decodeRuleOptions(CLOCK_OPTIONS, context.options)?.clockServiceSleeps ?? "banned";
|
|
82
140
|
const isGlobalDate = (callee: ESTree.Node) => isGlobalReference(callee, sourceCode, "Date");
|
|
83
141
|
const keepsWaiting = (operation: ESTree.Node) => {
|
|
84
142
|
const operationName = effectOperation(
|
|
@@ -153,6 +211,14 @@ export const noClockReadsAndSleeps = defineRule({
|
|
|
153
211
|
messageId: "restrictedProperty",
|
|
154
212
|
data: { usage: `${restricted.object}.${restricted.property}` },
|
|
155
213
|
});
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const sleepsThroughTheClockService =
|
|
217
|
+
clockServiceSleeps === "banned" &&
|
|
218
|
+
name === CLOCK_SLEEP &&
|
|
219
|
+
isClockService(receiver, sourceCode);
|
|
220
|
+
if (sleepsThroughTheClockService) {
|
|
221
|
+
context.report({ node, messageId: "restrictedProperty", data: { usage: "Clock.sleep" } });
|
|
156
222
|
}
|
|
157
223
|
};
|
|
158
224
|
|
|
@@ -192,6 +258,19 @@ export const noClockReadsAndSleeps = defineRule({
|
|
|
192
258
|
context.report({ node, messageId: "neverTimeout", data: { usage: `Effect.${timeout}` } });
|
|
193
259
|
return;
|
|
194
260
|
}
|
|
261
|
+
const cronStep = effectModuleReference(node.callee, sourceCode, "Cron");
|
|
262
|
+
const startTime = node.arguments[ARGUMENTS_OF_A_CRON_STEP_FROM_A_TIME - 1];
|
|
263
|
+
const hasNoStartTime =
|
|
264
|
+
startTime === undefined || isGlobalReference(startTime, sourceCode, "undefined");
|
|
265
|
+
const stepsFromTheCurrentTime =
|
|
266
|
+
cronStep !== undefined &&
|
|
267
|
+
CRON_STEPS.has(cronStep) &&
|
|
268
|
+
hasNoStartTime &&
|
|
269
|
+
node.arguments.every((argument) => argument.type !== "SpreadElement");
|
|
270
|
+
if (stepsFromTheCurrentTime) {
|
|
271
|
+
context.report({ node, messageId: "clockRead", data: { usage: cronStep } });
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
195
274
|
if (node.callee.type !== "MemberExpression") {
|
|
196
275
|
return;
|
|
197
276
|
}
|
|
@@ -234,6 +313,11 @@ export const noClockReadsAndSleeps = defineRule({
|
|
|
234
313
|
AssignmentExpression(node) {
|
|
235
314
|
reportDestructuredProperties(node.left, node.right);
|
|
236
315
|
},
|
|
316
|
+
ObjectPattern(node) {
|
|
317
|
+
if (isClockCallbackParameter(node, sourceCode)) {
|
|
318
|
+
reportDestructuredProperties(node, node);
|
|
319
|
+
}
|
|
320
|
+
},
|
|
237
321
|
};
|
|
238
322
|
},
|
|
239
323
|
});
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import type { ESTree, SourceCode } from "@oxlint/plugins";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
constantValue,
|
|
6
|
+
effectOperation,
|
|
7
|
+
importedExpression,
|
|
8
|
+
isPipeFunction,
|
|
9
|
+
memberName,
|
|
10
|
+
propertyKeyName,
|
|
11
|
+
resolvedVariable,
|
|
12
|
+
returnedExpression,
|
|
13
|
+
staticKeyName,
|
|
14
|
+
unwrappedExpression,
|
|
15
|
+
} from "./resolve-what-an-expression-imports.ts";
|
|
16
|
+
|
|
17
|
+
const EXISTS = "exists";
|
|
18
|
+
|
|
19
|
+
const PIPE = "pipe";
|
|
20
|
+
|
|
21
|
+
const PLATFORM_ERROR = "PlatformError";
|
|
22
|
+
|
|
23
|
+
const OPERATIONS_THAT_KEEP_THE_FAILURES = new Set(["map", "as"]);
|
|
24
|
+
|
|
25
|
+
const SUCCEEDING_OPERATIONS = new Set(["succeed", "succeedSome"]);
|
|
26
|
+
|
|
27
|
+
const SUCCEEDING_VALUES = new Set(["void", "succeedNone"]);
|
|
28
|
+
|
|
29
|
+
const isFileSystemTag = (node: ESTree.Node, sourceCode: SourceCode) => {
|
|
30
|
+
const imported = importedExpression(node, sourceCode);
|
|
31
|
+
const path = imported?.members.join(".");
|
|
32
|
+
return (
|
|
33
|
+
(imported?.module === "effect" && path === "FileSystem.FileSystem") ||
|
|
34
|
+
(imported?.module === "effect/FileSystem" && path === "FileSystem")
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const isYieldedFileSystem = (node: ESTree.Node, sourceCode: SourceCode) => {
|
|
39
|
+
const value = unwrappedExpression(node);
|
|
40
|
+
return (
|
|
41
|
+
value.type === "YieldExpression" &&
|
|
42
|
+
value.delegate &&
|
|
43
|
+
value.argument !== null &&
|
|
44
|
+
isFileSystemTag(value.argument, sourceCode)
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const yieldedFileSystemBinding = (node: ESTree.Node, sourceCode: SourceCode) => {
|
|
49
|
+
const definitions = resolvedVariable(node, sourceCode)?.defs ?? [];
|
|
50
|
+
const declarator = definitions.length === 1 ? definitions[0]?.node : undefined;
|
|
51
|
+
const isConstantDeclarator =
|
|
52
|
+
declarator?.type === "VariableDeclarator" &&
|
|
53
|
+
declarator.parent.type === "VariableDeclaration" &&
|
|
54
|
+
declarator.parent.kind === "const";
|
|
55
|
+
const initializer = isConstantDeclarator ? declarator.init : null;
|
|
56
|
+
const binding = isConstantDeclarator ? declarator.id : undefined;
|
|
57
|
+
if (initializer === null) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
return isYieldedFileSystem(initializer, sourceCode) ? binding : undefined;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const isFileSystemExists = (callee: ESTree.Node, sourceCode: SourceCode) => {
|
|
64
|
+
const node = unwrappedExpression(callee);
|
|
65
|
+
if (node.type === "MemberExpression") {
|
|
66
|
+
if (memberName(node) !== EXISTS) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return (
|
|
70
|
+
isYieldedFileSystem(node.object, sourceCode) ||
|
|
71
|
+
yieldedFileSystemBinding(node.object, sourceCode)?.type === "Identifier"
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
if (node.type !== "Identifier") {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
const pattern = yieldedFileSystemBinding(node, sourceCode);
|
|
78
|
+
return (
|
|
79
|
+
pattern?.type === "ObjectPattern" &&
|
|
80
|
+
pattern.properties.some(
|
|
81
|
+
(property) =>
|
|
82
|
+
property.type === "Property" &&
|
|
83
|
+
propertyKeyName(property) === EXISTS &&
|
|
84
|
+
property.value.type === "Identifier" &&
|
|
85
|
+
property.value.name === node.name,
|
|
86
|
+
)
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const succeeds = (handler: ESTree.Node | undefined, sourceCode: SourceCode) => {
|
|
91
|
+
const resolved = handler === undefined ? undefined : constantValue(handler, sourceCode);
|
|
92
|
+
const handlerOperation =
|
|
93
|
+
resolved === undefined ? undefined : effectOperation(resolved, sourceCode);
|
|
94
|
+
if (handlerOperation !== undefined) {
|
|
95
|
+
return SUCCEEDING_OPERATIONS.has(handlerOperation);
|
|
96
|
+
}
|
|
97
|
+
const returned = returnedExpression(resolved);
|
|
98
|
+
if (returned === undefined) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
const value = constantValue(returned, sourceCode);
|
|
102
|
+
if (value.type === "CallExpression") {
|
|
103
|
+
const operation = effectOperation(value.callee, sourceCode);
|
|
104
|
+
return operation !== undefined && SUCCEEDING_OPERATIONS.has(operation);
|
|
105
|
+
}
|
|
106
|
+
const operation = effectOperation(value, sourceCode);
|
|
107
|
+
return operation !== undefined && SUCCEEDING_VALUES.has(operation);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const namesPlatformError = (tags: ESTree.Node | undefined, sourceCode: SourceCode) => {
|
|
111
|
+
if (tags === undefined) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
const value = constantValue(tags, sourceCode);
|
|
115
|
+
if (value.type === "ArrayExpression") {
|
|
116
|
+
return value.elements.some(
|
|
117
|
+
(element) =>
|
|
118
|
+
element !== null && staticKeyName(constantValue(element, sourceCode)) === PLATFORM_ERROR,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
return staticKeyName(value) === PLATFORM_ERROR;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const effectivePlatformErrorHandler = (properties: readonly ESTree.Node[]) => {
|
|
125
|
+
const last = properties.findLast(
|
|
126
|
+
(property) =>
|
|
127
|
+
property.type === "SpreadElement" ||
|
|
128
|
+
propertyKeyName(property) === undefined ||
|
|
129
|
+
propertyKeyName(property) === PLATFORM_ERROR,
|
|
130
|
+
);
|
|
131
|
+
if (last?.type !== "Property") {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
return propertyKeyName(last) === PLATFORM_ERROR ? last.value : undefined;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const recoversPlatformErrorWithASuccess = (
|
|
138
|
+
handlers: ESTree.Node | undefined,
|
|
139
|
+
sourceCode: SourceCode,
|
|
140
|
+
) => {
|
|
141
|
+
const value = handlers === undefined ? undefined : unwrappedExpression(handlers);
|
|
142
|
+
return (
|
|
143
|
+
value?.type === "ObjectExpression" &&
|
|
144
|
+
succeeds(effectivePlatformErrorHandler(value.properties), sourceCode)
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const catchTagSwallows = (callArguments: readonly ESTree.Node[], sourceCode: SourceCode) =>
|
|
149
|
+
namesPlatformError(callArguments[0], sourceCode) && succeeds(callArguments[1], sourceCode);
|
|
150
|
+
|
|
151
|
+
const catchTagsSwallows = (callArguments: readonly ESTree.Node[], sourceCode: SourceCode) =>
|
|
152
|
+
recoversPlatformErrorWithASuccess(callArguments[0], sourceCode);
|
|
153
|
+
|
|
154
|
+
const handlerSwallows = (callArguments: readonly ESTree.Node[], sourceCode: SourceCode) =>
|
|
155
|
+
succeeds(callArguments[0], sourceCode);
|
|
156
|
+
|
|
157
|
+
const alwaysSwallows = () => true;
|
|
158
|
+
|
|
159
|
+
const RECOVERIES = new Map([
|
|
160
|
+
["catchTag", { arity: 2, swallows: catchTagSwallows }],
|
|
161
|
+
["catchTags", { arity: 1, swallows: catchTagsSwallows }],
|
|
162
|
+
["catch", { arity: 1, swallows: handlerSwallows }],
|
|
163
|
+
["catchEager", { arity: 1, swallows: handlerSwallows }],
|
|
164
|
+
["catchCause", { arity: 1, swallows: handlerSwallows }],
|
|
165
|
+
["orElse", { arity: 1, swallows: handlerSwallows }],
|
|
166
|
+
["orElseSucceed", { arity: 1, swallows: alwaysSwallows }],
|
|
167
|
+
["option", { arity: 0, swallows: alwaysSwallows }],
|
|
168
|
+
]);
|
|
169
|
+
|
|
170
|
+
const stepOperation = (step: ESTree.Node, sourceCode: SourceCode) => {
|
|
171
|
+
const node = constantValue(step, sourceCode);
|
|
172
|
+
if (node.type === "CallExpression") {
|
|
173
|
+
return {
|
|
174
|
+
operation: effectOperation(node.callee, sourceCode),
|
|
175
|
+
callArguments: node.arguments,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
return { operation: effectOperation(node, sourceCode), callArguments: [] };
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const swallowingRecovery = (
|
|
182
|
+
operation: string | undefined,
|
|
183
|
+
callArguments: readonly ESTree.Node[],
|
|
184
|
+
sourceCode: SourceCode,
|
|
185
|
+
) => {
|
|
186
|
+
const recovery = operation === undefined ? undefined : RECOVERIES.get(operation);
|
|
187
|
+
const isSpread = callArguments.some((argument) => argument.type === "SpreadElement");
|
|
188
|
+
const isSwallowing =
|
|
189
|
+
recovery !== undefined &&
|
|
190
|
+
!isSpread &&
|
|
191
|
+
callArguments.length >= recovery.arity &&
|
|
192
|
+
recovery.swallows(callArguments, sourceCode);
|
|
193
|
+
return isSwallowing ? operation : undefined;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const keepsTheFailures = (operation: string | undefined, callArguments: readonly ESTree.Node[]) =>
|
|
197
|
+
operation !== undefined &&
|
|
198
|
+
OPERATIONS_THAT_KEEP_THE_FAILURES.has(operation) &&
|
|
199
|
+
callArguments.length === 1;
|
|
200
|
+
|
|
201
|
+
const recoveryAmongSteps = (
|
|
202
|
+
steps: readonly ESTree.Node[],
|
|
203
|
+
sourceCode: SourceCode,
|
|
204
|
+
): { readonly recovery?: string; readonly isEveryStepKeepingTheFailures: boolean } => {
|
|
205
|
+
const [step, ...rest] = steps;
|
|
206
|
+
if (step === undefined) {
|
|
207
|
+
return { isEveryStepKeepingTheFailures: true };
|
|
208
|
+
}
|
|
209
|
+
const { operation, callArguments } = stepOperation(step, sourceCode);
|
|
210
|
+
const recovery = swallowingRecovery(operation, callArguments, sourceCode);
|
|
211
|
+
if (recovery !== undefined) {
|
|
212
|
+
return { recovery, isEveryStepKeepingTheFailures: false };
|
|
213
|
+
}
|
|
214
|
+
return keepsTheFailures(operation, callArguments)
|
|
215
|
+
? recoveryAmongSteps(rest, sourceCode)
|
|
216
|
+
: { isEveryStepKeepingTheFailures: false };
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const recoveryOf = (effect: ESTree.Node, sourceCode: SourceCode): string | undefined => {
|
|
220
|
+
const { parent } = effect;
|
|
221
|
+
const isWrappedByTypeScript =
|
|
222
|
+
parent?.type === "TSAsExpression" ||
|
|
223
|
+
parent?.type === "TSSatisfiesExpression" ||
|
|
224
|
+
parent?.type === "TSNonNullExpression";
|
|
225
|
+
if (isWrappedByTypeScript) {
|
|
226
|
+
return recoveryOf(parent, sourceCode);
|
|
227
|
+
}
|
|
228
|
+
const call = parent?.parent;
|
|
229
|
+
const isPipeMethod =
|
|
230
|
+
parent?.type === "MemberExpression" &&
|
|
231
|
+
parent.object === effect &&
|
|
232
|
+
memberName(parent) === PIPE &&
|
|
233
|
+
call?.type === "CallExpression" &&
|
|
234
|
+
call.callee === parent;
|
|
235
|
+
if (isPipeMethod) {
|
|
236
|
+
const { recovery, isEveryStepKeepingTheFailures } = recoveryAmongSteps(
|
|
237
|
+
call.arguments,
|
|
238
|
+
sourceCode,
|
|
239
|
+
);
|
|
240
|
+
return isEveryStepKeepingTheFailures ? recoveryOf(call, sourceCode) : recovery;
|
|
241
|
+
}
|
|
242
|
+
const isFirstArgument = parent?.type === "CallExpression" && parent.arguments[0] === effect;
|
|
243
|
+
if (!isFirstArgument) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const isAppliedStep =
|
|
247
|
+
constantValue(parent.callee, sourceCode).type === "CallExpression" &&
|
|
248
|
+
parent.arguments.length === 1;
|
|
249
|
+
if (isAppliedStep) {
|
|
250
|
+
const { recovery, isEveryStepKeepingTheFailures } = recoveryAmongSteps(
|
|
251
|
+
[parent.callee],
|
|
252
|
+
sourceCode,
|
|
253
|
+
);
|
|
254
|
+
return isEveryStepKeepingTheFailures ? recoveryOf(parent, sourceCode) : recovery;
|
|
255
|
+
}
|
|
256
|
+
if (isPipeFunction(parent.callee, sourceCode)) {
|
|
257
|
+
const { recovery, isEveryStepKeepingTheFailures } = recoveryAmongSteps(
|
|
258
|
+
parent.arguments.slice(1),
|
|
259
|
+
sourceCode,
|
|
260
|
+
);
|
|
261
|
+
return isEveryStepKeepingTheFailures ? recoveryOf(parent, sourceCode) : recovery;
|
|
262
|
+
}
|
|
263
|
+
const operation = effectOperation(parent.callee, sourceCode);
|
|
264
|
+
const dataLastArguments = parent.arguments.slice(1);
|
|
265
|
+
const isDataFirstRecovery =
|
|
266
|
+
operation !== undefined && RECOVERIES.get(operation)?.arity === dataLastArguments.length;
|
|
267
|
+
const recovery = isDataFirstRecovery
|
|
268
|
+
? swallowingRecovery(operation, dataLastArguments, sourceCode)
|
|
269
|
+
: undefined;
|
|
270
|
+
if (recovery !== undefined) {
|
|
271
|
+
return recovery;
|
|
272
|
+
}
|
|
273
|
+
return keepsTheFailures(operation, dataLastArguments)
|
|
274
|
+
? recoveryOf(parent, sourceCode)
|
|
275
|
+
: undefined;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
export const noExistsRecovery = defineRule({
|
|
279
|
+
meta: {
|
|
280
|
+
type: "problem",
|
|
281
|
+
messages: {
|
|
282
|
+
recovered:
|
|
283
|
+
"Effect.{{recovery}} turns a real failure of exists into an answer; exists already answers false for a missing path",
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
create(context) {
|
|
287
|
+
const { sourceCode } = context;
|
|
288
|
+
return {
|
|
289
|
+
CallExpression(node) {
|
|
290
|
+
if (!isFileSystemExists(node.callee, sourceCode)) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const recovery = recoveryOf(node, sourceCode);
|
|
294
|
+
if (recovery !== undefined) {
|
|
295
|
+
context.report({ node, messageId: "recovered", data: { recovery } });
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
},
|
|
300
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineRule } from "@oxlint/plugins";
|
|
2
2
|
import type { ESTree } from "@oxlint/plugins";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { retiredWordIn } from "../shared/find-retired-words.ts";
|
|
5
5
|
import { fileNameOf } from "../shared/match-file-names-and-path-prefixes.ts";
|
|
6
6
|
import { fileNameWords, identifierWords } from "./split-names-into-words.ts";
|
|
7
7
|
import { declaredNameListeners } from "./visit-every-declared-name.ts";
|
|
@@ -11,9 +11,6 @@ const wordsOf = (name: string) => identifierWords(name).map((word) => word.text)
|
|
|
11
11
|
export const noRetiredWords = defineRule({
|
|
12
12
|
meta: {
|
|
13
13
|
type: "suggestion",
|
|
14
|
-
docs: {
|
|
15
|
-
description: `Disallow the retired words ${[...RETIRED_WORDS].join(", ")} in the names a file declares and in its file name.`,
|
|
16
|
-
},
|
|
17
14
|
messages: {
|
|
18
15
|
name: "`{{name}}` uses the retired word {{word}}",
|
|
19
16
|
fileName: "file name {{fileName}} uses the retired word {{word}}",
|