@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.
- package/LICENSE +21 -0
- package/README.md +156 -2
- package/docs/how-to-make-check-pass.md +71 -0
- package/package.json +51 -4
- package/src/index.ts +8 -0
- package/src/internal/ban-abbreviated-words-in-declared-names.ts +165 -0
- package/src/internal/ban-checked-members-outside-calls.ts +151 -0
- package/src/internal/ban-comments.ts +23 -0
- package/src/internal/ban-comparing-or-switching-on-tag.ts +114 -0
- package/src/internal/ban-deadlines-inside-tests.ts +41 -0
- package/src/internal/ban-declared-values.ts +70 -0
- package/src/internal/ban-dropped-failures-detached-fibers-sleeps-and-untraced-functions.ts +67 -0
- package/src/internal/ban-failures-collected-as-results.ts +57 -0
- package/src/internal/ban-fallbacks-of-named-recoveries.ts +118 -0
- package/src/internal/ban-function-overloads.ts +107 -0
- package/src/internal/ban-global-error-in-failure-types.ts +146 -0
- package/src/internal/ban-instanceof-in-effect-recovery-callbacks.ts +63 -0
- package/src/internal/ban-let-and-effect-mutable-ref.ts +79 -0
- package/src/internal/ban-logic-in-index-files.ts +178 -0
- package/src/internal/ban-namespaces-used-without-a-member.ts +176 -0
- package/src/internal/ban-node-builtins-that-effect-replaces.ts +42 -0
- package/src/internal/ban-parsing-outside-data-without-a-schema.ts +299 -0
- package/src/internal/ban-re-exports.ts +172 -0
- package/src/internal/ban-reading-the-clock-and-sleeping-outside-effect.ts +239 -0
- package/src/internal/ban-retired-words-in-names.ts +49 -0
- package/src/internal/ban-scanning-directories-with-bun-glob.ts +79 -0
- package/src/internal/ban-shebang-lines.ts +26 -0
- package/src/internal/ban-timer-globals-and-the-global-object.ts +34 -0
- package/src/internal/ban-timer-schedules-without-deadlines.ts +240 -0
- package/src/internal/ban-type-and-interface-declarations.ts +48 -0
- package/src/internal/ban-type-predicates.ts +82 -0
- package/src/internal/ban-unknown-in-function-signatures.ts +143 -0
- package/src/internal/ban-vague-error-class-names.ts +28 -0
- package/src/internal/ban-vague-file-names.ts +51 -0
- package/src/internal/ban-what-a-file-is-not-granted.ts +512 -0
- package/src/internal/ban-while-do-while-and-for-loops.ts +27 -0
- package/src/internal/confine-service-declarations-to-granted-files.ts +116 -0
- package/src/internal/confine-the-stdio-service-to-terminal-output.ts +190 -0
- package/src/internal/define-the-lint-plugin-and-configs.ts +361 -0
- package/src/internal/describe-and-decode-rule-options.ts +22 -0
- package/src/internal/keep-assertions-in-the-test-home-and-ban-test-runners.ts +128 -0
- package/src/internal/keep-effect-testing-helpers-in-test-files.ts +157 -0
- package/src/internal/match-banned-modules-and-globals.ts +71 -0
- package/src/internal/match-effect-service-factories.ts +20 -0
- package/src/internal/require-a-named-const-for-compound-conditions.ts +44 -0
- package/src/internal/require-capital-snake-case-and-as-const-on-literal-constants.ts +141 -0
- package/src/internal/require-service-keys-to-end-with-their-class-name.ts +64 -0
- package/src/internal/resolve-what-an-expression-imports.ts +295 -0
- package/src/internal/sort-type-constituents.ts +82 -0
- package/src/internal/split-names-into-words.ts +12 -0
- package/src/internal/visit-every-declared-name.ts +264 -0
- package/src/lib/tasks/index.ts +1 -0
- package/src/lib/tasks/internal/declare-the-check-task.ts +29 -0
- package/src/lib/tasks/internal/declare-the-checker-queries-task.ts +41 -0
- package/src/lib/tasks/internal/declare-the-typed-checks-task.ts +25 -0
- package/src/lib/tasks/internal/run-checks-over-one-typescript-project.ts +68 -0
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/index.ts +15 -0
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/check-effect-diagnostics-with-effect-tsgo.ts +211 -0
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/read-effect-tsgo-json-report.ts +39 -0
- package/src/lib/tasks/lib/check-import-boundaries/index.ts +1 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/find-import-boundary-violations.ts +415 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/find-subpath-import-targets.ts +117 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/find-what-hides-an-import.ts +65 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/import-boundary-errors.ts +176 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/index.ts +1 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/declared-use-errors.ts +32 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/find-declared-use-violations.ts +38 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/find-sync-calls.ts +23 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/find-type-only-schemas.ts +375 -0
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/index.ts +1 -0
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/find-layer-provides-outside-program-starts.ts +648 -0
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/layer-provide-errors.ts +27 -0
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/resolve-imported-package-apis.ts +262 -0
- package/src/lib/tasks/lib/confine-stdio-to-granted-files/index.ts +1 -0
- package/src/lib/tasks/lib/confine-stdio-to-granted-files/internal/find-ungranted-stdio-uses.ts +219 -0
- package/src/lib/tasks/lib/confine-stdio-to-granted-files/internal/stdio-use-errors.ts +31 -0
- package/src/lib/tasks/lib/detect-inferrable-annotations/index.ts +1 -0
- package/src/lib/tasks/lib/detect-inferrable-annotations/internal/find-inferrable-annotations.ts +357 -0
- package/src/lib/tasks/lib/detect-inferrable-annotations/internal/inferrable-annotation-errors.ts +33 -0
- package/src/lib/tasks/lib/detect-repeated-service-yields/index.ts +1 -0
- package/src/lib/tasks/lib/detect-repeated-service-yields/internal/find-repeated-service-yields.ts +162 -0
- package/src/lib/tasks/lib/detect-repeated-service-yields/internal/repeated-service-yield-errors.ts +25 -0
- package/src/lib/tasks/lib/enforce-file-layout/index.ts +5 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/check-the-layout-of-each-package.ts +9 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/file-layout-errors.ts +417 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-export-path-mismatches.ts +83 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +827 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-module-layout-violations.ts +82 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/resolve-task-imports.ts +178 -0
- package/src/lib/tasks/lib/enforce-file-types/index.ts +5 -0
- package/src/lib/tasks/lib/enforce-file-types/internal/file-type-errors.ts +21 -0
- package/src/lib/tasks/lib/enforce-file-types/internal/find-file-type-violations.ts +78 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/index.ts +1 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/check-formatting-with-bun-fmt.ts +157 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/declare-the-formatting-task.ts +66 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/find-format-config-violations.ts +16 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/find-format-input-violations.ts +74 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/find-symbolic-links.ts +14 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/unformatted-file-errors.ts +12 -0
- package/src/lib/tasks/lib/judge-index-re-exports/index.ts +1 -0
- package/src/lib/tasks/lib/judge-index-re-exports/internal/find-index-re-export-violations.ts +353 -0
- package/src/lib/tasks/lib/judge-index-re-exports/internal/index-re-export-errors.ts +21 -0
- package/src/lib/tasks/lib/lint-with-oxlint/index.ts +15 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/check-lint-rules-with-oxlint.ts +123 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/check-unsafe-enum-assignments.ts +152 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/find-tsgolint-executable.ts +21 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/read-oxlint-json-report.ts +82 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/read-tsgolint-rule-messages.ts +68 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/index.ts +1 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/export-placement-errors.ts +135 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-export-placement-violations.ts +507 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-misplaced-files.ts +116 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-subdivided-directories.ts +29 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-the-importer-graph.ts +451 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/list-binding-names.ts +49 -0
- package/src/lib/tasks/lib/refuse-disable-directives/index.ts +15 -0
- package/src/lib/tasks/lib/refuse-disable-directives/internal/disable-directive-errors.ts +45 -0
- package/src/lib/tasks/lib/refuse-disable-directives/internal/find-disable-directives.ts +66 -0
- package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/index.ts +1 -0
- package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/internal/error-mapping-errors.ts +21 -0
- package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/internal/find-error-mappings-to-done.ts +135 -0
- package/src/lib/tasks/lib/require-separate-service-layers/index.ts +1 -0
- package/src/lib/tasks/lib/require-separate-service-layers/internal/find-service-layer-violations.ts +170 -0
- package/src/lib/tasks/lib/require-separate-service-layers/internal/service-layer-errors.ts +21 -0
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/index.ts +14 -0
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/find-linted-files-not-type-checked.ts +117 -0
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/linted-file-errors.ts +51 -0
- package/src/lib/tasks/lib/type-check-with-bun-check/index.ts +11 -0
- package/src/lib/tasks/lib/type-check-with-bun-check/internal/check-types-with-bun-check.ts +54 -0
- package/src/lib/tasks/lib/type-check-with-bun-check/internal/read-bun-check-output.ts +73 -0
- package/src/lib/tasks/lib/type-check-with-bun-check/internal/type-check-errors.ts +10 -0
- package/src/lib/tasks/shared/check-each-nested-package.ts +79 -0
- package/src/lib/tasks/shared/classify-files-by-role.ts +115 -0
- package/src/lib/tasks/shared/count-the-line-of-an-offset.ts +2 -0
- package/src/lib/tasks/shared/create-the-module-resolver.ts +38 -0
- package/src/lib/tasks/shared/declare-lint-config-task.ts +13 -0
- package/src/lib/tasks/shared/declare-typescript-config-task.ts +18 -0
- package/src/lib/tasks/shared/encode-compact-json.ts +5 -0
- package/src/lib/tasks/shared/find-installed-package-binaries.ts +62 -0
- package/src/lib/tasks/shared/find-module-requests.ts +482 -0
- package/src/lib/tasks/shared/find-named-package-manifests.ts +94 -0
- package/src/lib/tasks/shared/find-unmet-typescript-config-requirements.ts +60 -0
- package/src/lib/tasks/shared/list-ignored-files-imported-by-source.ts +79 -0
- package/src/lib/tasks/shared/list-linted-files.ts +28 -0
- package/src/lib/tasks/shared/list-owned-files.ts +13 -0
- package/src/lib/tasks/shared/list-package-files.ts +66 -0
- package/src/lib/tasks/shared/load-the-lint-config.ts +176 -0
- package/src/lib/tasks/shared/match-granted-patch-files.ts +88 -0
- package/src/lib/tasks/shared/parse-config-files-that-import-from-check.ts +310 -0
- package/src/lib/tasks/shared/print-failures-and-keep-detail-in-the-trace.ts +99 -0
- package/src/lib/tasks/shared/project-config-and-tool-errors.ts +485 -0
- package/src/lib/tasks/shared/query-the-typescript-project.ts +635 -0
- package/src/lib/tasks/shared/read-named-package-manifests.ts +53 -0
- package/src/lib/tasks/shared/read-package-manifest-object.ts +28 -0
- package/src/lib/tasks/shared/resolve-absolute-paths.ts +4 -0
- package/src/lib/tasks/shared/resolve-module-requests.ts +121 -0
- package/src/lib/tasks/shared/run-tools-and-decode-their-reports.ts +98 -0
- package/src/lib/tasks/shared/tool-file-locations.ts +38 -0
- package/src/shared/bans-each-permission-lifts.ts +454 -0
- package/src/shared/config-file-names.ts +3 -0
- package/src/shared/find-retired-words.ts +17 -0
- package/src/shared/format-reported-failures.ts +31 -0
- package/src/shared/lint-rule-messages-and-patterns.ts +104 -0
- package/src/shared/match-file-names-and-path-prefixes.ts +18 -0
- package/src/shared/permission-grant-errors.ts +42 -0
- package/src/shared/record-and-grant-permissions-by-path.ts +419 -0
- package/src/shared/test-home-directories.ts +4 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import type { ESTree, Scope, SourceCode, Variable } from "@oxlint/plugins";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_EXPORT = "default";
|
|
4
|
+
|
|
5
|
+
const variableVisibleFrom = (scope: Scope, name: string): Variable | undefined => {
|
|
6
|
+
const variable = scope.set.get(name);
|
|
7
|
+
if (variable) {
|
|
8
|
+
return variable;
|
|
9
|
+
}
|
|
10
|
+
if (!scope.upper) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
return variableVisibleFrom(scope.upper, name);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const moduleExportName = (name: ESTree.ModuleExportName) =>
|
|
17
|
+
name.type === "Identifier" ? name.name : name.value;
|
|
18
|
+
|
|
19
|
+
export const enclosingFunction = (
|
|
20
|
+
node: ESTree.Node,
|
|
21
|
+
): ESTree.ArrowFunctionExpression | ESTree.Function | undefined => {
|
|
22
|
+
const parent = node.parent;
|
|
23
|
+
if (!parent) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
const isFunction =
|
|
27
|
+
parent.type === "ArrowFunctionExpression" ||
|
|
28
|
+
parent.type === "FunctionExpression" ||
|
|
29
|
+
parent.type === "FunctionDeclaration";
|
|
30
|
+
return isFunction ? parent : enclosingFunction(parent);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const resolvedVariable = (
|
|
34
|
+
node: ESTree.Node,
|
|
35
|
+
sourceCode: SourceCode,
|
|
36
|
+
): Variable | undefined => {
|
|
37
|
+
if (node.type !== "Identifier") {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
return variableVisibleFrom(sourceCode.getScope(node), node.name);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const staticKeyName = (key: ESTree.Node) => {
|
|
44
|
+
const isTemplateWithoutExpressions =
|
|
45
|
+
key.type === "TemplateLiteral" && key.expressions.length === 0;
|
|
46
|
+
if (isTemplateWithoutExpressions) {
|
|
47
|
+
const cooked = key.quasis[0]?.value.cooked;
|
|
48
|
+
return cooked === null ? undefined : cooked;
|
|
49
|
+
}
|
|
50
|
+
const isStringLiteral = key.type === "Literal" && typeof key.value === "string";
|
|
51
|
+
return isStringLiteral ? key.value : undefined;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const memberName = (node: ESTree.MemberExpression) => {
|
|
55
|
+
const isUncomputedIdentifierProperty = !node.computed && node.property.type === "Identifier";
|
|
56
|
+
return isUncomputedIdentifierProperty ? node.property.name : staticKeyName(node.property);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const withMember = (
|
|
60
|
+
imported: ReturnType<typeof importedExpression>,
|
|
61
|
+
member: string | undefined,
|
|
62
|
+
) => {
|
|
63
|
+
const isMissingImportOrMember = imported === undefined || member === undefined;
|
|
64
|
+
return isMissingImportOrMember
|
|
65
|
+
? undefined
|
|
66
|
+
: { module: imported.module, members: [...imported.members, member] };
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const unwrappedExpression = (node: ESTree.Node): ESTree.Node => {
|
|
70
|
+
const isTypeScriptWrapper =
|
|
71
|
+
node.type === "TSAsExpression" ||
|
|
72
|
+
node.type === "TSSatisfiesExpression" ||
|
|
73
|
+
node.type === "TSTypeAssertion" ||
|
|
74
|
+
node.type === "TSNonNullExpression";
|
|
75
|
+
return isTypeScriptWrapper ? unwrappedExpression(node.expression) : node;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export const importedExpression = (
|
|
79
|
+
expression: ESTree.Node,
|
|
80
|
+
sourceCode: SourceCode,
|
|
81
|
+
):
|
|
82
|
+
| {
|
|
83
|
+
readonly module: string;
|
|
84
|
+
readonly members: readonly string[];
|
|
85
|
+
}
|
|
86
|
+
| undefined => {
|
|
87
|
+
const node = unwrappedExpression(expression);
|
|
88
|
+
if (node.type === "MemberExpression") {
|
|
89
|
+
return withMember(importedExpression(node.object, sourceCode), memberName(node));
|
|
90
|
+
}
|
|
91
|
+
if (node.type !== "Identifier") {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
const definition = resolvedVariable(node, sourceCode)?.defs[0]?.node;
|
|
95
|
+
if (definition?.parent?.type !== "ImportDeclaration") {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
const module = definition.parent.source.value;
|
|
99
|
+
if (definition.type !== "ImportSpecifier") {
|
|
100
|
+
return { module, members: [] };
|
|
101
|
+
}
|
|
102
|
+
const importedName = moduleExportName(definition.imported);
|
|
103
|
+
return { module, members: importedName === DEFAULT_EXPORT ? [] : [importedName] };
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const isEffectModule = (
|
|
107
|
+
imported: NonNullable<ReturnType<typeof importedExpression>>,
|
|
108
|
+
moduleName: string,
|
|
109
|
+
) =>
|
|
110
|
+
(imported.module === "effect" &&
|
|
111
|
+
imported.members.length === 1 &&
|
|
112
|
+
imported.members[0] === moduleName) ||
|
|
113
|
+
(imported.module === `effect/${moduleName}` && imported.members.length === 0);
|
|
114
|
+
|
|
115
|
+
export const effectModuleOperation = (
|
|
116
|
+
node: ESTree.Node,
|
|
117
|
+
sourceCode: SourceCode,
|
|
118
|
+
moduleName: string,
|
|
119
|
+
) => {
|
|
120
|
+
const imported = importedExpression(node, sourceCode);
|
|
121
|
+
if (imported === undefined) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (imported.members.length === 0) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const operation = imported.members.at(-1);
|
|
128
|
+
return isEffectModule(
|
|
129
|
+
{ module: imported.module, members: imported.members.slice(0, -1) },
|
|
130
|
+
moduleName,
|
|
131
|
+
)
|
|
132
|
+
? operation
|
|
133
|
+
: undefined;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const referencesEffectModule = (
|
|
137
|
+
imported: NonNullable<ReturnType<typeof importedExpression>>,
|
|
138
|
+
moduleName: string,
|
|
139
|
+
) =>
|
|
140
|
+
imported.module === `effect/${moduleName}` ||
|
|
141
|
+
(imported.module === "effect" && imported.members[0] === moduleName);
|
|
142
|
+
|
|
143
|
+
const CLASS_MEMBER_TYPES = new Set(["MethodDefinition", "PropertyDefinition", "AccessorProperty"]);
|
|
144
|
+
|
|
145
|
+
export const isMemberExpressionObject = (node: ESTree.Node) =>
|
|
146
|
+
node.parent?.type === "MemberExpression" && node.parent.object === node;
|
|
147
|
+
|
|
148
|
+
export const isShorthandKey = (node: ESTree.Node) =>
|
|
149
|
+
node.parent?.type === "Property" && node.parent.shorthand && node.parent.key === node;
|
|
150
|
+
|
|
151
|
+
const TYPESCRIPT_VALUE_WRAPPERS: ReadonlySet<string> = new Set([
|
|
152
|
+
"TSAsExpression",
|
|
153
|
+
"TSSatisfiesExpression",
|
|
154
|
+
"TSNonNullExpression",
|
|
155
|
+
"TSTypeAssertion",
|
|
156
|
+
"TSInstantiationExpression",
|
|
157
|
+
"TSExportAssignment",
|
|
158
|
+
]);
|
|
159
|
+
|
|
160
|
+
const isWrappedByTypeScript = (node: ESTree.Node, parent: ESTree.Node) =>
|
|
161
|
+
TYPESCRIPT_VALUE_WRAPPERS.has(parent.type) &&
|
|
162
|
+
"expression" in parent &&
|
|
163
|
+
parent.expression === node;
|
|
164
|
+
|
|
165
|
+
const isExportedValue = (node: ESTree.Node, parent: ESTree.Node) =>
|
|
166
|
+
(parent.type === "ExportDefaultDeclaration" && parent.declaration === node) ||
|
|
167
|
+
(parent.type === "ExportSpecifier" && parent.local === node);
|
|
168
|
+
|
|
169
|
+
export const isValueOperandOfTypeScriptOrExport = (node: ESTree.Node, parent: ESTree.Node) =>
|
|
170
|
+
isWrappedByTypeScript(node, parent) || isExportedValue(node, parent);
|
|
171
|
+
|
|
172
|
+
export const isReferencePosition = (node: ESTree.Node): boolean => {
|
|
173
|
+
const parent = node.parent;
|
|
174
|
+
if (!parent) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
if (isWrappedByTypeScript(node, parent)) {
|
|
178
|
+
return isReferencePosition(parent);
|
|
179
|
+
}
|
|
180
|
+
if (parent.type === "MemberExpression") {
|
|
181
|
+
return parent.object !== node && parent.computed;
|
|
182
|
+
}
|
|
183
|
+
const isPropertyKey = parent.type === "Property" && parent.key === node;
|
|
184
|
+
if (isPropertyKey) {
|
|
185
|
+
return parent.shorthand;
|
|
186
|
+
}
|
|
187
|
+
const isClassMemberKey =
|
|
188
|
+
CLASS_MEMBER_TYPES.has(parent.type) && "key" in parent && parent.key === node;
|
|
189
|
+
if (isClassMemberKey) {
|
|
190
|
+
return "computed" in parent && parent.computed;
|
|
191
|
+
}
|
|
192
|
+
return (
|
|
193
|
+
!parent.type.startsWith("Import") &&
|
|
194
|
+
!parent.type.startsWith("Export") &&
|
|
195
|
+
!parent.type.startsWith("TS")
|
|
196
|
+
);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const isOutermostReference = (node: ESTree.Node) => {
|
|
200
|
+
const parent = node.parent;
|
|
201
|
+
const isObjectOfMemberExpression = parent?.type === "MemberExpression" && parent.object === node;
|
|
202
|
+
return !isObjectOfMemberExpression && (node.type !== "Identifier" || isReferencePosition(node));
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const effectModuleUsage = (
|
|
206
|
+
imported: NonNullable<ReturnType<typeof importedExpression>>,
|
|
207
|
+
moduleName: string,
|
|
208
|
+
) => {
|
|
209
|
+
if (!referencesEffectModule(imported, moduleName)) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
return imported.module === "effect"
|
|
213
|
+
? imported.members.join(".")
|
|
214
|
+
: [moduleName, ...imported.members].join(".");
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
export const effectModuleReference = (
|
|
218
|
+
node: ESTree.Node,
|
|
219
|
+
sourceCode: SourceCode,
|
|
220
|
+
moduleName: string,
|
|
221
|
+
) => {
|
|
222
|
+
if (!isOutermostReference(node)) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const imported = importedExpression(node, sourceCode);
|
|
226
|
+
return imported === undefined ? undefined : effectModuleUsage(imported, moduleName);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
export const isGlobalReference = (node: ESTree.Node, sourceCode: SourceCode, name: string) => {
|
|
230
|
+
const isIdentifierWithName = node.type === "Identifier" && node.name === name;
|
|
231
|
+
if (!isIdentifierWithName) {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
const variable = resolvedVariable(node, sourceCode);
|
|
235
|
+
return variable === undefined || variable.defs.length === 0;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const FROM_KEYWORD = "from";
|
|
239
|
+
|
|
240
|
+
export const importsEmptyBraces = (declaration: ESTree.ImportDeclaration, sourceCode: SourceCode) =>
|
|
241
|
+
declaration.importKind !== "type" &&
|
|
242
|
+
declaration.specifiers.length === 0 &&
|
|
243
|
+
sourceCode.getTokenBefore(declaration.source)?.value === FROM_KEYWORD;
|
|
244
|
+
|
|
245
|
+
export const importsOnlyTypes = (declaration: ESTree.ImportDeclaration, sourceCode: SourceCode) =>
|
|
246
|
+
declaration.importKind === "type" ||
|
|
247
|
+
importsEmptyBraces(declaration, sourceCode) ||
|
|
248
|
+
(declaration.specifiers.length > 0 &&
|
|
249
|
+
declaration.specifiers.every(
|
|
250
|
+
(specifier) => specifier.type === "ImportSpecifier" && specifier.importKind === "type",
|
|
251
|
+
));
|
|
252
|
+
|
|
253
|
+
export const propertyKeyName = (property: ESTree.Node) => {
|
|
254
|
+
if (property.type !== "Property") {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const { computed, key } = property;
|
|
258
|
+
const isUncomputedIdentifierKey = !computed && key.type === "Identifier";
|
|
259
|
+
return isUncomputedIdentifierKey ? key.name : staticKeyName(key);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
export const effectOperation = (node: ESTree.Node, sourceCode: SourceCode) =>
|
|
263
|
+
effectModuleOperation(node, sourceCode, "Effect");
|
|
264
|
+
|
|
265
|
+
const LINE_BREAKS = /\r\n|[\n\r]/gu;
|
|
266
|
+
|
|
267
|
+
const LINE_BREAK = String.raw`\n`;
|
|
268
|
+
|
|
269
|
+
const onOneLine = (text: string) => text.replace(LINE_BREAKS, LINE_BREAK);
|
|
270
|
+
|
|
271
|
+
export const importedBindingOf = (expression: ESTree.Node, sourceCode: SourceCode) => {
|
|
272
|
+
const value = unwrappedExpression(expression);
|
|
273
|
+
const isMember = value.type === "MemberExpression";
|
|
274
|
+
const binding = isMember ? value.object : value;
|
|
275
|
+
if (binding.type !== "Identifier") {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const imported = importedExpression(binding, sourceCode);
|
|
279
|
+
if (imported === undefined) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (!isMember) {
|
|
283
|
+
return { name: binding.name, member: undefined, module: imported.module };
|
|
284
|
+
}
|
|
285
|
+
return memberName(value) === undefined
|
|
286
|
+
? undefined
|
|
287
|
+
: {
|
|
288
|
+
name: binding.name,
|
|
289
|
+
member: onOneLine(sourceCode.getText(value)),
|
|
290
|
+
module: imported.module,
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
export const isImportBinding = (node: ESTree.Node, sourceCode: SourceCode) =>
|
|
295
|
+
resolvedVariable(node, sourceCode)?.defs[0]?.node.parent?.type === "ImportDeclaration";
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import type { ESTree } from "@oxlint/plugins";
|
|
3
|
+
|
|
4
|
+
const GROUPS = [
|
|
5
|
+
["TSArrayType", "TSIndexedAccessType", "TSInferType", "TSTypeReference", "TSQualifiedName"],
|
|
6
|
+
[
|
|
7
|
+
"TSAnyKeyword",
|
|
8
|
+
"TSBigIntKeyword",
|
|
9
|
+
"TSBooleanKeyword",
|
|
10
|
+
"TSNeverKeyword",
|
|
11
|
+
"TSNumberKeyword",
|
|
12
|
+
"TSObjectKeyword",
|
|
13
|
+
"TSStringKeyword",
|
|
14
|
+
"TSSymbolKeyword",
|
|
15
|
+
"TSThisType",
|
|
16
|
+
"TSUnknownKeyword",
|
|
17
|
+
"TSIntrinsicKeyword",
|
|
18
|
+
],
|
|
19
|
+
["TSTypeOperator", "TSTypeQuery"],
|
|
20
|
+
["TSLiteralType", "TSTemplateLiteralType"],
|
|
21
|
+
["TSConstructorType", "TSFunctionType"],
|
|
22
|
+
["TSImportType"],
|
|
23
|
+
["TSConditionalType"],
|
|
24
|
+
["TSMappedType", "TSTypeLiteral"],
|
|
25
|
+
["TSTupleType"],
|
|
26
|
+
["TSIntersectionType"],
|
|
27
|
+
["TSUnionType"],
|
|
28
|
+
["TSNullKeyword", "TSUndefinedKeyword", "TSVoidKeyword"],
|
|
29
|
+
] as const;
|
|
30
|
+
|
|
31
|
+
const unparenthesized = (node: ESTree.TSType): ESTree.TSType =>
|
|
32
|
+
node.type === "TSParenthesizedType" ? unparenthesized(node.typeAnnotation) : node;
|
|
33
|
+
|
|
34
|
+
const groupOf = (node: ESTree.TSType) =>
|
|
35
|
+
GROUPS.findIndex((group) => group.some((kind) => kind === unparenthesized(node).type));
|
|
36
|
+
|
|
37
|
+
const typeParentOf = (
|
|
38
|
+
node: ESTree.TSIntersectionType | ESTree.TSParenthesizedType | ESTree.TSUnionType,
|
|
39
|
+
): ESTree.Node =>
|
|
40
|
+
node.parent.type === "TSParenthesizedType" ? typeParentOf(node.parent) : node.parent;
|
|
41
|
+
|
|
42
|
+
export const noUnsortedTypeConstituents = defineRule({
|
|
43
|
+
meta: {
|
|
44
|
+
type: "suggestion",
|
|
45
|
+
schema: [],
|
|
46
|
+
messages: {
|
|
47
|
+
notSorted: "{{type}} type constituents must be sorted",
|
|
48
|
+
notSortedNamed: "{{type}} type {{name}} constituents must be sorted",
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
create(context) {
|
|
52
|
+
const compare = (left: ESTree.TSType, right: ESTree.TSType) => {
|
|
53
|
+
const leftText = context.sourceCode.getText(unparenthesized(left));
|
|
54
|
+
const rightText = context.sourceCode.getText(unparenthesized(right));
|
|
55
|
+
return (
|
|
56
|
+
groupOf(left) - groupOf(right) ||
|
|
57
|
+
leftText.localeCompare(rightText, "en", { numeric: true, sensitivity: "base" }) ||
|
|
58
|
+
(leftText < rightText ? -1 : Number(leftText > rightText))
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
const check = (node: ESTree.TSIntersectionType | ESTree.TSUnionType) => {
|
|
62
|
+
const isSorted = node.types.every((constituent, index) => {
|
|
63
|
+
const previous = node.types[index - 1];
|
|
64
|
+
return previous === undefined || compare(previous, constituent) <= 0;
|
|
65
|
+
});
|
|
66
|
+
if (isSorted) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const parent = typeParentOf(node);
|
|
70
|
+
const alias = parent.type === "TSTypeAliasDeclaration" ? parent : undefined;
|
|
71
|
+
context.report({
|
|
72
|
+
node,
|
|
73
|
+
messageId: alias === undefined ? "notSorted" : "notSortedNamed",
|
|
74
|
+
data: {
|
|
75
|
+
type: node.type === "TSUnionType" ? "Union" : "Intersection",
|
|
76
|
+
name: alias?.id.name ?? "",
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
return { TSUnionType: check, TSIntersectionType: check };
|
|
81
|
+
},
|
|
82
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const IDENTIFIER_WORDS = /[A-Z]+(?![a-z])|[A-Z]?[a-z]+|\d+/gu;
|
|
2
|
+
|
|
3
|
+
export const identifierWords = (name: string) =>
|
|
4
|
+
Array.from(name.matchAll(IDENTIFIER_WORDS), (match) => ({
|
|
5
|
+
text: match[0],
|
|
6
|
+
start: match.index,
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
export const fileNameWords = (fileName: string) => {
|
|
10
|
+
const parts = fileName.replace(/^\./u, "").split(".");
|
|
11
|
+
return (parts.length > 1 ? parts.slice(0, -1) : parts).flatMap((part) => part.split(/[-_]/u));
|
|
12
|
+
};
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import type { ESTree, Visitor } from "@oxlint/plugins";
|
|
2
|
+
|
|
3
|
+
const isExternalPropertyName = (property: ESTree.Node) => {
|
|
4
|
+
if (property.type !== "Property") {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
if (property.computed) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
if (property.key.type !== "Identifier") {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const value = property.value.type === "AssignmentPattern" ? property.value.left : property.value;
|
|
14
|
+
return value.type === "Identifier" && value.name === property.key.name;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const bindingsIn = (scope: "every" | "own") => {
|
|
18
|
+
const bindings = (pattern: ESTree.Node | null): readonly ESTree.Node[] => {
|
|
19
|
+
if (pattern === null) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
if (pattern.type === "Identifier") {
|
|
23
|
+
return [pattern];
|
|
24
|
+
}
|
|
25
|
+
if (pattern.type === "ObjectPattern") {
|
|
26
|
+
return pattern.properties
|
|
27
|
+
.filter((property) => scope === "every" || !isExternalPropertyName(property))
|
|
28
|
+
.flatMap((property) =>
|
|
29
|
+
property.type === "RestElement" ? bindings(property.argument) : bindings(property.value),
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
if (pattern.type === "ArrayPattern") {
|
|
33
|
+
return pattern.elements.flatMap(bindings);
|
|
34
|
+
}
|
|
35
|
+
if (pattern.type === "RestElement") {
|
|
36
|
+
return bindings(pattern.argument);
|
|
37
|
+
}
|
|
38
|
+
if (pattern.type === "AssignmentPattern") {
|
|
39
|
+
return bindings(pattern.left);
|
|
40
|
+
}
|
|
41
|
+
if (pattern.type === "TSParameterProperty") {
|
|
42
|
+
return bindings(pattern.parameter);
|
|
43
|
+
}
|
|
44
|
+
return [];
|
|
45
|
+
};
|
|
46
|
+
return bindings;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const named = (key: ESTree.Node, computed: boolean) => {
|
|
50
|
+
const isUncomputedName =
|
|
51
|
+
!computed && (key.type === "Identifier" || key.type === "PrivateIdentifier");
|
|
52
|
+
return isUncomputedName ? [key] : [];
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const referencedTypeNames = (type: ESTree.Node): readonly string[] => {
|
|
56
|
+
if (type.type === "TSTypeReference") {
|
|
57
|
+
return referencedTypeNames(type.typeName);
|
|
58
|
+
}
|
|
59
|
+
if (type.type === "TSQualifiedName") {
|
|
60
|
+
return [...referencedTypeNames(type.left), ...referencedTypeNames(type.right)];
|
|
61
|
+
}
|
|
62
|
+
if (type.type === "Identifier") {
|
|
63
|
+
return [type.name];
|
|
64
|
+
}
|
|
65
|
+
if (type.type === "TSArrayType") {
|
|
66
|
+
return referencedTypeNames(type.elementType);
|
|
67
|
+
}
|
|
68
|
+
if (type.type === "TSTypeOperator") {
|
|
69
|
+
return referencedTypeNames(type.typeAnnotation);
|
|
70
|
+
}
|
|
71
|
+
if (type.type === "TSImportType") {
|
|
72
|
+
return type.qualifier === null ? [] : referencedTypeNames(type.qualifier);
|
|
73
|
+
}
|
|
74
|
+
return [];
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const programOf = (node: ESTree.Node): ESTree.Node =>
|
|
78
|
+
node.parent === null ? node : programOf(node.parent);
|
|
79
|
+
|
|
80
|
+
const memberNamesOfLocalInterface = (program: ESTree.Node, interfaceName: string) => {
|
|
81
|
+
if (program.type !== "Program") {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const declaration = program.body
|
|
85
|
+
.map((statement) =>
|
|
86
|
+
statement.type === "ExportNamedDeclaration" ? statement.declaration : statement,
|
|
87
|
+
)
|
|
88
|
+
.find(
|
|
89
|
+
(statement) =>
|
|
90
|
+
statement?.type === "TSInterfaceDeclaration" && statement.id.name === interfaceName,
|
|
91
|
+
);
|
|
92
|
+
if (declaration?.type !== "TSInterfaceDeclaration") {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
return new Set(
|
|
96
|
+
declaration.body.body.flatMap((member) => {
|
|
97
|
+
const isPropertyOrMethodSignature =
|
|
98
|
+
member.type === "TSPropertySignature" || member.type === "TSMethodSignature";
|
|
99
|
+
if (!isPropertyOrMethodSignature) {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
const { computed, key } = member;
|
|
103
|
+
const isUncomputedIdentifierKey = !computed && key.type === "Identifier";
|
|
104
|
+
return isUncomputedIdentifierKey ? [key.name] : [];
|
|
105
|
+
}),
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const INTERFACES_WITHOUT_LOCAL_DECLARATIONS_NEED_TYPE_INFORMATION = true;
|
|
110
|
+
|
|
111
|
+
const isInterfaceMember = (
|
|
112
|
+
member: ESTree.AccessorProperty | ESTree.MethodDefinition | ESTree.PropertyDefinition,
|
|
113
|
+
) => {
|
|
114
|
+
const body = member.parent;
|
|
115
|
+
const owner = body.type === "ClassBody" ? body.parent : undefined;
|
|
116
|
+
if (member.computed) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
if (member.key.type !== "Identifier") {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
const isOwnedByAClass = owner?.type === "ClassDeclaration" || owner?.type === "ClassExpression";
|
|
123
|
+
if (!isOwnedByAClass) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
const memberName = member.key.name;
|
|
127
|
+
return (owner.implements ?? []).some((heritage) => {
|
|
128
|
+
const declared =
|
|
129
|
+
heritage.expression.type === "Identifier"
|
|
130
|
+
? memberNamesOfLocalInterface(programOf(member), heritage.expression.name)
|
|
131
|
+
: undefined;
|
|
132
|
+
return declared === undefined
|
|
133
|
+
? INTERFACES_WITHOUT_LOCAL_DECLARATIONS_NEED_TYPE_INFORMATION
|
|
134
|
+
: declared.has(memberName);
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export const declaredNameListeners = (
|
|
139
|
+
check: (node: ESTree.Node, inheritedNames?: readonly string[]) => void,
|
|
140
|
+
scope: Parameters<typeof bindingsIn>[0] = "every",
|
|
141
|
+
) => {
|
|
142
|
+
const bindings = bindingsIn(scope);
|
|
143
|
+
const isOwnMember = (
|
|
144
|
+
member: ESTree.AccessorProperty | ESTree.MethodDefinition | ESTree.PropertyDefinition,
|
|
145
|
+
) => scope === "every" || !isInterfaceMember(member);
|
|
146
|
+
|
|
147
|
+
const each = (nodes: readonly ESTree.Node[]) => {
|
|
148
|
+
for (const node of nodes) {
|
|
149
|
+
check(node);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const property = (node: ESTree.AccessorProperty | ESTree.PropertyDefinition) => {
|
|
154
|
+
const isOwnNonOverridingProperty = node.override !== true && isOwnMember(node);
|
|
155
|
+
if (isOwnNonOverridingProperty) {
|
|
156
|
+
each(named(node.key, node.computed));
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const parameters = (
|
|
161
|
+
node:
|
|
162
|
+
| ESTree.ArrowFunctionExpression
|
|
163
|
+
| ESTree.Function
|
|
164
|
+
| ESTree.TSCallSignatureDeclaration
|
|
165
|
+
| ESTree.TSConstructSignatureDeclaration
|
|
166
|
+
| ESTree.TSFunctionType
|
|
167
|
+
| ESTree.TSMethodSignature,
|
|
168
|
+
) => {
|
|
169
|
+
each(node.params.flatMap(bindings));
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const declared = (node: { readonly id: ESTree.Node | null }) => {
|
|
173
|
+
each(bindings(node.id));
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
return {
|
|
177
|
+
VariableDeclarator(node) {
|
|
178
|
+
declared(node);
|
|
179
|
+
},
|
|
180
|
+
FunctionDeclaration(node) {
|
|
181
|
+
declared(node);
|
|
182
|
+
parameters(node);
|
|
183
|
+
},
|
|
184
|
+
FunctionExpression(node) {
|
|
185
|
+
declared(node);
|
|
186
|
+
parameters(node);
|
|
187
|
+
},
|
|
188
|
+
ArrowFunctionExpression(node) {
|
|
189
|
+
parameters(node);
|
|
190
|
+
},
|
|
191
|
+
TSDeclareFunction(node) {
|
|
192
|
+
declared(node);
|
|
193
|
+
parameters(node);
|
|
194
|
+
},
|
|
195
|
+
TSFunctionType(node) {
|
|
196
|
+
parameters(node);
|
|
197
|
+
},
|
|
198
|
+
TSCallSignatureDeclaration(node) {
|
|
199
|
+
parameters(node);
|
|
200
|
+
},
|
|
201
|
+
TSConstructSignatureDeclaration(node) {
|
|
202
|
+
parameters(node);
|
|
203
|
+
},
|
|
204
|
+
TSMethodSignature(node) {
|
|
205
|
+
each(named(node.key, node.computed));
|
|
206
|
+
parameters(node);
|
|
207
|
+
},
|
|
208
|
+
TSPropertySignature(node) {
|
|
209
|
+
each(named(node.key, node.computed));
|
|
210
|
+
},
|
|
211
|
+
ClassDeclaration(node) {
|
|
212
|
+
declared(node);
|
|
213
|
+
},
|
|
214
|
+
ClassExpression(node) {
|
|
215
|
+
declared(node);
|
|
216
|
+
},
|
|
217
|
+
MethodDefinition(node) {
|
|
218
|
+
const isOwnNonOverridingMethod =
|
|
219
|
+
node.override !== true && node.kind !== "constructor" && isOwnMember(node);
|
|
220
|
+
if (isOwnNonOverridingMethod) {
|
|
221
|
+
each(named(node.key, node.computed));
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
PropertyDefinition(node) {
|
|
225
|
+
property(node);
|
|
226
|
+
},
|
|
227
|
+
AccessorProperty(node) {
|
|
228
|
+
property(node);
|
|
229
|
+
},
|
|
230
|
+
TSInterfaceDeclaration(node) {
|
|
231
|
+
declared(node);
|
|
232
|
+
},
|
|
233
|
+
TSTypeAliasDeclaration(node) {
|
|
234
|
+
check(node.id, referencedTypeNames(node.typeAnnotation));
|
|
235
|
+
},
|
|
236
|
+
TSEnumDeclaration(node) {
|
|
237
|
+
declared(node);
|
|
238
|
+
},
|
|
239
|
+
TSEnumMember(node) {
|
|
240
|
+
if (node.id.type === "Identifier") {
|
|
241
|
+
check(node.id);
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
TSTypeParameter(node) {
|
|
245
|
+
check(node.name);
|
|
246
|
+
},
|
|
247
|
+
CatchClause(node) {
|
|
248
|
+
each(bindings(node.param));
|
|
249
|
+
},
|
|
250
|
+
ImportDefaultSpecifier(node) {
|
|
251
|
+
check(node.local);
|
|
252
|
+
},
|
|
253
|
+
ImportNamespaceSpecifier(node) {
|
|
254
|
+
check(node.local);
|
|
255
|
+
},
|
|
256
|
+
ImportSpecifier(node) {
|
|
257
|
+
const importsUnderADifferentLocalName =
|
|
258
|
+
node.imported.type !== "Identifier" || node.imported.name !== node.local.name;
|
|
259
|
+
if (importsUnderADifferentLocalName) {
|
|
260
|
+
check(node.local);
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
} satisfies Visitor;
|
|
264
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { check } from "./internal/declare-the-check-task.ts";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Task } from "@sshkeda/task";
|
|
2
|
+
import { Effect, Path } from "effect";
|
|
3
|
+
|
|
4
|
+
import { layout } from "../lib/enforce-file-layout/index.ts";
|
|
5
|
+
import { fileTypes } from "../lib/enforce-file-types/index.ts";
|
|
6
|
+
import { formatting } from "../lib/format-with-bun-fmt/index.ts";
|
|
7
|
+
import { lintConfigFile } from "../shared/declare-lint-config-task.ts";
|
|
8
|
+
import { typeScriptConfig } from "../shared/declare-typescript-config-task.ts";
|
|
9
|
+
import { typedChecks } from "./declare-the-typed-checks-task.ts";
|
|
10
|
+
|
|
11
|
+
const GUIDE_FILE = new URL("../../../../docs/how-to-make-check-pass.md", import.meta.url);
|
|
12
|
+
|
|
13
|
+
const pointAtTheGuide = Effect.gen(function* () {
|
|
14
|
+
const path = yield* Path.Path;
|
|
15
|
+
const guide = path.relative(path.resolve("."), yield* path.fromFileUrl(GUIDE_FILE));
|
|
16
|
+
yield* Effect.logError(`read ${guide} before you change the code`);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const check: Task.Task<void> = Task.make(
|
|
20
|
+
"check",
|
|
21
|
+
Task.allSettled([
|
|
22
|
+
typeScriptConfig,
|
|
23
|
+
lintConfigFile,
|
|
24
|
+
typedChecks,
|
|
25
|
+
formatting,
|
|
26
|
+
layout,
|
|
27
|
+
fileTypes,
|
|
28
|
+
]).pipe(Effect.tapError(() => pointAtTheGuide)),
|
|
29
|
+
);
|