@milkenjoyer/toolchain 0.14.1 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -17
- package/STARTS.md +11 -0
- package/dist/effect-plugin-BsrW5_nI.mjs +79 -0
- package/dist/effect-plugin.d.mts +2 -3966
- package/dist/effect-plugin.mjs +1 -1
- package/dist/fmt-BaECz64m.mjs +8 -0
- package/dist/fmt.mjs +1 -8
- package/dist/formal.mjs +1 -1
- package/dist/guard-Doqk4Fju.mjs +143 -0
- package/dist/guard.mjs +1 -96
- package/dist/{lint-IhmtnBbx.mjs → lint-CfztB4u8.mjs} +1 -1
- package/dist/lint.mjs +1 -1
- package/dist/standard.mjs +557 -4
- package/dist/starts.d.mts +100 -0
- package/dist/starts.mjs +385 -0
- package/package.json +11 -9
- package/src/arithmetic.ts +60 -0
- package/src/compatible.ts +512 -0
- package/src/conformance.ts +56 -0
- package/src/effect-plugin.ts +24 -0
- package/src/effect-tsgo.ts +44 -0
- package/src/exceptions.ts +17 -0
- package/src/fmt.ts +13 -0
- package/src/foldkit-plugin.ts +51 -0
- package/src/guard.ts +307 -0
- package/src/hooks.ts +205 -0
- package/src/index.ts +1 -0
- package/src/knip.ts +25 -0
- package/src/lint.ts +170 -0
- package/src/plugin.ts +21 -0
- package/src/rules/no-comments.ts +36 -0
- package/src/rules/no-process-env.ts +68 -0
- package/src/rules/prefer-accessible-scene-locators.ts +227 -0
- package/src/rules/require-command-answer-names.ts +144 -0
- package/src/rules/require-past-tense-messages.ts +201 -0
- package/src/rules/use-temp-file-scoped.ts +132 -0
- package/src/rules.ts +121 -0
- package/src/shared/foldkit-api.ts +51 -0
- package/src/shared/member-path.ts +106 -0
- package/src/shared/syntax.ts +47 -0
- package/src/standard/alchemy.ts +70 -0
- package/src/standard/checks.ts +10 -1
- package/src/standard/config.ts +84 -0
- package/src/standard/domain-rules.ts +204 -0
- package/src/standard/domain.ts +296 -0
- package/src/standard/infra.ts +486 -0
- package/src/starts/boat.ts +140 -0
- package/src/starts/budget.ts +151 -0
- package/src/starts/policy.ts +171 -0
- package/src/starts.ts +84 -0
- package/src/versions.ts +221 -0
- package/dist/effect-plugin-BXUx9PPu.mjs +0 -3561
- package/dist/manifest-xQwgnYI1.mjs +0 -53
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { Diagnostic, Rule, RuleContext } from "effect-oxlint";
|
|
2
|
+
import type { ESTree } from "effect-oxlint";
|
|
3
|
+
import * as Arr from "effect/Array";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as HashSet from "effect/HashSet";
|
|
6
|
+
import * as Option from "effect/Option";
|
|
7
|
+
import * as Str from "effect/String";
|
|
8
|
+
|
|
9
|
+
import { isFoldkitCall } from "../shared/foldkit-api.ts";
|
|
10
|
+
import { propertyName, unwrapExpression } from "../shared/syntax.ts";
|
|
11
|
+
|
|
12
|
+
const IRREGULAR_PAST = HashSet.make(
|
|
13
|
+
"Ate",
|
|
14
|
+
"Became",
|
|
15
|
+
"Began",
|
|
16
|
+
"Bought",
|
|
17
|
+
"Broke",
|
|
18
|
+
"Brought",
|
|
19
|
+
"Built",
|
|
20
|
+
"Came",
|
|
21
|
+
"Caught",
|
|
22
|
+
"Chose",
|
|
23
|
+
"Did",
|
|
24
|
+
"Drew",
|
|
25
|
+
"Drove",
|
|
26
|
+
"Fell",
|
|
27
|
+
"Felt",
|
|
28
|
+
"Fled",
|
|
29
|
+
"Flew",
|
|
30
|
+
"Forgot",
|
|
31
|
+
"Found",
|
|
32
|
+
"Froze",
|
|
33
|
+
"Gave",
|
|
34
|
+
"Got",
|
|
35
|
+
"Grew",
|
|
36
|
+
"Had",
|
|
37
|
+
"Heard",
|
|
38
|
+
"Held",
|
|
39
|
+
"Hid",
|
|
40
|
+
"Hung",
|
|
41
|
+
"Kept",
|
|
42
|
+
"Knew",
|
|
43
|
+
"Laid",
|
|
44
|
+
"Led",
|
|
45
|
+
"Left",
|
|
46
|
+
"Lent",
|
|
47
|
+
"Lost",
|
|
48
|
+
"Made",
|
|
49
|
+
"Meant",
|
|
50
|
+
"Met",
|
|
51
|
+
"Paid",
|
|
52
|
+
"Ran",
|
|
53
|
+
"Rang",
|
|
54
|
+
"Rode",
|
|
55
|
+
"Rose",
|
|
56
|
+
"Said",
|
|
57
|
+
"Sang",
|
|
58
|
+
"Sank",
|
|
59
|
+
"Sat",
|
|
60
|
+
"Saw",
|
|
61
|
+
"Sent",
|
|
62
|
+
"Shook",
|
|
63
|
+
"Shot",
|
|
64
|
+
"Slept",
|
|
65
|
+
"Slid",
|
|
66
|
+
"Sold",
|
|
67
|
+
"Sought",
|
|
68
|
+
"Spent",
|
|
69
|
+
"Spoke",
|
|
70
|
+
"Stole",
|
|
71
|
+
"Stood",
|
|
72
|
+
"Struck",
|
|
73
|
+
"Stuck",
|
|
74
|
+
"Swept",
|
|
75
|
+
"Swung",
|
|
76
|
+
"Taught",
|
|
77
|
+
"Thought",
|
|
78
|
+
"Threw",
|
|
79
|
+
"Told",
|
|
80
|
+
"Took",
|
|
81
|
+
"Tore",
|
|
82
|
+
"Understood",
|
|
83
|
+
"Undid",
|
|
84
|
+
"Went",
|
|
85
|
+
"Withdrew",
|
|
86
|
+
"Woke",
|
|
87
|
+
"Won",
|
|
88
|
+
"Wore",
|
|
89
|
+
"Wrote"
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const PRESENT_ENDING_IN_ED = HashSet.make(
|
|
93
|
+
"Bed",
|
|
94
|
+
"Bleed",
|
|
95
|
+
"Breed",
|
|
96
|
+
"Embed",
|
|
97
|
+
"Exceed",
|
|
98
|
+
"Feed",
|
|
99
|
+
"Heed",
|
|
100
|
+
"Need",
|
|
101
|
+
"Proceed",
|
|
102
|
+
"Red",
|
|
103
|
+
"Seed",
|
|
104
|
+
"Shed",
|
|
105
|
+
"Shred",
|
|
106
|
+
"Speed",
|
|
107
|
+
"Succeed",
|
|
108
|
+
"Weed"
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const IMPERATIVE = /^(?:Set|Mutate)(?![a-z])/u;
|
|
112
|
+
|
|
113
|
+
const FIRST_WORD = /^[A-Z][a-z]*/u;
|
|
114
|
+
|
|
115
|
+
const problemOf = (name: string): Option.Option<string> => {
|
|
116
|
+
if (IMPERATIVE.test(name)) {
|
|
117
|
+
return Option.some("imperative");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const [word = ""] = FIRST_WORD.exec(name) ?? [];
|
|
121
|
+
|
|
122
|
+
return HashSet.has(IRREGULAR_PAST, word) ||
|
|
123
|
+
(Str.endsWith("ed")(word) && !HashSet.has(PRESENT_ENDING_IN_ED, word))
|
|
124
|
+
? Option.none()
|
|
125
|
+
: Option.some("notPastTense");
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export const requirePastTenseMessagesRule = Rule.define({
|
|
129
|
+
*create() {
|
|
130
|
+
const context = yield* RuleContext;
|
|
131
|
+
|
|
132
|
+
const reportKey = (
|
|
133
|
+
property: ESTree.Node
|
|
134
|
+
): Effect.Effect<void, never, RuleContext> => {
|
|
135
|
+
if (property.type !== "Property") {
|
|
136
|
+
return Effect.void;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return Option.match(
|
|
140
|
+
Option.flatMap(propertyName(property), (name) =>
|
|
141
|
+
Option.map(problemOf(name), (messageId) => ({ messageId, name }))
|
|
142
|
+
),
|
|
143
|
+
{
|
|
144
|
+
onNone: () => Effect.void,
|
|
145
|
+
onSome: ({ messageId, name }) =>
|
|
146
|
+
context.report(
|
|
147
|
+
Diagnostic.fromId({
|
|
148
|
+
data: { name },
|
|
149
|
+
messageId,
|
|
150
|
+
node: property.key,
|
|
151
|
+
})
|
|
152
|
+
),
|
|
153
|
+
}
|
|
154
|
+
);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
CallExpression: (
|
|
159
|
+
node: ESTree.Node
|
|
160
|
+
): Effect.Effect<void, never, RuleContext> => {
|
|
161
|
+
if (
|
|
162
|
+
node.type !== "CallExpression" ||
|
|
163
|
+
!isFoldkitCall(
|
|
164
|
+
context.sourceCode,
|
|
165
|
+
node,
|
|
166
|
+
["Message", "defineMessageUnion"],
|
|
167
|
+
["Schema", "defineMessageUnion"]
|
|
168
|
+
)
|
|
169
|
+
) {
|
|
170
|
+
return Effect.void;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return Option.match(
|
|
174
|
+
Option.map(Arr.head(node.arguments), unwrapExpression),
|
|
175
|
+
{
|
|
176
|
+
onNone: () => Effect.void,
|
|
177
|
+
onSome: (cases) =>
|
|
178
|
+
cases.type === "ObjectExpression"
|
|
179
|
+
? Effect.forEach(cases.properties, reportKey, {
|
|
180
|
+
concurrency: 1,
|
|
181
|
+
discard: true,
|
|
182
|
+
})
|
|
183
|
+
: Effect.void,
|
|
184
|
+
}
|
|
185
|
+
);
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
},
|
|
189
|
+
meta: Rule.meta({
|
|
190
|
+
description:
|
|
191
|
+
"Every Message union key is a past-tense fact with its source prefix, never Set* or Mutate*",
|
|
192
|
+
messages: {
|
|
193
|
+
imperative:
|
|
194
|
+
"`{{name}}` is an imperative name. Name the Message for the fact that happened, with its source prefix: Clicked*, Updated*, Pressed*, Submitted*, Got*, Completed*, Succeeded* or Failed*.",
|
|
195
|
+
notPastTense:
|
|
196
|
+
"`{{name}}` doesn't start with a past-tense source prefix. Name the Message for the fact that happened: Clicked*, Updated*, Pressed*, Submitted*, Got*, Completed*, Succeeded* or Failed*.",
|
|
197
|
+
},
|
|
198
|
+
type: "suggestion",
|
|
199
|
+
}),
|
|
200
|
+
name: "require-past-tense-messages",
|
|
201
|
+
});
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Diagnostic,
|
|
3
|
+
type ESTree,
|
|
4
|
+
Rule,
|
|
5
|
+
RuleContext,
|
|
6
|
+
type OxlintSourceCode,
|
|
7
|
+
} from "effect-oxlint";
|
|
8
|
+
import * as Arr from "effect/Array";
|
|
9
|
+
import * as Effect from "effect/Effect";
|
|
10
|
+
import * as Option from "effect/Option";
|
|
11
|
+
|
|
12
|
+
import { memberPropertyName } from "../shared/syntax.ts";
|
|
13
|
+
|
|
14
|
+
const isOs = (source: string): boolean =>
|
|
15
|
+
source === "os" || source === "node:os";
|
|
16
|
+
|
|
17
|
+
const isOsBinding = (
|
|
18
|
+
source: OxlintSourceCode,
|
|
19
|
+
node: Extract<ESTree.Node, { readonly type: "Identifier" }>
|
|
20
|
+
): boolean => {
|
|
21
|
+
const lookup = (scope: ReturnType<OxlintSourceCode["getScope"]>): boolean => {
|
|
22
|
+
const variable = scope.set.get(node.name);
|
|
23
|
+
if (variable === undefined) {
|
|
24
|
+
return scope.upper === null ? false : lookup(scope.upper);
|
|
25
|
+
}
|
|
26
|
+
return Arr.some(
|
|
27
|
+
variable.defs,
|
|
28
|
+
(definition) =>
|
|
29
|
+
definition.type === "ImportBinding" &&
|
|
30
|
+
(definition.node.type === "ImportDefaultSpecifier" ||
|
|
31
|
+
definition.node.type === "ImportNamespaceSpecifier") &&
|
|
32
|
+
definition.parent?.type === "ImportDeclaration" &&
|
|
33
|
+
isOs(definition.parent.source.value)
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
return lookup(source.getScope(node));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const isManagedAcquire = (node: ESTree.Node): boolean => {
|
|
40
|
+
const parent = node.parent;
|
|
41
|
+
if (parent === null) return false;
|
|
42
|
+
if (
|
|
43
|
+
parent.type === "CallExpression" &&
|
|
44
|
+
parent.arguments[0] === node &&
|
|
45
|
+
parent.callee.type === "MemberExpression" &&
|
|
46
|
+
parent.callee.object.type === "Identifier" &&
|
|
47
|
+
parent.callee.object.name === "Effect" &&
|
|
48
|
+
Option.exists(
|
|
49
|
+
memberPropertyName(parent.callee),
|
|
50
|
+
(name) => name === "acquireRelease" || name === "acquireUseRelease"
|
|
51
|
+
)
|
|
52
|
+
)
|
|
53
|
+
return true;
|
|
54
|
+
return isManagedAcquire(parent);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const useTempFileScopedRule = Rule.define({
|
|
58
|
+
name: "use-temp-file-scoped",
|
|
59
|
+
meta: Rule.meta({
|
|
60
|
+
type: "suggestion",
|
|
61
|
+
description:
|
|
62
|
+
"Prefer scoped temporary files and directories with automatic cleanup",
|
|
63
|
+
messages: {
|
|
64
|
+
tmpdir:
|
|
65
|
+
"Avoid `os.tmpdir()` — use `FileSystem.makeTempFileScoped` from `@effect/platform` for scoped temp files with automatic cleanup.",
|
|
66
|
+
unscoped:
|
|
67
|
+
"Avoid `{{api}}` — the unscoped variant requires manual cleanup. Use `{{api}}Scoped` so the resource is finalized when its scope closes.",
|
|
68
|
+
},
|
|
69
|
+
}),
|
|
70
|
+
*create() {
|
|
71
|
+
const context = yield* RuleContext;
|
|
72
|
+
return {
|
|
73
|
+
ImportDeclaration: (
|
|
74
|
+
node: ESTree.Node
|
|
75
|
+
): Effect.Effect<void, never, RuleContext> =>
|
|
76
|
+
node.type === "ImportDeclaration" && isOs(node.source.value)
|
|
77
|
+
? Effect.forEach(
|
|
78
|
+
Arr.filter(
|
|
79
|
+
node.specifiers,
|
|
80
|
+
(specifier) =>
|
|
81
|
+
specifier.type === "ImportSpecifier" &&
|
|
82
|
+
(specifier.imported.type === "Identifier"
|
|
83
|
+
? specifier.imported.name
|
|
84
|
+
: specifier.imported.value) === "tmpdir"
|
|
85
|
+
),
|
|
86
|
+
(specifier) =>
|
|
87
|
+
context.report(
|
|
88
|
+
Diagnostic.fromId({ node: specifier, messageId: "tmpdir" })
|
|
89
|
+
),
|
|
90
|
+
{ concurrency: 1, discard: true }
|
|
91
|
+
)
|
|
92
|
+
: Effect.void,
|
|
93
|
+
MemberExpression: (
|
|
94
|
+
node: ESTree.Node
|
|
95
|
+
): Effect.Effect<void, never, RuleContext> =>
|
|
96
|
+
node.type === "MemberExpression" &&
|
|
97
|
+
Option.contains(memberPropertyName(node), "tmpdir") &&
|
|
98
|
+
node.object.type === "Identifier" &&
|
|
99
|
+
isOsBinding(context.sourceCode, node.object)
|
|
100
|
+
? context.report(Diagnostic.fromId({ node, messageId: "tmpdir" }))
|
|
101
|
+
: Effect.void,
|
|
102
|
+
CallExpression: (
|
|
103
|
+
node: ESTree.Node
|
|
104
|
+
): Effect.Effect<void, never, RuleContext> => {
|
|
105
|
+
if (
|
|
106
|
+
node.type !== "CallExpression" ||
|
|
107
|
+
node.callee.type !== "MemberExpression" ||
|
|
108
|
+
isManagedAcquire(node)
|
|
109
|
+
) {
|
|
110
|
+
return Effect.void;
|
|
111
|
+
}
|
|
112
|
+
return Option.match(
|
|
113
|
+
Option.filter(
|
|
114
|
+
memberPropertyName(node.callee),
|
|
115
|
+
(name) => name === "makeTempFile" || name === "makeTempDirectory"
|
|
116
|
+
),
|
|
117
|
+
{
|
|
118
|
+
onNone: () => Effect.void,
|
|
119
|
+
onSome: (api) =>
|
|
120
|
+
context.report(
|
|
121
|
+
Diagnostic.fromId({
|
|
122
|
+
node,
|
|
123
|
+
messageId: "unscoped",
|
|
124
|
+
data: { api },
|
|
125
|
+
})
|
|
126
|
+
),
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
});
|
package/src/rules.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { OxlintConfig } from "vite-plus/lint";
|
|
2
|
+
|
|
3
|
+
const testImportPaths = [
|
|
4
|
+
{
|
|
5
|
+
name: "vitest",
|
|
6
|
+
message:
|
|
7
|
+
"Import test utilities from '@effect/vitest' instead of raw 'vitest'.",
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
name: "vite-plus/test",
|
|
11
|
+
message:
|
|
12
|
+
"Import test utilities from '@effect/vitest' instead of 'vite-plus/test'.",
|
|
13
|
+
},
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
export const staticRules = {
|
|
17
|
+
"effecttsgo/any-unknown-in-error-context": "off",
|
|
18
|
+
"effecttsgo/strict-effect-provide": "off",
|
|
19
|
+
"eslint/array-callback-return": "error",
|
|
20
|
+
"eslint/constructor-super": "off",
|
|
21
|
+
"eslint/eqeqeq": ["error", "always"],
|
|
22
|
+
"eslint/getter-return": "off",
|
|
23
|
+
"eslint/no-case-declarations": "error",
|
|
24
|
+
"eslint/no-class-assign": "off",
|
|
25
|
+
"eslint/no-console": "error",
|
|
26
|
+
"eslint/no-const-assign": "off",
|
|
27
|
+
"eslint/no-constructor-return": "error",
|
|
28
|
+
"eslint/no-delete-var": "off",
|
|
29
|
+
"eslint/no-dupe-class-members": "off",
|
|
30
|
+
"eslint/no-dupe-keys": "off",
|
|
31
|
+
"eslint/no-empty": "error",
|
|
32
|
+
"eslint/no-fallthrough": "error",
|
|
33
|
+
"eslint/no-func-assign": "off",
|
|
34
|
+
"eslint/no-implied-eval": "off",
|
|
35
|
+
"eslint/no-import-assign": "off",
|
|
36
|
+
"eslint/no-new-func": "error",
|
|
37
|
+
"eslint/no-new-native-nonconstructor": "off",
|
|
38
|
+
"eslint/no-new-wrappers": "error",
|
|
39
|
+
"eslint/no-obj-calls": "off",
|
|
40
|
+
"eslint/no-promise-executor-return": "error",
|
|
41
|
+
"eslint/no-proto": "error",
|
|
42
|
+
"eslint/no-prototype-builtins": "error",
|
|
43
|
+
"eslint/no-restricted-globals": ["error", "__dirname", "__filename"],
|
|
44
|
+
"eslint/no-restricted-imports": ["error", { paths: testImportPaths }],
|
|
45
|
+
"eslint/no-return-assign": "error",
|
|
46
|
+
"eslint/no-script-url": "error",
|
|
47
|
+
"eslint/no-self-compare": "error",
|
|
48
|
+
"eslint/no-sequences": "error",
|
|
49
|
+
"eslint/no-setter-return": "off",
|
|
50
|
+
"eslint/no-shadow": "off",
|
|
51
|
+
"eslint/no-template-curly-in-string": "error",
|
|
52
|
+
"eslint/no-this-before-super": "off",
|
|
53
|
+
"eslint/no-underscore-dangle": "off",
|
|
54
|
+
"eslint/no-unneeded-ternary": "off",
|
|
55
|
+
"eslint/no-unreachable-loop": "error",
|
|
56
|
+
"eslint/no-unsafe-negation": "off",
|
|
57
|
+
"eslint/no-useless-call": "error",
|
|
58
|
+
"eslint/no-useless-concat": "off",
|
|
59
|
+
"eslint/no-var": "error",
|
|
60
|
+
"eslint/no-with": "off",
|
|
61
|
+
"eslint/valid-typeof": "off",
|
|
62
|
+
"import/default": "off",
|
|
63
|
+
"import/namespace": "off",
|
|
64
|
+
"import/no-cycle": "error",
|
|
65
|
+
"import/no-mutable-exports": "error",
|
|
66
|
+
"import/no-unassigned-import": "off",
|
|
67
|
+
"node/no-process-env": "off",
|
|
68
|
+
"oxc/bad-bitwise-operator": "error",
|
|
69
|
+
"oxc/no-accumulating-spread": "error",
|
|
70
|
+
"promise/always-return": "off",
|
|
71
|
+
"promise/no-return-in-finally": "error",
|
|
72
|
+
"promise/valid-params": "off",
|
|
73
|
+
"typescript/ban-ts-comment": "error",
|
|
74
|
+
"typescript/method-signature-style": "error",
|
|
75
|
+
"typescript/no-deprecated": "error",
|
|
76
|
+
"typescript/no-empty-object-type": "error",
|
|
77
|
+
"typescript/no-explicit-any": "error",
|
|
78
|
+
"typescript/no-extraneous-class": "off",
|
|
79
|
+
"typescript/no-import-type-side-effects": "error",
|
|
80
|
+
"typescript/no-invalid-void-type": "error",
|
|
81
|
+
"typescript/no-misused-promises": "error",
|
|
82
|
+
"typescript/no-non-null-assertion": "error",
|
|
83
|
+
"typescript/no-unnecessary-boolean-literal-compare": "off",
|
|
84
|
+
"typescript/no-unnecessary-condition": "error",
|
|
85
|
+
"typescript/no-unnecessary-template-expression": "off",
|
|
86
|
+
"typescript/no-unnecessary-type-arguments": "off",
|
|
87
|
+
"typescript/no-unnecessary-type-constraint": "off",
|
|
88
|
+
"typescript/no-unnecessary-type-conversion": "off",
|
|
89
|
+
"typescript/no-unsafe-argument": "error",
|
|
90
|
+
"typescript/no-unsafe-assignment": "error",
|
|
91
|
+
"typescript/no-unsafe-call": "error",
|
|
92
|
+
"typescript/no-unsafe-function-type": "error",
|
|
93
|
+
"typescript/no-unsafe-member-access": "error",
|
|
94
|
+
"typescript/no-unsafe-return": "error",
|
|
95
|
+
"typescript/only-throw-error": "error",
|
|
96
|
+
"typescript/prefer-nullish-coalescing": "error",
|
|
97
|
+
"typescript/prefer-promise-reject-errors": "error",
|
|
98
|
+
"typescript/related-getter-setter-pairs": "error",
|
|
99
|
+
"typescript/require-await": "error",
|
|
100
|
+
"typescript/restrict-plus-operands": "error",
|
|
101
|
+
"typescript/strict-boolean-expressions": "error",
|
|
102
|
+
"typescript/switch-exhaustiveness-check": "error",
|
|
103
|
+
"typescript/use-unknown-in-catch-callback-variable": "error",
|
|
104
|
+
"unicorn/consistent-function-scoping": "off",
|
|
105
|
+
"unicorn/new-for-builtins": "error",
|
|
106
|
+
"unicorn/no-abusive-eslint-disable": "error",
|
|
107
|
+
"unicorn/no-document-cookie": "off",
|
|
108
|
+
"unicorn/no-negation-in-equality-check": "error",
|
|
109
|
+
"unicorn/no-new-buffer": "error",
|
|
110
|
+
"unicorn/no-object-as-default-parameter": "error",
|
|
111
|
+
"unicorn/no-unnecessary-await": "off",
|
|
112
|
+
"unicorn/require-post-message-target-origin": "off",
|
|
113
|
+
"unicorn/prefer-module": "error",
|
|
114
|
+
"unicorn/prefer-number-properties": "error",
|
|
115
|
+
"vitest/expect-expect": "off",
|
|
116
|
+
"vitest/no-identical-title": "error",
|
|
117
|
+
"vitest/no-import-node-test": "error",
|
|
118
|
+
"vitest/no-standalone-expect": "off",
|
|
119
|
+
"vitest/valid-expect": ["error", { maxArgs: 2 }],
|
|
120
|
+
"vitest/valid-title": ["error", { allowArguments: true }],
|
|
121
|
+
} satisfies OxlintConfig["rules"];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ESTree, OxlintSourceCode } from "effect-oxlint";
|
|
2
|
+
import * as Arr from "effect/Array";
|
|
3
|
+
import { dual } from "effect/Function";
|
|
4
|
+
import * as HashMap from "effect/HashMap";
|
|
5
|
+
import * as Option from "effect/Option";
|
|
6
|
+
|
|
7
|
+
import { importedPath } from "./member-path.ts";
|
|
8
|
+
import { isStringLiteral } from "./syntax.ts";
|
|
9
|
+
|
|
10
|
+
const NAMESPACES = HashMap.make<
|
|
11
|
+
ReadonlyArray<readonly [string, ReadonlyArray<string>]>
|
|
12
|
+
>(
|
|
13
|
+
["foldkit", []],
|
|
14
|
+
["foldkit/command", ["Command"]],
|
|
15
|
+
["foldkit/html", ["Html"]],
|
|
16
|
+
["foldkit/message", ["Message"]],
|
|
17
|
+
["foldkit/scene", ["Scene"]],
|
|
18
|
+
["foldkit/schema", ["Schema"]],
|
|
19
|
+
["foldkit/test", []]
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export const isFoldkitCall = (
|
|
23
|
+
sourceCode: OxlintSourceCode,
|
|
24
|
+
node: ESTree.CallExpression,
|
|
25
|
+
...wanted: ReadonlyArray<ReadonlyArray<string>>
|
|
26
|
+
): boolean =>
|
|
27
|
+
Option.exists(importedPath(sourceCode, node.callee), (path) =>
|
|
28
|
+
Option.exists(HashMap.get(NAMESPACES, path.source), (prefix) => {
|
|
29
|
+
const full = Arr.join([...prefix, ...path.members], ".");
|
|
30
|
+
|
|
31
|
+
return Arr.some(wanted, (candidate) => Arr.join(candidate, ".") === full);
|
|
32
|
+
})
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
export const textWithHoles: {
|
|
36
|
+
(hole: string): (node: ESTree.Node) => Option.Option<string>;
|
|
37
|
+
(node: ESTree.Node, hole: string): Option.Option<string>;
|
|
38
|
+
} = dual(2, (node: ESTree.Node, hole: string): Option.Option<string> => {
|
|
39
|
+
if (isStringLiteral(node)) {
|
|
40
|
+
return Option.some(node.value);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return node.type === "TemplateLiteral"
|
|
44
|
+
? Option.some(
|
|
45
|
+
Arr.join(
|
|
46
|
+
Arr.map(node.quasis, (quasi) => quasi.value.raw),
|
|
47
|
+
hole
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
: Option.none();
|
|
51
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { ESTree, OxlintSourceCode, Variable } from "effect-oxlint";
|
|
2
|
+
import * as Arr from "effect/Array";
|
|
3
|
+
import { dual } from "effect/Function";
|
|
4
|
+
import * as Option from "effect/Option";
|
|
5
|
+
|
|
6
|
+
import { memberPropertyName, unwrapExpression } from "./syntax.ts";
|
|
7
|
+
|
|
8
|
+
const resolveBinding = (
|
|
9
|
+
sourceCode: OxlintSourceCode,
|
|
10
|
+
node: Extract<ESTree.Node, { readonly type: "Identifier" }>
|
|
11
|
+
): Option.Option<Variable> => {
|
|
12
|
+
const findBinding = (
|
|
13
|
+
scope: Option.Option<ReturnType<OxlintSourceCode["getScope"]>>
|
|
14
|
+
): Option.Option<Variable> =>
|
|
15
|
+
Option.flatMap(scope, (current) =>
|
|
16
|
+
Option.orElse(Option.fromUndefinedOr(current.set.get(node.name)), () =>
|
|
17
|
+
findBinding(Option.fromNullishOr(current.upper))
|
|
18
|
+
)
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
return findBinding(Option.fromNullishOr(sourceCode.getScope(node)));
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type MemberPath = {
|
|
25
|
+
readonly root: Extract<ESTree.Node, { readonly type: "Identifier" }>;
|
|
26
|
+
readonly members: ReadonlyArray<string>;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const memberPath = (node: ESTree.Node): Option.Option<MemberPath> => {
|
|
30
|
+
const current = unwrapExpression(node);
|
|
31
|
+
|
|
32
|
+
if (current.type === "Identifier") {
|
|
33
|
+
return Option.some({ root: current, members: [] });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (current.type !== "MemberExpression") {
|
|
37
|
+
return Option.none();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return Option.flatMap(memberPath(current.object), (path) =>
|
|
41
|
+
Option.map(memberPropertyName(current), (name) => ({
|
|
42
|
+
root: path.root,
|
|
43
|
+
members: [...path.members, name],
|
|
44
|
+
}))
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const lastName = (node: ESTree.Node): Option.Option<string> =>
|
|
49
|
+
Option.map(memberPath(node), (path) =>
|
|
50
|
+
Option.getOrElse(Arr.last(path.members), () => path.root.name)
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
export type ImportedPath = {
|
|
54
|
+
readonly source: string;
|
|
55
|
+
readonly members: ReadonlyArray<string>;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const importedPath: {
|
|
59
|
+
(
|
|
60
|
+
node: ESTree.Node
|
|
61
|
+
): (sourceCode: OxlintSourceCode) => Option.Option<ImportedPath>;
|
|
62
|
+
(
|
|
63
|
+
sourceCode: OxlintSourceCode,
|
|
64
|
+
node: ESTree.Node
|
|
65
|
+
): Option.Option<ImportedPath>;
|
|
66
|
+
} = dual(
|
|
67
|
+
2,
|
|
68
|
+
(
|
|
69
|
+
sourceCode: OxlintSourceCode,
|
|
70
|
+
node: ESTree.Node
|
|
71
|
+
): Option.Option<ImportedPath> =>
|
|
72
|
+
Option.gen(function* () {
|
|
73
|
+
const path = yield* memberPath(node);
|
|
74
|
+
const variable = yield* resolveBinding(sourceCode, path.root);
|
|
75
|
+
|
|
76
|
+
const definition = yield* Arr.findFirst(
|
|
77
|
+
variable.defs,
|
|
78
|
+
(candidate) => candidate.type === "ImportBinding"
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const declaration = definition.parent;
|
|
82
|
+
const specifier = definition.node;
|
|
83
|
+
|
|
84
|
+
if (declaration?.type !== "ImportDeclaration") {
|
|
85
|
+
return yield* Option.none();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (specifier.type === "ImportNamespaceSpecifier") {
|
|
89
|
+
return { source: declaration.source.value, members: path.members };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (specifier.type !== "ImportSpecifier") {
|
|
93
|
+
return yield* Option.none();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const imported =
|
|
97
|
+
specifier.imported.type === "Identifier"
|
|
98
|
+
? specifier.imported.name
|
|
99
|
+
: specifier.imported.value;
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
source: declaration.source.value,
|
|
103
|
+
members: [imported, ...path.members],
|
|
104
|
+
};
|
|
105
|
+
})
|
|
106
|
+
);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ESTree } from "effect-oxlint";
|
|
2
|
+
import * as Option from "effect/Option";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
|
|
5
|
+
export const unwrapExpression = (node: ESTree.Node): ESTree.Node => {
|
|
6
|
+
if (
|
|
7
|
+
node.type === "ParenthesizedExpression" ||
|
|
8
|
+
node.type === "ChainExpression" ||
|
|
9
|
+
node.type === "TSAsExpression" ||
|
|
10
|
+
node.type === "TSTypeAssertion" ||
|
|
11
|
+
node.type === "TSNonNullExpression" ||
|
|
12
|
+
node.type === "TSSatisfiesExpression"
|
|
13
|
+
) {
|
|
14
|
+
return unwrapExpression(node.expression);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return node;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const isStringLiteral = (
|
|
21
|
+
node: ESTree.Node
|
|
22
|
+
): node is ESTree.StringLiteral =>
|
|
23
|
+
node.type === "Literal" && Schema.is(Schema.String)(node.value);
|
|
24
|
+
|
|
25
|
+
export const memberPropertyName = (
|
|
26
|
+
node: ESTree.MemberExpression
|
|
27
|
+
): Option.Option<string> => {
|
|
28
|
+
if (!node.computed && node.property.type === "Identifier") {
|
|
29
|
+
return Option.some(node.property.name);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return node.computed && isStringLiteral(node.property)
|
|
33
|
+
? Option.some(node.property.value)
|
|
34
|
+
: Option.none();
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const propertyName = (
|
|
38
|
+
property: Pick<ESTree.ObjectProperty, "computed" | "key">
|
|
39
|
+
): Option.Option<string> => {
|
|
40
|
+
if (!property.computed && property.key.type === "Identifier") {
|
|
41
|
+
return Option.some(property.key.name);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return isStringLiteral(property.key)
|
|
45
|
+
? Option.some(property.key.value)
|
|
46
|
+
: Option.none();
|
|
47
|
+
};
|