@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.
Files changed (167) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +156 -2
  3. package/docs/how-to-make-check-pass.md +71 -0
  4. package/package.json +51 -4
  5. package/src/index.ts +8 -0
  6. package/src/internal/ban-abbreviated-words-in-declared-names.ts +165 -0
  7. package/src/internal/ban-checked-members-outside-calls.ts +151 -0
  8. package/src/internal/ban-comments.ts +23 -0
  9. package/src/internal/ban-comparing-or-switching-on-tag.ts +114 -0
  10. package/src/internal/ban-deadlines-inside-tests.ts +41 -0
  11. package/src/internal/ban-declared-values.ts +70 -0
  12. package/src/internal/ban-dropped-failures-detached-fibers-sleeps-and-untraced-functions.ts +67 -0
  13. package/src/internal/ban-failures-collected-as-results.ts +57 -0
  14. package/src/internal/ban-fallbacks-of-named-recoveries.ts +118 -0
  15. package/src/internal/ban-function-overloads.ts +107 -0
  16. package/src/internal/ban-global-error-in-failure-types.ts +146 -0
  17. package/src/internal/ban-instanceof-in-effect-recovery-callbacks.ts +63 -0
  18. package/src/internal/ban-let-and-effect-mutable-ref.ts +79 -0
  19. package/src/internal/ban-logic-in-index-files.ts +178 -0
  20. package/src/internal/ban-namespaces-used-without-a-member.ts +176 -0
  21. package/src/internal/ban-node-builtins-that-effect-replaces.ts +42 -0
  22. package/src/internal/ban-parsing-outside-data-without-a-schema.ts +299 -0
  23. package/src/internal/ban-re-exports.ts +172 -0
  24. package/src/internal/ban-reading-the-clock-and-sleeping-outside-effect.ts +239 -0
  25. package/src/internal/ban-retired-words-in-names.ts +49 -0
  26. package/src/internal/ban-scanning-directories-with-bun-glob.ts +79 -0
  27. package/src/internal/ban-shebang-lines.ts +26 -0
  28. package/src/internal/ban-timer-globals-and-the-global-object.ts +34 -0
  29. package/src/internal/ban-timer-schedules-without-deadlines.ts +240 -0
  30. package/src/internal/ban-type-and-interface-declarations.ts +48 -0
  31. package/src/internal/ban-type-predicates.ts +82 -0
  32. package/src/internal/ban-unknown-in-function-signatures.ts +143 -0
  33. package/src/internal/ban-vague-error-class-names.ts +28 -0
  34. package/src/internal/ban-vague-file-names.ts +51 -0
  35. package/src/internal/ban-what-a-file-is-not-granted.ts +512 -0
  36. package/src/internal/ban-while-do-while-and-for-loops.ts +27 -0
  37. package/src/internal/confine-service-declarations-to-granted-files.ts +116 -0
  38. package/src/internal/confine-the-stdio-service-to-terminal-output.ts +190 -0
  39. package/src/internal/define-the-lint-plugin-and-configs.ts +361 -0
  40. package/src/internal/describe-and-decode-rule-options.ts +22 -0
  41. package/src/internal/keep-assertions-in-the-test-home-and-ban-test-runners.ts +128 -0
  42. package/src/internal/keep-effect-testing-helpers-in-test-files.ts +157 -0
  43. package/src/internal/match-banned-modules-and-globals.ts +71 -0
  44. package/src/internal/match-effect-service-factories.ts +20 -0
  45. package/src/internal/require-a-named-const-for-compound-conditions.ts +44 -0
  46. package/src/internal/require-capital-snake-case-and-as-const-on-literal-constants.ts +141 -0
  47. package/src/internal/require-service-keys-to-end-with-their-class-name.ts +64 -0
  48. package/src/internal/resolve-what-an-expression-imports.ts +295 -0
  49. package/src/internal/sort-type-constituents.ts +82 -0
  50. package/src/internal/split-names-into-words.ts +12 -0
  51. package/src/internal/visit-every-declared-name.ts +264 -0
  52. package/src/lib/tasks/index.ts +1 -0
  53. package/src/lib/tasks/internal/declare-the-check-task.ts +29 -0
  54. package/src/lib/tasks/internal/declare-the-checker-queries-task.ts +41 -0
  55. package/src/lib/tasks/internal/declare-the-typed-checks-task.ts +25 -0
  56. package/src/lib/tasks/internal/run-checks-over-one-typescript-project.ts +68 -0
  57. package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/index.ts +15 -0
  58. package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/check-effect-diagnostics-with-effect-tsgo.ts +211 -0
  59. package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/read-effect-tsgo-json-report.ts +39 -0
  60. package/src/lib/tasks/lib/check-import-boundaries/index.ts +1 -0
  61. package/src/lib/tasks/lib/check-import-boundaries/internal/find-import-boundary-violations.ts +415 -0
  62. package/src/lib/tasks/lib/check-import-boundaries/internal/find-subpath-import-targets.ts +117 -0
  63. package/src/lib/tasks/lib/check-import-boundaries/internal/find-what-hides-an-import.ts +65 -0
  64. package/src/lib/tasks/lib/check-import-boundaries/internal/import-boundary-errors.ts +176 -0
  65. package/src/lib/tasks/lib/check-uses-by-their-declarations/index.ts +1 -0
  66. package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/declared-use-errors.ts +32 -0
  67. package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/find-declared-use-violations.ts +38 -0
  68. package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/find-sync-calls.ts +23 -0
  69. package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/find-type-only-schemas.ts +375 -0
  70. package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/index.ts +1 -0
  71. package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/find-layer-provides-outside-program-starts.ts +648 -0
  72. package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/layer-provide-errors.ts +27 -0
  73. package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/resolve-imported-package-apis.ts +262 -0
  74. package/src/lib/tasks/lib/confine-stdio-to-granted-files/index.ts +1 -0
  75. package/src/lib/tasks/lib/confine-stdio-to-granted-files/internal/find-ungranted-stdio-uses.ts +219 -0
  76. package/src/lib/tasks/lib/confine-stdio-to-granted-files/internal/stdio-use-errors.ts +31 -0
  77. package/src/lib/tasks/lib/detect-inferrable-annotations/index.ts +1 -0
  78. package/src/lib/tasks/lib/detect-inferrable-annotations/internal/find-inferrable-annotations.ts +357 -0
  79. package/src/lib/tasks/lib/detect-inferrable-annotations/internal/inferrable-annotation-errors.ts +33 -0
  80. package/src/lib/tasks/lib/detect-repeated-service-yields/index.ts +1 -0
  81. package/src/lib/tasks/lib/detect-repeated-service-yields/internal/find-repeated-service-yields.ts +162 -0
  82. package/src/lib/tasks/lib/detect-repeated-service-yields/internal/repeated-service-yield-errors.ts +25 -0
  83. package/src/lib/tasks/lib/enforce-file-layout/index.ts +5 -0
  84. package/src/lib/tasks/lib/enforce-file-layout/internal/check-the-layout-of-each-package.ts +9 -0
  85. package/src/lib/tasks/lib/enforce-file-layout/internal/file-layout-errors.ts +417 -0
  86. package/src/lib/tasks/lib/enforce-file-layout/internal/find-export-path-mismatches.ts +83 -0
  87. package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +827 -0
  88. package/src/lib/tasks/lib/enforce-file-layout/internal/find-module-layout-violations.ts +82 -0
  89. package/src/lib/tasks/lib/enforce-file-layout/internal/resolve-task-imports.ts +178 -0
  90. package/src/lib/tasks/lib/enforce-file-types/index.ts +5 -0
  91. package/src/lib/tasks/lib/enforce-file-types/internal/file-type-errors.ts +21 -0
  92. package/src/lib/tasks/lib/enforce-file-types/internal/find-file-type-violations.ts +78 -0
  93. package/src/lib/tasks/lib/format-with-bun-fmt/index.ts +1 -0
  94. package/src/lib/tasks/lib/format-with-bun-fmt/internal/check-formatting-with-bun-fmt.ts +157 -0
  95. package/src/lib/tasks/lib/format-with-bun-fmt/internal/declare-the-formatting-task.ts +66 -0
  96. package/src/lib/tasks/lib/format-with-bun-fmt/internal/find-format-config-violations.ts +16 -0
  97. package/src/lib/tasks/lib/format-with-bun-fmt/internal/find-format-input-violations.ts +74 -0
  98. package/src/lib/tasks/lib/format-with-bun-fmt/internal/find-symbolic-links.ts +14 -0
  99. package/src/lib/tasks/lib/format-with-bun-fmt/internal/unformatted-file-errors.ts +12 -0
  100. package/src/lib/tasks/lib/judge-index-re-exports/index.ts +1 -0
  101. package/src/lib/tasks/lib/judge-index-re-exports/internal/find-index-re-export-violations.ts +353 -0
  102. package/src/lib/tasks/lib/judge-index-re-exports/internal/index-re-export-errors.ts +21 -0
  103. package/src/lib/tasks/lib/lint-with-oxlint/index.ts +15 -0
  104. package/src/lib/tasks/lib/lint-with-oxlint/internal/check-lint-rules-with-oxlint.ts +123 -0
  105. package/src/lib/tasks/lib/lint-with-oxlint/internal/check-unsafe-enum-assignments.ts +152 -0
  106. package/src/lib/tasks/lib/lint-with-oxlint/internal/find-tsgolint-executable.ts +21 -0
  107. package/src/lib/tasks/lib/lint-with-oxlint/internal/read-oxlint-json-report.ts +82 -0
  108. package/src/lib/tasks/lib/lint-with-oxlint/internal/read-tsgolint-rule-messages.ts +68 -0
  109. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/index.ts +1 -0
  110. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/export-placement-errors.ts +135 -0
  111. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-export-placement-violations.ts +507 -0
  112. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-misplaced-files.ts +116 -0
  113. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-subdivided-directories.ts +29 -0
  114. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-the-importer-graph.ts +451 -0
  115. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/list-binding-names.ts +49 -0
  116. package/src/lib/tasks/lib/refuse-disable-directives/index.ts +15 -0
  117. package/src/lib/tasks/lib/refuse-disable-directives/internal/disable-directive-errors.ts +45 -0
  118. package/src/lib/tasks/lib/refuse-disable-directives/internal/find-disable-directives.ts +66 -0
  119. package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/index.ts +1 -0
  120. package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/internal/error-mapping-errors.ts +21 -0
  121. package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/internal/find-error-mappings-to-done.ts +135 -0
  122. package/src/lib/tasks/lib/require-separate-service-layers/index.ts +1 -0
  123. package/src/lib/tasks/lib/require-separate-service-layers/internal/find-service-layer-violations.ts +170 -0
  124. package/src/lib/tasks/lib/require-separate-service-layers/internal/service-layer-errors.ts +21 -0
  125. package/src/lib/tasks/lib/require-type-checking-every-linted-file/index.ts +14 -0
  126. package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/find-linted-files-not-type-checked.ts +117 -0
  127. package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/linted-file-errors.ts +51 -0
  128. package/src/lib/tasks/lib/type-check-with-bun-check/index.ts +11 -0
  129. package/src/lib/tasks/lib/type-check-with-bun-check/internal/check-types-with-bun-check.ts +54 -0
  130. package/src/lib/tasks/lib/type-check-with-bun-check/internal/read-bun-check-output.ts +73 -0
  131. package/src/lib/tasks/lib/type-check-with-bun-check/internal/type-check-errors.ts +10 -0
  132. package/src/lib/tasks/shared/check-each-nested-package.ts +79 -0
  133. package/src/lib/tasks/shared/classify-files-by-role.ts +115 -0
  134. package/src/lib/tasks/shared/count-the-line-of-an-offset.ts +2 -0
  135. package/src/lib/tasks/shared/create-the-module-resolver.ts +38 -0
  136. package/src/lib/tasks/shared/declare-lint-config-task.ts +13 -0
  137. package/src/lib/tasks/shared/declare-typescript-config-task.ts +18 -0
  138. package/src/lib/tasks/shared/encode-compact-json.ts +5 -0
  139. package/src/lib/tasks/shared/find-installed-package-binaries.ts +62 -0
  140. package/src/lib/tasks/shared/find-module-requests.ts +482 -0
  141. package/src/lib/tasks/shared/find-named-package-manifests.ts +94 -0
  142. package/src/lib/tasks/shared/find-unmet-typescript-config-requirements.ts +60 -0
  143. package/src/lib/tasks/shared/list-ignored-files-imported-by-source.ts +79 -0
  144. package/src/lib/tasks/shared/list-linted-files.ts +28 -0
  145. package/src/lib/tasks/shared/list-owned-files.ts +13 -0
  146. package/src/lib/tasks/shared/list-package-files.ts +66 -0
  147. package/src/lib/tasks/shared/load-the-lint-config.ts +176 -0
  148. package/src/lib/tasks/shared/match-granted-patch-files.ts +88 -0
  149. package/src/lib/tasks/shared/parse-config-files-that-import-from-check.ts +310 -0
  150. package/src/lib/tasks/shared/print-failures-and-keep-detail-in-the-trace.ts +99 -0
  151. package/src/lib/tasks/shared/project-config-and-tool-errors.ts +485 -0
  152. package/src/lib/tasks/shared/query-the-typescript-project.ts +635 -0
  153. package/src/lib/tasks/shared/read-named-package-manifests.ts +53 -0
  154. package/src/lib/tasks/shared/read-package-manifest-object.ts +28 -0
  155. package/src/lib/tasks/shared/resolve-absolute-paths.ts +4 -0
  156. package/src/lib/tasks/shared/resolve-module-requests.ts +121 -0
  157. package/src/lib/tasks/shared/run-tools-and-decode-their-reports.ts +98 -0
  158. package/src/lib/tasks/shared/tool-file-locations.ts +38 -0
  159. package/src/shared/bans-each-permission-lifts.ts +454 -0
  160. package/src/shared/config-file-names.ts +3 -0
  161. package/src/shared/find-retired-words.ts +17 -0
  162. package/src/shared/format-reported-failures.ts +31 -0
  163. package/src/shared/lint-rule-messages-and-patterns.ts +104 -0
  164. package/src/shared/match-file-names-and-path-prefixes.ts +18 -0
  165. package/src/shared/permission-grant-errors.ts +42 -0
  166. package/src/shared/record-and-grant-permissions-by-path.ts +419 -0
  167. package/src/shared/test-home-directories.ts +4 -0
@@ -0,0 +1,239 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import type { ESTree, SourceCode } from "@oxlint/plugins";
3
+
4
+ import { moduleSpecifiersOfGlobalObject } from "../shared/bans-each-permission-lifts.ts";
5
+ import {
6
+ effectModuleReference,
7
+ effectOperation,
8
+ importedExpression,
9
+ isGlobalReference,
10
+ memberName,
11
+ propertyKeyName,
12
+ resolvedVariable,
13
+ } from "./resolve-what-an-expression-imports.ts";
14
+
15
+ export const CLOCK_PROPERTIES = [
16
+ { object: "process", property: "hrtime" },
17
+ { object: "process", property: "uptime" },
18
+ { object: "Bun", property: "nanoseconds" },
19
+ { object: "AbortSignal", property: "timeout" },
20
+ { object: "Bun", property: "sleepSync" },
21
+ ] as const;
22
+
23
+ const CLOCK_READS = new Set([
24
+ "DateTime.nowUnsafe",
25
+ "DateTime.isFutureUnsafe",
26
+ "DateTime.isPastUnsafe",
27
+ ]);
28
+ const DATE_FORMATS = new Set(["format", "formatToParts"]);
29
+ export const DATE_TIME_FORMAT = "DateTimeFormat";
30
+ export const TIMED_WAITS = new Set(["wait", "waitAsync"]);
31
+ const ARGUMENTS_OF_A_TIMED_WAIT = 4;
32
+ const UNTIMED_WAIT_TIMEOUTS = ["undefined", "Infinity"] as const;
33
+ const EFFECT_TIMEOUTS = new Set(["timeout", "timeoutOption", "timeoutOrElse"]);
34
+ const PIPE = "pipe";
35
+ const OPERATIONS_THAT_KEEP_WAITING = new Set(["onInterrupt", "ensuring", "onExit", "asVoid", "as"]);
36
+
37
+ const isDateTimeFormatConstruction = (node: ESTree.Node, sourceCode: SourceCode) => {
38
+ const isConstruction = node.type === "NewExpression" || node.type === "CallExpression";
39
+ return (
40
+ isConstruction &&
41
+ node.callee.type === "MemberExpression" &&
42
+ memberName(node.callee) === DATE_TIME_FORMAT &&
43
+ isGlobalReference(node.callee.object, sourceCode, "Intl")
44
+ );
45
+ };
46
+
47
+ const isDateTimeFormatter = (node: ESTree.Node, sourceCode: SourceCode) => {
48
+ const variable = resolvedVariable(node, sourceCode);
49
+ if (variable?.references.some((reference) => reference.isWrite() && !reference.init) === true) {
50
+ return false;
51
+ }
52
+ const declarator = variable?.defs[0]?.node;
53
+ const initializer =
54
+ declarator?.type === "VariableDeclarator" ? (declarator.init ?? undefined) : undefined;
55
+ return isDateTimeFormatConstruction(initializer ?? node, sourceCode);
56
+ };
57
+
58
+ const isPipeFunction = (node: ESTree.Node, sourceCode: SourceCode) => {
59
+ const imported = importedExpression(node, sourceCode);
60
+ return imported?.module.startsWith("effect") === true && imported.members.at(-1) === PIPE;
61
+ };
62
+
63
+ export const noClockReadsAndSleeps = defineRule({
64
+ meta: {
65
+ 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
+ messages: {
71
+ dateCall: "calling the Date constructor is banned",
72
+ currentDate: "new Date() reads the current time",
73
+ clockRead: "{{usage}} reads the current time outside Effect Clock",
74
+ restrictedProperty: "{{usage}} is banned",
75
+ formatsNow: "{{method}}() of Intl.DateTimeFormat without a date formats the current time",
76
+ timedWait: "Atomics.{{method}} with a timeout sleeps",
77
+ neverTimeout: "{{usage}} on Effect.never sleeps",
78
+ },
79
+ },
80
+ create(context) {
81
+ const { sourceCode } = context;
82
+ const isGlobalDate = (callee: ESTree.Node) => isGlobalReference(callee, sourceCode, "Date");
83
+ const keepsWaiting = (operation: ESTree.Node) => {
84
+ const operationName = effectOperation(
85
+ operation.type === "CallExpression" ? operation.callee : operation,
86
+ sourceCode,
87
+ );
88
+ return operationName !== undefined && OPERATIONS_THAT_KEEP_WAITING.has(operationName);
89
+ };
90
+ const isNever = (node: ESTree.Node | undefined): boolean => {
91
+ if (node === undefined) {
92
+ return false;
93
+ }
94
+ if (effectOperation(node, sourceCode) === "never") {
95
+ return true;
96
+ }
97
+ if (node.type !== "CallExpression") {
98
+ return false;
99
+ }
100
+ const [first, ...rest] = node.arguments;
101
+ const isPipeMethodOnNever =
102
+ node.callee.type === "MemberExpression" &&
103
+ memberName(node.callee) === PIPE &&
104
+ isNever(node.callee.object) &&
105
+ node.arguments.every((operation) => keepsWaiting(operation));
106
+ const isPipeFunctionFromNever =
107
+ isPipeFunction(node.callee, sourceCode) &&
108
+ isNever(first) &&
109
+ rest.every((operation) => keepsWaiting(operation));
110
+ return isPipeMethodOnNever || isPipeFunctionFromNever;
111
+ };
112
+
113
+ const isTimeoutOnNever = (node: ESTree.CallExpression) => {
114
+ if (isNever(node.arguments[0])) {
115
+ return true;
116
+ }
117
+ const { parent } = node;
118
+ if (parent.type !== "CallExpression") {
119
+ return false;
120
+ }
121
+ const { callee } = parent;
122
+ const position = parent.arguments.indexOf(node);
123
+ const operationsBefore = (start: number) =>
124
+ parent.arguments.slice(start, position).every((operation) => keepsWaiting(operation));
125
+ if (callee.type === "MemberExpression") {
126
+ return memberName(callee) === PIPE && isNever(callee.object) && operationsBefore(0);
127
+ }
128
+ return (
129
+ isPipeFunction(callee, sourceCode) &&
130
+ position > 0 &&
131
+ isNever(parent.arguments[0]) &&
132
+ operationsBefore(1)
133
+ );
134
+ };
135
+
136
+ const reportRestrictedProperty = (
137
+ node: ESTree.Node,
138
+ receiver: ESTree.Node,
139
+ name: string | undefined,
140
+ ) => {
141
+ const imported = importedExpression(receiver, sourceCode);
142
+ const restricted = CLOCK_PROPERTIES.find(({ object, property }) => {
143
+ const isImportedObject =
144
+ imported?.members.length === 0 &&
145
+ moduleSpecifiersOfGlobalObject(object).includes(imported.module);
146
+ return (
147
+ name === property && (isGlobalReference(receiver, sourceCode, object) || isImportedObject)
148
+ );
149
+ });
150
+ if (restricted !== undefined) {
151
+ context.report({
152
+ node,
153
+ messageId: "restrictedProperty",
154
+ data: { usage: `${restricted.object}.${restricted.property}` },
155
+ });
156
+ }
157
+ };
158
+
159
+ const reportClockRead = (node: ESTree.Node) => {
160
+ const usage = effectModuleReference(node, sourceCode, "DateTime");
161
+ const readsTheClock = usage !== undefined && CLOCK_READS.has(usage);
162
+ if (readsTheClock) {
163
+ context.report({ node, messageId: "clockRead", data: { usage } });
164
+ }
165
+ if (node.type === "MemberExpression") {
166
+ reportRestrictedProperty(node, node.object, memberName(node));
167
+ }
168
+ };
169
+
170
+ const reportDestructuredProperties = (pattern: ESTree.Node, value: ESTree.Node | null) => {
171
+ const isMissingObjectPattern = pattern.type !== "ObjectPattern" || value === null;
172
+ if (isMissingObjectPattern) {
173
+ return;
174
+ }
175
+ for (const property of pattern.properties) {
176
+ if (property.type === "Property") {
177
+ reportRestrictedProperty(property, value, propertyKeyName(property));
178
+ }
179
+ }
180
+ };
181
+
182
+ return {
183
+ CallExpression(node) {
184
+ if (isGlobalDate(node.callee)) {
185
+ context.report({ node, messageId: "dateCall" });
186
+ return;
187
+ }
188
+ const timeout = effectOperation(node.callee, sourceCode);
189
+ const isEffectTimeoutOnNever =
190
+ timeout !== undefined && EFFECT_TIMEOUTS.has(timeout) && isTimeoutOnNever(node);
191
+ if (isEffectTimeoutOnNever) {
192
+ context.report({ node, messageId: "neverTimeout", data: { usage: `Effect.${timeout}` } });
193
+ return;
194
+ }
195
+ if (node.callee.type !== "MemberExpression") {
196
+ return;
197
+ }
198
+ const method = memberName(node.callee);
199
+ if (method === undefined) {
200
+ return;
201
+ }
202
+ const formatsTheCurrentDate =
203
+ DATE_FORMATS.has(method) &&
204
+ node.arguments.length === 0 &&
205
+ isDateTimeFormatter(node.callee.object, sourceCode);
206
+ if (formatsTheCurrentDate) {
207
+ context.report({ node, messageId: "formatsNow", data: { method } });
208
+ return;
209
+ }
210
+ const waitTimeout = node.arguments[ARGUMENTS_OF_A_TIMED_WAIT - 1];
211
+ const isUntimedWait =
212
+ waitTimeout !== undefined &&
213
+ UNTIMED_WAIT_TIMEOUTS.some((name) => isGlobalReference(waitTimeout, sourceCode, name));
214
+ const waitsWithATimeout =
215
+ TIMED_WAITS.has(method) &&
216
+ node.arguments.length >= ARGUMENTS_OF_A_TIMED_WAIT &&
217
+ !isUntimedWait &&
218
+ isGlobalReference(node.callee.object, sourceCode, "Atomics");
219
+ if (waitsWithATimeout) {
220
+ context.report({ node, messageId: "timedWait", data: { method } });
221
+ }
222
+ },
223
+ NewExpression(node) {
224
+ const constructsTheCurrentDate = node.arguments.length === 0 && isGlobalDate(node.callee);
225
+ if (constructsTheCurrentDate) {
226
+ context.report({ node, messageId: "currentDate" });
227
+ }
228
+ },
229
+ Identifier: reportClockRead,
230
+ MemberExpression: reportClockRead,
231
+ VariableDeclarator(node) {
232
+ reportDestructuredProperties(node.id, node.init);
233
+ },
234
+ AssignmentExpression(node) {
235
+ reportDestructuredProperties(node.left, node.right);
236
+ },
237
+ };
238
+ },
239
+ });
@@ -0,0 +1,49 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import type { ESTree } from "@oxlint/plugins";
3
+
4
+ import { RETIRED_WORDS, retiredWordIn } from "../shared/find-retired-words.ts";
5
+ import { fileNameOf } from "../shared/match-file-names-and-path-prefixes.ts";
6
+ import { fileNameWords, identifierWords } from "./split-names-into-words.ts";
7
+ import { declaredNameListeners } from "./visit-every-declared-name.ts";
8
+
9
+ const wordsOf = (name: string) => identifierWords(name).map((word) => word.text);
10
+
11
+ export const noRetiredWords = defineRule({
12
+ meta: {
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
+ messages: {
18
+ name: "`{{name}}` uses the retired word {{word}}",
19
+ fileName: "file name {{fileName}} uses the retired word {{word}}",
20
+ },
21
+ },
22
+ create(context) {
23
+ const check = (node: ESTree.Node, inheritedNames: readonly string[] = []) => {
24
+ const isIdentifierOrPrivateIdentifier =
25
+ node.type === "Identifier" || node.type === "PrivateIdentifier";
26
+ if (!isIdentifierOrPrivateIdentifier) {
27
+ return;
28
+ }
29
+ const retired = retiredWordIn(wordsOf(node.name));
30
+ const inherited = new Set(
31
+ inheritedNames.flatMap((name) => wordsOf(name)).map((text) => text.toLowerCase()),
32
+ );
33
+ const usesRetiredWordNotInherited = retired !== undefined && !inherited.has(retired.word);
34
+ if (usesRetiredWordNotInherited) {
35
+ context.report({ node, messageId: "name", data: { name: node.name, ...retired } });
36
+ }
37
+ };
38
+ return {
39
+ ...declaredNameListeners(check, "own"),
40
+ Program(node) {
41
+ const fileName = fileNameOf(context.filename);
42
+ const retired = retiredWordIn(fileNameWords(fileName));
43
+ if (retired !== undefined) {
44
+ context.report({ node, messageId: "fileName", data: { fileName, ...retired } });
45
+ }
46
+ },
47
+ };
48
+ },
49
+ });
@@ -0,0 +1,79 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import type { ESTree, SourceCode } from "@oxlint/plugins";
3
+
4
+ import {
5
+ importedExpression,
6
+ isGlobalReference,
7
+ memberName,
8
+ resolvedVariable,
9
+ } from "./resolve-what-an-expression-imports.ts";
10
+
11
+ const SCANNING_METHODS = new Set(["scan", "scanSync"]);
12
+
13
+ const isBunNamespace = (node: ESTree.Node, sourceCode: SourceCode) => {
14
+ if (isGlobalReference(node, sourceCode, "Bun")) {
15
+ return true;
16
+ }
17
+ const definition = resolvedVariable(node, sourceCode)?.defs[0]?.node;
18
+ return (
19
+ (definition?.type === "ImportDefaultSpecifier" ||
20
+ definition?.type === "ImportNamespaceSpecifier") &&
21
+ definition.parent.type === "ImportDeclaration" &&
22
+ definition.parent.source.value === "bun"
23
+ );
24
+ };
25
+
26
+ const isGlobConstructor = (node: ESTree.Node, sourceCode: SourceCode): boolean => {
27
+ if (node.type === "MemberExpression") {
28
+ return memberName(node) === "Glob" && isBunNamespace(node.object, sourceCode);
29
+ }
30
+ const imported = importedExpression(node, sourceCode);
31
+ return imported?.module === "bun" && imported.members.join(".") === "Glob";
32
+ };
33
+
34
+ const isGlobInstance = (
35
+ node: ESTree.Node,
36
+ sourceCode: SourceCode,
37
+ followedDeclarators: ReadonlySet<ESTree.Node> = new Set(),
38
+ ): boolean => {
39
+ if (node.type === "NewExpression") {
40
+ return isGlobConstructor(node.callee, sourceCode);
41
+ }
42
+ if (node.type !== "Identifier") {
43
+ return false;
44
+ }
45
+ const definition = resolvedVariable(node, sourceCode)?.defs[0]?.node;
46
+ return (
47
+ definition?.type === "VariableDeclarator" &&
48
+ !followedDeclarators.has(definition) &&
49
+ definition.id.type === "Identifier" &&
50
+ definition.init !== null &&
51
+ isGlobInstance(definition.init, sourceCode, new Set([...followedDeclarators, definition]))
52
+ );
53
+ };
54
+
55
+ export const noGlobScan = defineRule({
56
+ meta: {
57
+ type: "problem",
58
+ docs: {
59
+ description: "Allow Bun.Glob for matching strings but not for scanning directories.",
60
+ },
61
+ messages: {
62
+ scan: "Bun.Glob {{method}} scans directories",
63
+ },
64
+ },
65
+ create(context) {
66
+ return {
67
+ MemberExpression(node) {
68
+ const method = memberName(node);
69
+ const isScanOnGlobInstance =
70
+ method !== undefined &&
71
+ SCANNING_METHODS.has(method) &&
72
+ isGlobInstance(node.object, context.sourceCode);
73
+ if (isScanOnGlobInstance) {
74
+ context.report({ node, messageId: "scan", data: { method } });
75
+ }
76
+ },
77
+ };
78
+ },
79
+ });
@@ -0,0 +1,26 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+
3
+ export const noShebang = defineRule({
4
+ meta: {
5
+ type: "suggestion",
6
+ docs: {
7
+ description:
8
+ "Start source files with code instead of a shebang, so the runtime and its flags come from the caller or package.json.",
9
+ },
10
+ messages: {
11
+ shebang: "file starts with a shebang line",
12
+ },
13
+ },
14
+ create(context) {
15
+ return {
16
+ Program() {
17
+ const shebang = context.sourceCode
18
+ .getAllComments()
19
+ .find((comment) => comment.type === "Shebang");
20
+ if (shebang !== undefined) {
21
+ context.report({ loc: shebang.loc, messageId: "shebang" });
22
+ }
23
+ },
24
+ };
25
+ },
26
+ });
@@ -0,0 +1,34 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+
3
+ import { GLOBAL_RULES } from "../shared/lint-rule-messages-and-patterns.ts";
4
+ import {
5
+ isGlobalReference,
6
+ isMemberExpressionObject,
7
+ isReferencePosition,
8
+ isShorthandKey,
9
+ } from "./resolve-what-an-expression-imports.ts";
10
+
11
+ export const globalRule = (ruleName: keyof typeof GLOBAL_RULES) => {
12
+ const restrictedGlobals: ReadonlySet<string> = new Set(GLOBAL_RULES[ruleName].globals);
13
+ return defineRule({
14
+ meta: {
15
+ type: "problem",
16
+ docs: { description: `Refuse the globals ${[...restrictedGlobals].join(", ")}.` },
17
+ messages: { global: "global {{name}} is used" },
18
+ },
19
+ create(context) {
20
+ return {
21
+ Identifier(node) {
22
+ const isRestrictedGlobalReference =
23
+ restrictedGlobals.has(node.name) &&
24
+ !isShorthandKey(node) &&
25
+ (isMemberExpressionObject(node) || isReferencePosition(node)) &&
26
+ isGlobalReference(node, context.sourceCode, node.name);
27
+ if (isRestrictedGlobalReference) {
28
+ context.report({ node, messageId: "global", data: { name: node.name } });
29
+ }
30
+ },
31
+ };
32
+ },
33
+ });
34
+ };
@@ -0,0 +1,240 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import type { Context, ESTree } from "@oxlint/plugins";
3
+ import { Schema } from "effect";
4
+
5
+ import { SCHEDULE_MESSAGES } from "../shared/lint-rule-messages-and-patterns.ts";
6
+ import { decodeRuleOptions, ruleOptionsJsonSchema } from "./describe-and-decode-rule-options.ts";
7
+ import {
8
+ effectModuleReference,
9
+ effectOperation,
10
+ importedExpression,
11
+ } from "./resolve-what-an-expression-imports.ts";
12
+
13
+ const TWO_ARGUMENTS = 2;
14
+
15
+ export const POLLING_OPERATIONS = new Set([
16
+ "retry",
17
+ "repeat",
18
+ "retryOrElse",
19
+ "repeatOrElse",
20
+ "schedule",
21
+ "scheduleFrom",
22
+ ]);
23
+ const RETRY_OPERATIONS = new Set(["retry", "retryOrElse"]);
24
+ const FALLBACK_OPERATIONS = new Set(["retryOrElse", "repeatOrElse"]);
25
+ export const DEADLINE_OPERATIONS = new Set(["timeout", "timeoutOption", "timeoutOrElse"]);
26
+ const COUNT_ONLY_SCHEDULE = "Schedule.recurs";
27
+ const OUTPUT_MAPPING = "Schedule.map";
28
+ const SCHEDULE_A_GRANT_ALLOWS = "Schedule.spaced";
29
+ const PIPE_METHOD = "pipe";
30
+
31
+ const isFunctionExpression = (node: ESTree.Node) =>
32
+ node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression";
33
+
34
+ const TIMED_SCHEDULES = ["banned", "allowedWithDeadline"] as const;
35
+
36
+ const SCHEDULE_OPTIONS = Schema.Struct({
37
+ timedSchedules: Schema.optionalKey(Schema.Literals(TIMED_SCHEDULES)),
38
+ });
39
+
40
+ export const scheduleVisitors = ({
41
+ context,
42
+ timedSchedules,
43
+ }: {
44
+ readonly context: Context;
45
+ readonly timedSchedules: (typeof TIMED_SCHEDULES)[number];
46
+ }) => {
47
+ const isDeadlineCall = (node: ESTree.Node) => {
48
+ if (node.type !== "CallExpression") {
49
+ return false;
50
+ }
51
+ const operation = effectOperation(node.callee, context.sourceCode);
52
+ return operation !== undefined && DEADLINE_OPERATIONS.has(operation);
53
+ };
54
+
55
+ const isPipeFunction = (node: ESTree.Node) => {
56
+ const imported = importedExpression(node, context.sourceCode);
57
+ return (
58
+ imported !== undefined &&
59
+ ((imported.module === "effect" && imported.members.join(".") === "pipe") ||
60
+ (imported.module === "effect/Function" && imported.members.join(".") === "pipe"))
61
+ );
62
+ };
63
+
64
+ const pollingOperation = (node: ESTree.Node) => {
65
+ if (node.type !== "CallExpression") {
66
+ return;
67
+ }
68
+ const operation = effectOperation(node.callee, context.sourceCode);
69
+ const isPollingOperation = operation !== undefined && POLLING_OPERATIONS.has(operation);
70
+ return isPollingOperation ? operation : undefined;
71
+ };
72
+
73
+ const hasDeadline = (child: ESTree.Node): boolean => {
74
+ const ancestor = child.parent;
75
+ if (ancestor === null) {
76
+ return false;
77
+ }
78
+ if (ancestor.type === "CallExpression") {
79
+ const isDeadlineAroundChild =
80
+ isDeadlineCall(ancestor) && ancestor.arguments.some((argument) => argument === child);
81
+ if (isDeadlineAroundChild) {
82
+ return true;
83
+ }
84
+ const isMethodPipe =
85
+ ancestor.callee.type === "MemberExpression" &&
86
+ !ancestor.callee.computed &&
87
+ ancestor.callee.property.type === "Identifier" &&
88
+ ancestor.callee.property.name === "pipe";
89
+ const isPipeCall = isMethodPipe || isPipeFunction(ancestor.callee);
90
+ if (isPipeCall) {
91
+ const pipedArguments: readonly ESTree.Node[] = ancestor.arguments;
92
+ const position = pipedArguments.indexOf(child);
93
+ if (ancestor.arguments.slice(position + 1).some((argument) => isDeadlineCall(argument))) {
94
+ return true;
95
+ }
96
+ }
97
+ }
98
+ return hasDeadline(ancestor);
99
+ };
100
+
101
+ const enclosingPolling = (node: ESTree.Node): ESTree.Node | null => {
102
+ const ancestor = node.parent;
103
+ if (ancestor === null) {
104
+ return null;
105
+ }
106
+ if (pollingOperation(ancestor) !== undefined) {
107
+ return ancestor;
108
+ }
109
+ return enclosingPolling(ancestor);
110
+ };
111
+
112
+ const report = (node: ESTree.Node, usage: string, polling: ESTree.Node | null) => {
113
+ const operation = polling === null ? undefined : pollingOperation(polling);
114
+ const retries = operation !== undefined && RETRY_OPERATIONS.has(operation);
115
+ if (timedSchedules === "banned") {
116
+ context.report({ node, messageId: retries ? "retrying" : "polling", data: { usage } });
117
+ return;
118
+ }
119
+ if (retries) {
120
+ context.report({ node, messageId: "retryingEvenWhenGranted", data: { usage } });
121
+ return;
122
+ }
123
+ if (usage !== SCHEDULE_A_GRANT_ALLOWS) {
124
+ context.report({ node, messageId: "scheduleEvenWhenGranted", data: { usage } });
125
+ return;
126
+ }
127
+ const lacksDeadline = polling === null || !hasDeadline(polling);
128
+ if (lacksDeadline) {
129
+ context.report({ node, messageId: "deadline", data: { usage } });
130
+ }
131
+ };
132
+
133
+ const scheduleUsageOf = (node: ESTree.Node) =>
134
+ effectModuleReference(node, context.sourceCode, "Schedule");
135
+
136
+ const isDataLastMapping = (node: ESTree.Node) =>
137
+ node.type === "CallExpression" &&
138
+ scheduleUsageOf(node.callee) === OUTPUT_MAPPING &&
139
+ node.arguments.length === 1;
140
+
141
+ const pipeOf = (call: ESTree.CallExpression) => {
142
+ const callee = call.callee;
143
+ const isMethodPipe =
144
+ callee.type === "MemberExpression" &&
145
+ !callee.computed &&
146
+ callee.property.type === "Identifier" &&
147
+ callee.property.name === PIPE_METHOD;
148
+ if (isMethodPipe) {
149
+ return { source: callee.object, stages: call.arguments };
150
+ }
151
+ const [source, ...stages] = call.arguments;
152
+ const isPipeFunctionCallWithSource = source !== undefined && isPipeFunction(call.callee);
153
+ return isPipeFunctionCallWithSource ? { source, stages } : undefined;
154
+ };
155
+
156
+ const isCountOnlySchedule = (node: ESTree.Node | undefined): boolean => {
157
+ if (node?.type !== "CallExpression") {
158
+ return false;
159
+ }
160
+ const usage = scheduleUsageOf(node.callee);
161
+ if (usage === COUNT_ONLY_SCHEDULE) {
162
+ return node.arguments.length === 1;
163
+ }
164
+ if (usage === OUTPUT_MAPPING) {
165
+ return node.arguments.length === TWO_ARGUMENTS && isCountOnlySchedule(node.arguments[0]);
166
+ }
167
+ const piped = pipeOf(node);
168
+ return (
169
+ piped !== undefined &&
170
+ isCountOnlySchedule(piped.source) &&
171
+ piped.stages.every((stage) => isDataLastMapping(stage))
172
+ );
173
+ };
174
+
175
+ const keepsCountOnly = (node: ESTree.Node) => {
176
+ const call = node.parent;
177
+ if (call?.type !== "CallExpression") {
178
+ return false;
179
+ }
180
+ if (call.callee !== node) {
181
+ return false;
182
+ }
183
+ if (isCountOnlySchedule(call)) {
184
+ return true;
185
+ }
186
+ const piped = call.parent.type === "CallExpression" ? pipeOf(call.parent) : undefined;
187
+ const stage = piped?.stages.indexOf(call) ?? -1;
188
+ return (
189
+ piped !== undefined &&
190
+ stage !== -1 &&
191
+ isDataLastMapping(call) &&
192
+ isCountOnlySchedule(piped.source) &&
193
+ piped.stages.slice(0, stage).every((earlier) => isDataLastMapping(earlier))
194
+ );
195
+ };
196
+
197
+ const scheduleReference = (node: ESTree.Node) => {
198
+ const usage = scheduleUsageOf(node);
199
+ const isUnboundedScheduleUsage = usage !== undefined && !keepsCountOnly(node);
200
+ if (isUnboundedScheduleUsage) {
201
+ report(node, usage, enclosingPolling(node));
202
+ }
203
+ };
204
+
205
+ return {
206
+ Identifier: scheduleReference,
207
+ MemberExpression: scheduleReference,
208
+ CallExpression(node: ESTree.CallExpression) {
209
+ const operation = pollingOperation(node);
210
+ if (operation === undefined) {
211
+ return;
212
+ }
213
+ const policies = FALLBACK_OPERATIONS.has(operation)
214
+ ? node.arguments.slice(0, -1)
215
+ : node.arguments;
216
+ if (policies.some((policy) => isFunctionExpression(policy))) {
217
+ report(node.callee, `Effect.${operation} with a schedule`, node);
218
+ }
219
+ },
220
+ };
221
+ };
222
+
223
+ export const noSchedules = defineRule({
224
+ meta: {
225
+ type: "problem",
226
+ docs: {
227
+ description:
228
+ "Wait on signals instead of timers; Schedule.recurs(n) counts without a timer, and files allowed pollsWithADeadline may repeat with Schedule.spaced when the polling has a deadline, but no file retries on a timer.",
229
+ },
230
+ messages: SCHEDULE_MESSAGES,
231
+ schema: ruleOptionsJsonSchema(SCHEDULE_OPTIONS),
232
+ },
233
+ create(context) {
234
+ return scheduleVisitors({
235
+ context,
236
+ timedSchedules:
237
+ decodeRuleOptions(SCHEDULE_OPTIONS, context.options)?.timedSchedules ?? "banned",
238
+ });
239
+ },
240
+ });