@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,48 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+
3
+ export const noTypeDeclarations = defineRule({
4
+ meta: {
5
+ type: "suggestion",
6
+ docs: {
7
+ description:
8
+ "Derive types inline from the Schema or function that produces them instead of declaring type aliases, interfaces, enums, namespaces or ambient modules.",
9
+ },
10
+ messages: {
11
+ typeAlias: "type {{name}} is declared",
12
+ interface: "interface {{name}} is declared",
13
+ enum: "enum {{name}} is declared",
14
+ namespace: "{{keyword}} {{name}} is declared",
15
+ ambient: "declare {{name}} is declared",
16
+ },
17
+ },
18
+ create(context) {
19
+ return {
20
+ TSTypeAliasDeclaration(node) {
21
+ context.report({ node: node.id, messageId: "typeAlias", data: { name: node.id.name } });
22
+ },
23
+ TSInterfaceDeclaration(node) {
24
+ context.report({ node: node.id, messageId: "interface", data: { name: node.id.name } });
25
+ },
26
+ TSEnumDeclaration(node) {
27
+ context.report({ node: node.id, messageId: "enum", data: { name: node.id.name } });
28
+ },
29
+ TSModuleDeclaration(node) {
30
+ const name = context.sourceCode.getText(node.id);
31
+ const isAmbientModule = node.kind === "global" || node.id.type === "Literal";
32
+ if (isAmbientModule) {
33
+ context.report({
34
+ node,
35
+ messageId: "ambient",
36
+ data: { name: node.kind === "global" ? name : `module ${name}` },
37
+ });
38
+ return;
39
+ }
40
+ context.report({
41
+ node: node.id,
42
+ messageId: "namespace",
43
+ data: { keyword: node.kind, name },
44
+ });
45
+ },
46
+ };
47
+ },
48
+ });
@@ -0,0 +1,82 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import type { ESTree, SourceCode } from "@oxlint/plugins";
3
+ import { Schema } from "effect";
4
+
5
+ import { decodeRuleOptions, ruleOptionsJsonSchema } from "./describe-and-decode-rule-options.ts";
6
+ import { effectModuleOperation } from "./resolve-what-an-expression-imports.ts";
7
+
8
+ const SCHEMA_DECLARATIONS = ["banned", "allowed"] as const;
9
+
10
+ const TYPE_PREDICATE_OPTIONS = Schema.Struct({
11
+ schemaDeclarations: Schema.optionalKey(Schema.Literals(SCHEMA_DECLARATIONS)),
12
+ });
13
+
14
+ const SCHEMA_DECLARATION_OPERATIONS = new Set(["declare", "declareConstructor"]);
15
+
16
+ const FUNCTIONS = new Set([
17
+ "ArrowFunctionExpression",
18
+ "FunctionDeclaration",
19
+ "FunctionExpression",
20
+ "TSDeclareFunction",
21
+ "TSEmptyBodyFunctionExpression",
22
+ ]);
23
+
24
+ const isSchemaDeclarationCall = (call: ESTree.CallExpression, sourceCode: SourceCode) => {
25
+ const target = call.callee.type === "CallExpression" ? call.callee.callee : call.callee;
26
+ const operation = effectModuleOperation(target, sourceCode, "Schema");
27
+ return operation !== undefined && SCHEMA_DECLARATION_OPERATIONS.has(operation);
28
+ };
29
+
30
+ const isFunctionReturnType = (predicate: ESTree.TSTypePredicate) => {
31
+ const annotation = predicate.parent;
32
+ return annotation.parent !== null && FUNCTIONS.has(annotation.parent.type);
33
+ };
34
+
35
+ const isSchemaDeclarationCallback = (predicate: ESTree.TSTypePredicate, sourceCode: SourceCode) => {
36
+ const callback = predicate.parent.parent;
37
+ const isCallback =
38
+ callback?.type === "ArrowFunctionExpression" || callback?.type === "FunctionExpression";
39
+ if (!isCallback) {
40
+ return false;
41
+ }
42
+ const call = callback.parent;
43
+ return (
44
+ call.type === "CallExpression" &&
45
+ call.arguments.some((argument) => argument === callback) &&
46
+ isSchemaDeclarationCall(call, sourceCode)
47
+ );
48
+ };
49
+
50
+ export const noTypePredicates = defineRule({
51
+ meta: {
52
+ type: "problem",
53
+ docs: {
54
+ description:
55
+ "Let TypeScript narrow on checks it can see; a hand-written type predicate is a promise the compiler never checks, like a type assertion.",
56
+ },
57
+ messages: {
58
+ typePredicate: "`{{predicate}}` is an unchecked type predicate",
59
+ },
60
+ schema: ruleOptionsJsonSchema(TYPE_PREDICATE_OPTIONS),
61
+ },
62
+ create(context) {
63
+ const schemaDeclarations =
64
+ decodeRuleOptions(TYPE_PREDICATE_OPTIONS, context.options)?.schemaDeclarations ?? "banned";
65
+ return {
66
+ TSTypePredicate(node) {
67
+ const isLeftUnreported =
68
+ !isFunctionReturnType(node) ||
69
+ (schemaDeclarations === "allowed" &&
70
+ isSchemaDeclarationCallback(node, context.sourceCode));
71
+ if (isLeftUnreported) {
72
+ return;
73
+ }
74
+ context.report({
75
+ node,
76
+ messageId: "typePredicate",
77
+ data: { predicate: context.sourceCode.getText(node) },
78
+ });
79
+ },
80
+ };
81
+ },
82
+ });
@@ -0,0 +1,143 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import type { ESTree } from "@oxlint/plugins";
3
+
4
+ import { effectModuleOperation } from "./resolve-what-an-expression-imports.ts";
5
+
6
+ const isUnknownAnnotation = (annotation: ESTree.TSTypeAnnotation | null | undefined) =>
7
+ annotation?.typeAnnotation.type === "TSUnknownKeyword";
8
+
9
+ const annotatedParameter = (parameter: ESTree.Node) => {
10
+ if (parameter.type === "TSParameterProperty") {
11
+ return annotatedParameter(parameter.parameter);
12
+ }
13
+ if (parameter.type === "AssignmentPattern") {
14
+ return parameter.left.type === "Identifier"
15
+ ? { identifier: parameter.left, annotation: parameter.left.typeAnnotation }
16
+ : undefined;
17
+ }
18
+ if (parameter.type === "RestElement") {
19
+ return parameter.argument.type === "Identifier"
20
+ ? { identifier: parameter.argument, annotation: parameter.typeAnnotation }
21
+ : undefined;
22
+ }
23
+ return parameter.type === "Identifier"
24
+ ? { identifier: parameter, annotation: parameter.typeAnnotation }
25
+ : undefined;
26
+ };
27
+
28
+ const isCallback = (node: ESTree.ArrowFunctionExpression | ESTree.Function) =>
29
+ node.parent.type === "CallExpression" ||
30
+ (node.parent.type === "Property" && node.parent.value === node);
31
+
32
+ const reportedFunctionName = (node: Parameters<typeof isCallback>[0]) => {
33
+ if (node.id) {
34
+ return node.id.name;
35
+ }
36
+ const parent = node.parent;
37
+ if (parent.type !== "VariableDeclarator") {
38
+ return "this function";
39
+ }
40
+ const declared = parent.id;
41
+ return declared.type === "Identifier" ? declared.name : "this function";
42
+ };
43
+
44
+ const isDeclaredForExport = (node: Parameters<typeof isCallback>[0]) => {
45
+ const isFunctionDeclaration =
46
+ node.type === "FunctionDeclaration" || node.type === "TSDeclareFunction";
47
+ if (isFunctionDeclaration) {
48
+ return true;
49
+ }
50
+ const parent = node.parent;
51
+ if (parent.type === "ExportDefaultDeclaration") {
52
+ return true;
53
+ }
54
+ return (
55
+ parent.type === "VariableDeclarator" &&
56
+ parent.init === node &&
57
+ parent.parent.type === "VariableDeclaration" &&
58
+ parent.parent.parent.type === "ExportNamedDeclaration"
59
+ );
60
+ };
61
+
62
+ export const noUnknownBoundaries = defineRule({
63
+ meta: {
64
+ type: "problem",
65
+ docs: {
66
+ description:
67
+ "Keep unknown out of function signatures; decode unknown input with Schema where it enters.",
68
+ },
69
+ messages: {
70
+ parameter: "parameter {{name}} is typed unknown",
71
+ returnType: "{{name}} returns unknown",
72
+ },
73
+ },
74
+ create(context) {
75
+ const isSchemaDecoder = (callee: ESTree.Node) => {
76
+ const target = callee.type === "CallExpression" ? callee.callee : callee;
77
+ const operation = effectModuleOperation(target, context.sourceCode, "Schema");
78
+ return (
79
+ operation !== undefined && (operation.startsWith("decodeUnknown") || operation === "is")
80
+ );
81
+ };
82
+
83
+ const isDecodedRightAway = (
84
+ node: Parameters<typeof isCallback>[0],
85
+ identifier: ESTree.BindingIdentifier,
86
+ ) => {
87
+ const variable = context.sourceCode
88
+ .getDeclaredVariables(node)
89
+ .find((candidate) => candidate.name === identifier.name);
90
+ const references = variable?.references ?? [];
91
+ return (
92
+ references.length > 0 &&
93
+ references.every((reference) => {
94
+ const parent = reference.identifier.parent;
95
+ return (
96
+ parent.type === "CallExpression" &&
97
+ parent.arguments.some((argument) => argument === reference.identifier) &&
98
+ isSchemaDecoder(parent.callee)
99
+ );
100
+ })
101
+ );
102
+ };
103
+
104
+ const checkFunction = (node: Parameters<typeof isCallback>[0]) => {
105
+ for (const parameter of node.params) {
106
+ const annotated = annotatedParameter(parameter);
107
+ if (annotated === undefined) {
108
+ continue;
109
+ }
110
+ if (!isUnknownAnnotation(annotated.annotation)) {
111
+ continue;
112
+ }
113
+ const isCauseParameterOfCallback =
114
+ annotated.identifier.name === "cause" && isCallback(node);
115
+ if (isCauseParameterOfCallback) {
116
+ continue;
117
+ }
118
+ if (isDecodedRightAway(node, annotated.identifier)) {
119
+ continue;
120
+ }
121
+ context.report({
122
+ node: parameter,
123
+ messageId: "parameter",
124
+ data: { name: annotated.identifier.name },
125
+ });
126
+ }
127
+ const { returnType } = node;
128
+ const exportedFunctionReturnsUnknown =
129
+ returnType?.typeAnnotation.type === "TSUnknownKeyword" && isDeclaredForExport(node);
130
+ if (exportedFunctionReturnsUnknown) {
131
+ const name = reportedFunctionName(node);
132
+ context.report({ node: returnType, messageId: "returnType", data: { name } });
133
+ }
134
+ };
135
+
136
+ return {
137
+ FunctionDeclaration: checkFunction,
138
+ FunctionExpression: checkFunction,
139
+ ArrowFunctionExpression: checkFunction,
140
+ TSDeclareFunction: checkFunction,
141
+ };
142
+ },
143
+ });
@@ -0,0 +1,28 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import type { ESTree } from "@oxlint/plugins";
3
+
4
+ const VAGUE_ERROR_NAME = /^(?:Failure|Error|Invalid|Unknown|Refused)+$/u;
5
+
6
+ export const noVagueErrorNames = defineRule({
7
+ meta: {
8
+ type: "suggestion",
9
+ docs: {
10
+ description:
11
+ "Name a class that extends another after what went wrong, not only Failure, Error, Invalid, Unknown or Refused.",
12
+ },
13
+ messages: {
14
+ vague: "error class {{name}} has a vague name",
15
+ },
16
+ },
17
+ create(context) {
18
+ const check = (node: ESTree.Class) => {
19
+ const name = node.id?.name;
20
+ const isVaguelyNamedSubclass =
21
+ node.superClass !== null && name !== undefined && VAGUE_ERROR_NAME.test(name);
22
+ if (isVaguelyNamedSubclass) {
23
+ context.report({ node, messageId: "vague", data: { name } });
24
+ }
25
+ };
26
+ return { ClassDeclaration: check, ClassExpression: check };
27
+ },
28
+ });
@@ -0,0 +1,51 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+
3
+ import { fileNameOf, isEntryFileName } from "../shared/match-file-names-and-path-prefixes.ts";
4
+
5
+ const VAGUE_SUFFIXES: ReadonlySet<string> = new Set(["logic", "impl"]);
6
+
7
+ const VAGUE_FILE_NAMES: ReadonlySet<string> = new Set([
8
+ "utils",
9
+ "helpers",
10
+ "common",
11
+ "misc",
12
+ "types",
13
+ ...VAGUE_SUFFIXES,
14
+ ]);
15
+
16
+ const ENTRY_NAME = "index";
17
+
18
+ export const noVagueFileNames = defineRule({
19
+ meta: {
20
+ type: "suggestion",
21
+ docs: {
22
+ description: `Name files after what they do, not ${[...VAGUE_FILE_NAMES].join(", ")} or a ${[...VAGUE_SUFFIXES].map((suffix) => `.${suffix}`).join(" or ")} suffix, and keep ${ENTRY_NAME} for entries.`,
23
+ },
24
+ messages: {
25
+ vague: "file name {{fileName}} is {{name}}, which does not say what it does",
26
+ vagueSuffix: "file name {{fileName}} ends in .{{suffix}}, which does not say what it does",
27
+ index: "file name {{fileName}} is index but is not an entry",
28
+ },
29
+ },
30
+ create(context) {
31
+ return {
32
+ Program(node) {
33
+ const fileName = fileNameOf(context.filename);
34
+ const [name = "", ...suffixes] = fileName.split(".");
35
+ if (VAGUE_FILE_NAMES.has(name)) {
36
+ context.report({ node, messageId: "vague", data: { fileName, name } });
37
+ return;
38
+ }
39
+ const suffix = suffixes.find((part) => VAGUE_SUFFIXES.has(part));
40
+ if (suffix !== undefined) {
41
+ context.report({ node, messageId: "vagueSuffix", data: { fileName, suffix } });
42
+ return;
43
+ }
44
+ const isIndexOutsideAnEntryFile = name === ENTRY_NAME && !isEntryFileName(fileName);
45
+ if (isIndexOutsideAnEntryFile) {
46
+ context.report({ node, messageId: "index", data: { fileName } });
47
+ }
48
+ },
49
+ };
50
+ },
51
+ });