@sshkeda/check 0.0.0-stage → 1.0.1

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 +848 -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,190 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import type { ESTree, SourceCode } from "@oxlint/plugins";
3
+
4
+ import {
5
+ effectOperation,
6
+ importedExpression,
7
+ isImportBinding,
8
+ isReferencePosition,
9
+ memberName,
10
+ propertyKeyName,
11
+ } from "./resolve-what-an-expression-imports.ts";
12
+
13
+ const MEMBERS_THAT_WRITE_NOTHING = new Set([
14
+ "args",
15
+ "stdin",
16
+ "stdinIsTerminal",
17
+ "stdoutIsTerminal",
18
+ "stderrIsTerminal",
19
+ ]);
20
+
21
+ const SERVICE_USE = "use";
22
+
23
+ const PIPE = "pipe";
24
+
25
+ const OPERATIONS_THAT_PASS_THE_SERVICE = new Set(["map", "flatMap", "andThen"]);
26
+
27
+ const rootOf = (node: ESTree.Node): ESTree.Node =>
28
+ node.type === "MemberExpression" ? rootOf(node.object) : node;
29
+
30
+ const isStdioTag = (node: ESTree.Node, sourceCode: SourceCode) => {
31
+ if (!isImportBinding(rootOf(node), sourceCode)) {
32
+ return false;
33
+ }
34
+ const imported = importedExpression(node, sourceCode);
35
+ const path = imported?.members.join(".");
36
+ return (
37
+ (imported?.module === "effect" && path === "Stdio.Stdio") ||
38
+ (imported?.module === "effect/Stdio" && path === "Stdio")
39
+ );
40
+ };
41
+
42
+ const readsOnlyMembersThatWriteNothing = (node: ESTree.Node) => {
43
+ const { parent } = node;
44
+ const isReadOfAMember = parent?.type === "MemberExpression" && parent.object === node;
45
+ const member = isReadOfAMember ? memberName(parent) : undefined;
46
+ return member !== undefined && MEMBERS_THAT_WRITE_NOTHING.has(member);
47
+ };
48
+
49
+ const patternReadsOnlyMembersThatWriteNothing = (properties: readonly ESTree.Node[]) =>
50
+ properties.every((property) => {
51
+ const key = propertyKeyName(property);
52
+ return key !== undefined && MEMBERS_THAT_WRITE_NOTHING.has(key);
53
+ });
54
+
55
+ const bindingReadsOnlyMembersThatWriteNothing = (
56
+ binding: ESTree.Node | undefined,
57
+ sourceCode: SourceCode,
58
+ ) => {
59
+ if (binding === undefined) {
60
+ return true;
61
+ }
62
+ if (binding.type === "ObjectPattern") {
63
+ return patternReadsOnlyMembersThatWriteNothing(binding.properties);
64
+ }
65
+ if (binding.type !== "Identifier") {
66
+ return false;
67
+ }
68
+ const declared = sourceCode
69
+ .getDeclaredVariables(binding.parent)
70
+ .find((variable) => variable.identifiers.includes(binding));
71
+ return (declared?.references ?? [])
72
+ .filter((reference) => reference.identifier !== binding)
73
+ .every((reference) => readsOnlyMembersThatWriteNothing(reference.identifier));
74
+ };
75
+
76
+ const serviceValueWritesNothing = (service: ESTree.Node, sourceCode: SourceCode) => {
77
+ if (readsOnlyMembersThatWriteNothing(service)) {
78
+ return true;
79
+ }
80
+ const declarator = service.parent;
81
+ const isConstantInitializer =
82
+ declarator?.type === "VariableDeclarator" &&
83
+ declarator.init === service &&
84
+ declarator.parent.type === "VariableDeclaration" &&
85
+ declarator.parent.kind === "const";
86
+ return (
87
+ isConstantInitializer && bindingReadsOnlyMembersThatWriteNothing(declarator.id, sourceCode)
88
+ );
89
+ };
90
+
91
+ const callbackWritesNothing = (callback: ESTree.Node | undefined, sourceCode: SourceCode) => {
92
+ const isInline =
93
+ callback?.type === "ArrowFunctionExpression" || callback?.type === "FunctionExpression";
94
+ if (isInline) {
95
+ return bindingReadsOnlyMembersThatWriteNothing(callback.params[0], sourceCode);
96
+ }
97
+ return false;
98
+ };
99
+
100
+ const stepWritesNothing = (step: ESTree.Node | undefined, sourceCode: SourceCode) => {
101
+ const isOneArgumentCall = step?.type === "CallExpression" && step.arguments.length === 1;
102
+ if (!isOneArgumentCall) {
103
+ return false;
104
+ }
105
+ const operation = effectOperation(step.callee, sourceCode);
106
+ const passesTheServiceOn =
107
+ operation !== undefined && OPERATIONS_THAT_PASS_THE_SERVICE.has(operation);
108
+ return passesTheServiceOn && callbackWritesNothing(step.arguments[0], sourceCode);
109
+ };
110
+
111
+ const isPipeFunction = (callee: ESTree.Node, sourceCode: SourceCode) => {
112
+ const imported = importedExpression(callee, sourceCode);
113
+ const path = imported?.members.join(".");
114
+ const isFromEffect =
115
+ imported?.module === "effect" && (path === PIPE || path === `Function.${PIPE}`);
116
+ const isFromFunction = imported?.module === "effect/Function" && path === PIPE;
117
+ return isFromEffect || isFromFunction;
118
+ };
119
+
120
+ const tagUseWritesNothing = (tag: ESTree.Node, sourceCode: SourceCode) => {
121
+ const { parent } = tag;
122
+ const isYielded =
123
+ parent?.type === "YieldExpression" && parent.delegate && parent.argument === tag;
124
+ if (isYielded) {
125
+ return serviceValueWritesNothing(parent, sourceCode);
126
+ }
127
+ const call = parent?.parent;
128
+ const isMethodCall =
129
+ parent?.type === "MemberExpression" &&
130
+ parent.object === tag &&
131
+ call?.type === "CallExpression" &&
132
+ call.callee === parent;
133
+ if (isMethodCall) {
134
+ const method = memberName(parent);
135
+ if (method === SERVICE_USE) {
136
+ return callbackWritesNothing(call.arguments[0], sourceCode);
137
+ }
138
+ return method === PIPE && stepWritesNothing(call.arguments[0], sourceCode);
139
+ }
140
+ const isCallOnTheTag = parent?.type === "CallExpression" && parent.arguments[0] === tag;
141
+ if (!isCallOnTheTag) {
142
+ return false;
143
+ }
144
+ if (isPipeFunction(parent.callee, sourceCode)) {
145
+ return stepWritesNothing(parent.arguments[1], sourceCode);
146
+ }
147
+ const operation = effectOperation(parent.callee, sourceCode);
148
+ const passesTheServiceOn =
149
+ operation !== undefined && OPERATIONS_THAT_PASS_THE_SERVICE.has(operation);
150
+ return passesTheServiceOn && callbackWritesNothing(parent.arguments[1], sourceCode);
151
+ };
152
+
153
+ export const noStdioService = defineRule({
154
+ meta: {
155
+ type: "problem",
156
+ docs: {
157
+ description:
158
+ "Use the Effect Stdio service only in files allowed writesToTheTerminal, except to read stdin, args or whether a stream is a terminal.",
159
+ },
160
+ messages: {
161
+ stdioService:
162
+ "{{usage}} is used for more than reading stdin, args or whether a stream is a terminal",
163
+ },
164
+ },
165
+ create(context) {
166
+ const { sourceCode } = context;
167
+ const check = (node: ESTree.Node) => {
168
+ const isRefusedTagUse =
169
+ isStdioTag(node, sourceCode) && !tagUseWritesNothing(node, sourceCode);
170
+ if (isRefusedTagUse) {
171
+ context.report({
172
+ node,
173
+ messageId: "stdioService",
174
+ data: { usage: sourceCode.getText(node) },
175
+ });
176
+ }
177
+ };
178
+ return {
179
+ Identifier(node) {
180
+ const isValueReference =
181
+ isReferencePosition(node) ||
182
+ (node.parent.type === "MemberExpression" && node.parent.object === node);
183
+ if (isValueReference) {
184
+ check(node);
185
+ }
186
+ },
187
+ MemberExpression: check,
188
+ };
189
+ },
190
+ });
@@ -0,0 +1,361 @@
1
+ import { eslintCompatPlugin } from "@oxlint/plugins";
2
+ import { Record } from "effect";
3
+
4
+ import {
5
+ everyBanOf,
6
+ IMPORT_META,
7
+ moduleSpecifiersOfGlobalObject,
8
+ PERMISSION_BAN_NAMES,
9
+ PERMISSION_BANS,
10
+ } from "../shared/bans-each-permission-lifts.ts";
11
+ import {
12
+ EFFECT_OPERATION_RULES,
13
+ GLOBAL_RULES,
14
+ NODE_BUILTIN_RULES,
15
+ } from "../shared/lint-rule-messages-and-patterns.ts";
16
+ import {
17
+ grantPermissions,
18
+ permissionBanRuleId,
19
+ FAILURES_AS_RESULTS_RULE,
20
+ STDIO_SERVICE_RULE,
21
+ TEST_TIMEOUTS_RULE,
22
+ TYPE_PREDICATES_RULE,
23
+ } from "../shared/record-and-grant-permissions-by-path.ts";
24
+ import { noAbbreviations } from "./ban-abbreviated-words-in-declared-names.ts";
25
+ import { noUncalledMembers } from "./ban-checked-members-outside-calls.ts";
26
+ import { noComments } from "./ban-comments.ts";
27
+ import { noManualTag, noTagBranching } from "./ban-comparing-or-switching-on-tag.ts";
28
+ import { noTestTimeouts } from "./ban-deadlines-inside-tests.ts";
29
+ import { noDeclaredValues } from "./ban-declared-values.ts";
30
+ import { effectOperationRule } from "./ban-dropped-failures-detached-fibers-sleeps-and-untraced-functions.ts";
31
+ import { noFailuresAsResults } from "./ban-failures-collected-as-results.ts";
32
+ import { noUnnamedFallbacks } from "./ban-fallbacks-of-named-recoveries.ts";
33
+ import { noOverloads } from "./ban-function-overloads.ts";
34
+ import { noPlainErrorFailures } from "./ban-global-error-in-failure-types.ts";
35
+ import { noErrorInstanceof } from "./ban-instanceof-in-effect-recovery-callbacks.ts";
36
+ import { noLet, noMutableRef } from "./ban-let-and-effect-mutable-ref.ts";
37
+ import { noIndexLogic } from "./ban-logic-in-index-files.ts";
38
+ import { noNamespaceAliases } from "./ban-namespaces-used-without-a-member.ts";
39
+ import { nodeBuiltinRule } from "./ban-node-builtins-that-effect-replaces.ts";
40
+ import { noUncheckedParsing } from "./ban-parsing-outside-data-without-a-schema.ts";
41
+ import { noReExports } from "./ban-re-exports.ts";
42
+ import {
43
+ CLOCK_PROPERTIES,
44
+ noClockReadsAndSleeps,
45
+ } from "./ban-reading-the-clock-and-sleeping-outside-effect.ts";
46
+ import { noRetiredWords } from "./ban-retired-words-in-names.ts";
47
+ import { noGlobScan } from "./ban-scanning-directories-with-bun-glob.ts";
48
+ import { noShebang } from "./ban-shebang-lines.ts";
49
+ import { globalRule } from "./ban-timer-globals-and-the-global-object.ts";
50
+ import { noSchedules } from "./ban-timer-schedules-without-deadlines.ts";
51
+ import { noTypeDeclarations } from "./ban-type-and-interface-declarations.ts";
52
+ import { noTypePredicates } from "./ban-type-predicates.ts";
53
+ import { noUnknownBoundaries } from "./ban-unknown-in-function-signatures.ts";
54
+ import { noVagueErrorNames } from "./ban-vague-error-class-names.ts";
55
+ import { noVagueFileNames } from "./ban-vague-file-names.ts";
56
+ import { permissionBanRule } from "./ban-what-a-file-is-not-granted.ts";
57
+ import { noWhile } from "./ban-while-do-while-and-for-loops.ts";
58
+ import {
59
+ noServiceDeclarations,
60
+ noUnusedServiceGrants,
61
+ } from "./confine-service-declarations-to-granted-files.ts";
62
+ import { noStdioService } from "./confine-the-stdio-service-to-terminal-output.ts";
63
+ import {
64
+ noAssertions,
65
+ noTestRunners,
66
+ } from "./keep-assertions-in-the-test-home-and-ban-test-runners.ts";
67
+ import { noTestingHelpers } from "./keep-effect-testing-helpers-in-test-files.ts";
68
+ import { bansByKind } from "./match-banned-modules-and-globals.ts";
69
+ import { noUnnamedCompoundConditions } from "./require-a-named-const-for-compound-conditions.ts";
70
+ import { noLooseLiteralConstants } from "./require-capital-snake-case-and-as-const-on-literal-constants.ts";
71
+ import { noMismatchedServiceKeys } from "./require-service-keys-to-end-with-their-class-name.ts";
72
+ import { noUnsortedTypeConstituents } from "./sort-type-constituents.ts";
73
+
74
+ const NAME_BASED_RESTRICTED_PROPERTIES = [
75
+ { object: "Reflect", property: "get" },
76
+ { object: "Reflect", property: "apply" },
77
+ { object: "JSON", property: "parse" },
78
+ { object: "JSON", property: "stringify" },
79
+ { object: "Date", property: "now" },
80
+ { object: "Bun", property: "sleep" },
81
+ { object: "Bun", property: "file" },
82
+ { object: "Bun", property: "write" },
83
+ { object: "Bun", property: "serve" },
84
+ { object: "process", property: "exitCode" },
85
+ { object: "process", property: "getBuiltinModule" },
86
+ { object: "mock", property: "module" },
87
+ ] as const;
88
+
89
+ export const RESTRICTED_PROPERTIES = [
90
+ ...NAME_BASED_RESTRICTED_PROPERTIES,
91
+ ...CLOCK_PROPERTIES,
92
+ ] as const;
93
+
94
+ export const RESTRICTED_IMPORT_PATHS = RESTRICTED_PROPERTIES.flatMap(({ object, property }) =>
95
+ moduleSpecifiersOfGlobalObject(object).map((name) => ({
96
+ name,
97
+ importNames: [property],
98
+ allowTypeImports: true,
99
+ })),
100
+ );
101
+
102
+ const CONSOLE = "console";
103
+
104
+ const GLOBALS_WHOSE_MEMBERS_OTHER_RULES_BAN = ["Atomics", "Intl", "Number"] as const;
105
+
106
+ const GLOBALS_WHOSE_MEMBERS_PERMISSIONS_BAN = Object.values(PERMISSION_BANS)
107
+ .flatMap((entry) => bansByKind(everyBanOf(entry)).globalMembers)
108
+ .map(({ globalObject }) => globalObject)
109
+ .filter((globalObject) => globalObject !== IMPORT_META);
110
+
111
+ const TABLE_RULES = {
112
+ ...Record.map(EFFECT_OPERATION_RULES, (_rule, name) => effectOperationRule(name)),
113
+ ...Record.map(NODE_BUILTIN_RULES, (_rule, name) => nodeBuiltinRule(name)),
114
+ ...Record.map(GLOBAL_RULES, (_rule, name) => globalRule(name)),
115
+ };
116
+
117
+ const NAMED_RULES = {
118
+ "no-unsorted-type-constituents": noUnsortedTypeConstituents,
119
+ "no-error-instanceof": noErrorInstanceof,
120
+ "no-abbreviations": noAbbreviations,
121
+ "no-retired-words": noRetiredWords,
122
+ "no-vague-file-names": noVagueFileNames,
123
+ "no-index-logic": noIndexLogic,
124
+ "no-vague-error-names": noVagueErrorNames,
125
+ "no-plain-error-failures": noPlainErrorFailures,
126
+ "no-comments": noComments,
127
+ "no-manual-tag": noManualTag,
128
+ "no-tag-branching": noTagBranching,
129
+ "no-mismatched-service-keys": noMismatchedServiceKeys,
130
+ "no-clock-reads-and-sleeps": noClockReadsAndSleeps,
131
+ "no-unchecked-parsing": noUncheckedParsing,
132
+ "no-schedules": noSchedules,
133
+ "no-service-declarations": noServiceDeclarations,
134
+ "no-unused-service-grants": noUnusedServiceGrants,
135
+ "no-glob-scan": noGlobScan,
136
+ "no-unknown-boundaries": noUnknownBoundaries,
137
+ "no-loose-literal-constants": noLooseLiteralConstants,
138
+ "no-type-declarations": noTypeDeclarations,
139
+ "no-declared-values": noDeclaredValues,
140
+ [TYPE_PREDICATES_RULE]: noTypePredicates,
141
+ [STDIO_SERVICE_RULE]: noStdioService,
142
+ [FAILURES_AS_RESULTS_RULE]: noFailuresAsResults,
143
+ "no-overloads": noOverloads,
144
+ "no-re-exports": noReExports,
145
+ "no-testing-helpers": noTestingHelpers,
146
+ "no-assertions": noAssertions,
147
+ "no-test-runners": noTestRunners,
148
+ "no-unnamed-compound-conditions": noUnnamedCompoundConditions,
149
+ "no-let": noLet,
150
+ "no-mutable-ref": noMutableRef,
151
+ "no-while": noWhile,
152
+ "no-shebang": noShebang,
153
+ "no-uncalled-members": noUncalledMembers,
154
+ "no-unnamed-fallbacks": noUnnamedFallbacks,
155
+ "no-namespace-aliases": noNamespaceAliases(
156
+ new Set([
157
+ ...RESTRICTED_PROPERTIES.map(({ object }) => object),
158
+ ...GLOBALS_WHOSE_MEMBERS_PERMISSIONS_BAN,
159
+ ...GLOBALS_WHOSE_MEMBERS_OTHER_RULES_BAN,
160
+ CONSOLE,
161
+ ]),
162
+ ),
163
+ };
164
+
165
+ const TEST_HOME_RULES = {
166
+ [TEST_TIMEOUTS_RULE]: noTestTimeouts,
167
+ };
168
+
169
+ const OWN_RULE_SEVERITIES = Object.fromEntries(
170
+ Object.keys({ ...NAMED_RULES, ...TABLE_RULES }).map(
171
+ (name) => [`sshkeda/${name}`, "error"] as const,
172
+ ),
173
+ );
174
+
175
+ const PERMISSION_BAN_RULES = Object.fromEntries(
176
+ PERMISSION_BAN_NAMES.map((permission) => [
177
+ PERMISSION_BANS[permission].ruleName,
178
+ permissionBanRule(permission),
179
+ ]),
180
+ );
181
+
182
+ const PERMISSION_BAN_RULE_SEVERITIES = Object.fromEntries(
183
+ PERMISSION_BAN_NAMES.map((permission) => [permissionBanRuleId(permission), "error"] as const),
184
+ );
185
+
186
+ export const RESTRICTED_TYPES = {
187
+ object: true,
188
+ "{}": true,
189
+ "Record<string, unknown>": true,
190
+ "Record<string, object>": true,
191
+ "Record<PropertyKey, unknown>": true,
192
+ } as const;
193
+
194
+ export default eslintCompatPlugin({
195
+ meta: { name: "sshkeda" },
196
+ rules: {
197
+ ...NAMED_RULES,
198
+ ...TABLE_RULES,
199
+ ...PERMISSION_BAN_RULES,
200
+ ...TEST_HOME_RULES,
201
+ },
202
+ });
203
+
204
+ const baseConfig = {
205
+ ignorePatterns: ["**/node_modules/**"],
206
+ options: { typeAware: true, denyWarnings: true },
207
+ plugins: ["eslint", "typescript", "unicorn", "oxc", "node", "import"],
208
+ jsPlugins: [{ name: "sshkeda", specifier: import.meta.filename }],
209
+ categories: { correctness: "error", perf: "error" },
210
+ rules: Object.fromEntries([
211
+ ...Object.entries(OWN_RULE_SEVERITIES),
212
+ ...Object.entries(PERMISSION_BAN_RULE_SEVERITIES),
213
+ ...Object.entries({
214
+ "eslint/array-callback-return": "error",
215
+ "eslint/arrow-body-style": "error",
216
+ "eslint/class-methods-use-this": ["error", { ignoreOverrideMethods: true }],
217
+ "eslint/curly": ["error", "all"],
218
+ "eslint/eqeqeq": "error",
219
+ "eslint/func-style": "error",
220
+ "eslint/id-length": "error",
221
+ "eslint/no-console": "error",
222
+ "eslint/no-duplicate-imports": ["error", { allowSeparateTypeImports: true }],
223
+ "eslint/no-else-return": "error",
224
+ "eslint/no-empty": "error",
225
+ "eslint/no-empty-function": ["error", { allow: ["privateConstructors"] }],
226
+ "eslint/no-implicit-coercion": "error",
227
+ "eslint/no-lone-blocks": "error",
228
+ "eslint/no-lonely-if": "error",
229
+ "eslint/no-magic-numbers": ["error", { ignore: [0, 1, -1], ignoreTypeIndexes: true }],
230
+ "eslint/no-nested-ternary": "error",
231
+ "eslint/no-param-reassign": "error",
232
+ "eslint/no-regex-spaces": "error",
233
+ "eslint/no-shadow": "error",
234
+ "eslint/no-template-curly-in-string": "error",
235
+ "eslint/no-unneeded-ternary": "error",
236
+ "eslint/no-unused-private-class-members": "error",
237
+ "eslint/no-unused-vars": ["error", { ignoreRestSiblings: true }],
238
+ "eslint/no-use-before-define": "error",
239
+ "eslint/no-useless-computed-key": "error",
240
+ "eslint/no-useless-concat": "error",
241
+ "eslint/no-useless-constructor": "error",
242
+ "eslint/no-useless-return": "error",
243
+ "eslint/no-var": "error",
244
+ "eslint/no-void": ["error", { allowAsStatement: true }],
245
+ "eslint/object-shorthand": "error",
246
+ "eslint/prefer-const": "error",
247
+ "eslint/no-restricted-properties": ["error", ...NAME_BASED_RESTRICTED_PROPERTIES],
248
+ "eslint/no-restricted-imports": ["error", { paths: RESTRICTED_IMPORT_PATHS }],
249
+ "eslint/prefer-named-capture-group": "error",
250
+ "eslint/prefer-object-spread": "error",
251
+ "eslint/prefer-regex-literals": "error",
252
+ "eslint/prefer-template": "error",
253
+ "eslint/require-unicode-regexp": "error",
254
+ "typescript/array-type": "error",
255
+ "typescript/consistent-indexed-object-style": ["error", "record"],
256
+ "typescript/consistent-type-imports": "error",
257
+ "typescript/consistent-type-assertions": ["error", { assertionStyle: "never" }],
258
+ "typescript/dot-notation": "error",
259
+ "typescript/explicit-member-accessibility": "error",
260
+ "typescript/no-confusing-void-expression": "error",
261
+ "typescript/no-deprecated": "error",
262
+ "typescript/no-dynamic-delete": "error",
263
+ "typescript/no-empty-object-type": "error",
264
+ "typescript/no-explicit-any": "error",
265
+ "typescript/no-extraneous-class": "error",
266
+ "typescript/no-import-type-side-effects": "error",
267
+ "typescript/no-inferrable-types": "error",
268
+ "typescript/no-misused-promises": "error",
269
+ "typescript/no-non-null-assertion": "error",
270
+ "typescript/no-require-imports": "error",
271
+ "typescript/no-restricted-types": ["error", { types: RESTRICTED_TYPES }],
272
+ "typescript/no-unnecessary-boolean-literal-compare": "error",
273
+ "typescript/no-unnecessary-condition": "error",
274
+ "typescript/no-unnecessary-template-expression": "error",
275
+ "typescript/no-unnecessary-type-arguments": "error",
276
+ "typescript/no-unnecessary-type-constraint": "error",
277
+ "typescript/no-unnecessary-type-conversion": "error",
278
+ "typescript/no-unnecessary-type-parameters": "error",
279
+ "typescript/no-unsafe-argument": "error",
280
+ "typescript/no-unsafe-assignment": "error",
281
+ "typescript/no-unsafe-call": "error",
282
+ "typescript/no-unsafe-function-type": "error",
283
+ "typescript/no-unsafe-member-access": "error",
284
+ "typescript/no-unsafe-return": "error",
285
+ "typescript/only-throw-error": "error",
286
+ "typescript/parameter-properties": "error",
287
+ "typescript/prefer-find": "error",
288
+ "typescript/prefer-for-of": "error",
289
+ "typescript/prefer-includes": "error",
290
+ "typescript/prefer-nullish-coalescing": "error",
291
+ "typescript/prefer-optional-chain": "error",
292
+ "typescript/prefer-promise-reject-errors": "error",
293
+ "typescript/prefer-regexp-exec": "error",
294
+ "typescript/prefer-string-starts-ends-with": "error",
295
+ "typescript/strict-boolean-expressions": "error",
296
+ "typescript/strict-void-return": "error",
297
+ "typescript/switch-exhaustiveness-check": "error",
298
+ "typescript/use-unknown-in-catch-callback-variable": "error",
299
+ "unicorn/catch-error-name": "error",
300
+ "unicorn/consistent-existence-index-check": "error",
301
+ "unicorn/consistent-function-scoping": "error",
302
+ "unicorn/escape-case": "error",
303
+ "unicorn/explicit-length-check": "error",
304
+ "unicorn/filename-case": "error",
305
+ "unicorn/new-for-builtins": "error",
306
+ "unicorn/no-array-callback-reference": "error",
307
+ "unicorn/no-array-for-each": "error",
308
+ "unicorn/no-array-reduce": "error",
309
+ "unicorn/no-array-sort": "error",
310
+ "unicorn/no-hex-escape": "error",
311
+ "unicorn/no-immediate-mutation": "error",
312
+ "unicorn/no-instanceof-builtins": "error",
313
+ "unicorn/no-negated-condition": "error",
314
+ "unicorn/no-static-only-class": "error",
315
+ "unicorn/no-typeof-undefined": "error",
316
+ "unicorn/no-useless-undefined": "error",
317
+ "unicorn/numeric-separators-style": "error",
318
+ "unicorn/prefer-add-event-listener": "error",
319
+ "unicorn/prefer-array-index-of": "error",
320
+ "unicorn/prefer-array-some": "error",
321
+ "unicorn/prefer-at": "error",
322
+ "unicorn/prefer-code-point": "error",
323
+ "unicorn/prefer-logical-operator-over-ternary": "error",
324
+ "unicorn/prefer-negative-index": "error",
325
+ "unicorn/prefer-node-protocol": "error",
326
+ "unicorn/prefer-number-properties": "error",
327
+ "unicorn/prefer-single-call": "error",
328
+ "unicorn/prefer-spread": "error",
329
+ "unicorn/prefer-string-raw": "error",
330
+ "unicorn/prefer-string-replace-all": "error",
331
+ "unicorn/prefer-structured-clone": "error",
332
+ "unicorn/prefer-ternary": "error",
333
+ "unicorn/relative-url-style": "error",
334
+ "unicorn/switch-case-braces": "error",
335
+ "oxc/branches-sharing-code": "error",
336
+ "oxc/no-const-enum": "error",
337
+ "import/consistent-type-specifier-style": ["error", "prefer-top-level"],
338
+ "import/first": "error",
339
+ "import/newline-after-import": "error",
340
+ "import/no-anonymous-default-export": "error",
341
+ "import/no-cycle": "error",
342
+ "import/no-duplicates": "error",
343
+ "import/no-mutable-exports": "error",
344
+ "import/no-self-import": "error",
345
+ "import/no-unassigned-import": "error",
346
+ } as const),
347
+ ]),
348
+ } as const;
349
+
350
+ export const lintConfig = (permissionsByPath: Parameters<typeof grantPermissions>[1]) =>
351
+ grantPermissions(baseConfig, permissionsByPath);
352
+
353
+ export const FORMAT_CONFIG = {
354
+ sortImports: true,
355
+ useTabs: false,
356
+ tabWidth: 2,
357
+ printWidth: 100,
358
+ endOfLine: "lf",
359
+ insertFinalNewline: true,
360
+ singleQuote: false,
361
+ } as const;
@@ -0,0 +1,22 @@
1
+ import { Result, Schema } from "effect";
2
+
3
+ export const ruleOptionsJsonSchema = (options: Schema.Top) => [
4
+ Schema.toJsonSchemaDocument(options, { onExcessProperty: "error" }).schema,
5
+ ];
6
+
7
+ export const decodeRuleOptions = <Options extends Schema.Codec<unknown, unknown>>(
8
+ options: Options,
9
+ ruleOptions: readonly unknown[],
10
+ ) => {
11
+ const [givenOptions] = ruleOptions;
12
+ return givenOptions === undefined
13
+ ? undefined
14
+ : Schema.decodeResult(options)(givenOptions, { onExcessProperty: "error" }).pipe(
15
+ Result.match({
16
+ onFailure: (error) => {
17
+ throw error;
18
+ },
19
+ onSuccess: (decoded) => decoded,
20
+ }),
21
+ );
22
+ };