@siim-m/config 0.1.0 → 0.3.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 (38) hide show
  1. package/README.md +82 -5
  2. package/dist/ai-guard.d.ts +5 -0
  3. package/dist/ai-guard.js +5 -0
  4. package/dist/anti-slop/effect/LICENSE-enfect +21 -0
  5. package/dist/anti-slop/effect/index.js +8 -0
  6. package/dist/anti-slop/effect/rules/no-ordie-in-service-construction.d.ts +2 -0
  7. package/dist/anti-slop/effect/rules/no-ordie-in-service-construction.js +117 -0
  8. package/dist/anti-slop/effect/rules/no-unbounded-retry.d.ts +2 -0
  9. package/dist/anti-slop/effect/rules/no-unbounded-retry.js +307 -0
  10. package/dist/anti-slop/effect/rules/require-cause-when-narrowing.d.ts +2 -0
  11. package/dist/anti-slop/effect/rules/require-cause-when-narrowing.js +250 -0
  12. package/dist/anti-slop/effect/rules/throw-in-effect-gen.d.ts +2 -0
  13. package/dist/anti-slop/effect/rules/throw-in-effect-gen.js +87 -0
  14. package/dist/anti-slop/effect/shared/effect-modules.d.ts +79 -0
  15. package/dist/anti-slop/effect/shared/effect-modules.js +336 -0
  16. package/dist/anti-slop/index.js +6 -0
  17. package/dist/anti-slop/rules/comments.d.ts +7 -0
  18. package/dist/anti-slop/rules/comments.js +376 -0
  19. package/dist/anti-slop/rules/no-disabled-type-assertion-rules.d.ts +2 -0
  20. package/dist/anti-slop/rules/no-disabled-type-assertion-rules.js +94 -0
  21. package/dist/anti-slop/rules/require-suppression-reason.d.ts +6 -0
  22. package/dist/anti-slop/rules/require-suppression-reason.js +61 -0
  23. package/dist/anti-slop-react/LICENSE +21 -0
  24. package/dist/anti-slop-react/index.d.ts +3 -0
  25. package/dist/anti-slop-react/index.js +14 -0
  26. package/dist/anti-slop-react/rules/no-hookless-use-function.d.ts +8 -0
  27. package/dist/anti-slop-react/rules/no-hookless-use-function.js +67 -0
  28. package/dist/anti-slop-react/rules/no-manual-memo.d.ts +7 -0
  29. package/dist/anti-slop-react/rules/no-manual-memo.js +58 -0
  30. package/dist/anti-slop-react/rules/require-sync-comment-for-effect.d.ts +8 -0
  31. package/dist/anti-slop-react/rules/require-sync-comment-for-effect.js +64 -0
  32. package/dist/landmines.d.ts +5 -0
  33. package/dist/landmines.js +5 -0
  34. package/dist/oxlint-react.d.ts +62 -0
  35. package/dist/oxlint-react.js +62 -0
  36. package/dist/oxlint.d.ts +41 -0
  37. package/dist/oxlint.js +48 -1
  38. package/package.json +20 -6
@@ -0,0 +1,336 @@
1
+ /** Resolve an identifier node to its binding by walking lexical scopes upward. */
2
+ export function resolveIdentifier(sourceCode, identifier) {
3
+ let scope = sourceCode.getScope(identifier);
4
+ while (scope !== null) {
5
+ const variable = scope.set.get(identifier.name);
6
+ if (variable !== undefined)
7
+ return variable;
8
+ scope = scope.upper;
9
+ }
10
+ return null;
11
+ }
12
+ const effectModules = new Set([
13
+ "Context",
14
+ "Effect",
15
+ "HttpClient",
16
+ "Layer",
17
+ "ManagedRuntime",
18
+ "Schedule",
19
+ "Stream",
20
+ ]);
21
+ /** Barrels that re-export Effect modules as named exports. */
22
+ const moduleBarrels = new Set(["effect", "effect/http"]);
23
+ /** The module a namespace import of `source` binds: `effect/Schedule` or `effect/http/HttpClient`. */
24
+ function namespaceModule(source) {
25
+ if (source.startsWith("effect/http/"))
26
+ return source.slice("effect/http/".length);
27
+ return source.startsWith("effect/") ? source.slice("effect/".length) : "";
28
+ }
29
+ const isEffectModule = (name) => effectModules.has(name);
30
+ const importedName = (specifier) => specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
31
+ /**
32
+ * Collect `import { Effect } from "effect"`, `import { HttpClient } from "effect/http"`,
33
+ * `import * as Effect from "effect/Effect"`, and `import * as HttpClient from "effect/http/HttpClient"` bindings.
34
+ */
35
+ export function collectEffectModuleNames(program) {
36
+ const names = new Map();
37
+ const add = (module, local) => {
38
+ const existing = names.get(module) ?? new Set();
39
+ existing.add(local);
40
+ names.set(module, existing);
41
+ };
42
+ for (const statement of program.body) {
43
+ if (statement.type !== "ImportDeclaration")
44
+ continue;
45
+ const source = statement.source.value;
46
+ if (moduleBarrels.has(source)) {
47
+ for (const specifier of statement.specifiers) {
48
+ if (specifier.type !== "ImportSpecifier")
49
+ continue;
50
+ const name = importedName(specifier);
51
+ if (isEffectModule(name))
52
+ add(name, specifier.local.name);
53
+ }
54
+ continue;
55
+ }
56
+ const module = namespaceModule(source);
57
+ if (!isEffectModule(module))
58
+ continue;
59
+ for (const specifier of statement.specifiers) {
60
+ if (specifier.type === "ImportNamespaceSpecifier" || specifier.type === "ImportDefaultSpecifier") {
61
+ add(module, specifier.local.name);
62
+ }
63
+ }
64
+ }
65
+ return names;
66
+ }
67
+ /** Strip parentheses, type assertions and instantiation expressions from an expression. */
68
+ export function unwrapExpression(expression) {
69
+ let current = expression;
70
+ while (current.type === "ParenthesizedExpression" ||
71
+ current.type === "TSAsExpression" ||
72
+ current.type === "TSSatisfiesExpression" ||
73
+ current.type === "TSTypeAssertion" ||
74
+ current.type === "TSNonNullExpression" ||
75
+ current.type === "TSInstantiationExpression") {
76
+ current = current.expression;
77
+ }
78
+ return current;
79
+ }
80
+ /** Like {@link unwrapExpression}, for any node. */
81
+ export function unwrapNode(node) {
82
+ let current = node;
83
+ while (current.type === "ParenthesizedExpression" ||
84
+ current.type === "TSAsExpression" ||
85
+ current.type === "TSSatisfiesExpression" ||
86
+ current.type === "TSTypeAssertion" ||
87
+ current.type === "TSNonNullExpression" ||
88
+ current.type === "TSInstantiationExpression") {
89
+ current = current.expression;
90
+ }
91
+ return current;
92
+ }
93
+ /** The member name when `node` is `<module>.<member>` for one of the module's local names, else null. */
94
+ export function moduleMemberName(node, names, module) {
95
+ if (node === null || node === undefined)
96
+ return null;
97
+ const expression = node.type === "TSInstantiationExpression" ? node.expression : node;
98
+ if (expression.type !== "MemberExpression" ||
99
+ expression.computed ||
100
+ expression.object.type !== "Identifier" ||
101
+ !(names.get(module)?.has(expression.object.name) ?? false) ||
102
+ expression.property.type !== "Identifier") {
103
+ return null;
104
+ }
105
+ return expression.property.name;
106
+ }
107
+ /** The member name when `node` is a call of `<module>.<member>(...)`, else null. */
108
+ export function moduleCallName(node, names, module) {
109
+ return node?.type === "CallExpression" ? moduleMemberName(unwrapExpression(node.callee), names, module) : null;
110
+ }
111
+ /** Read a Context.Service class declaration, or null when the class is not one. */
112
+ export function serviceClass(node, names) {
113
+ if (node.superClass === null)
114
+ return null;
115
+ const superClass = unwrapExpression(node.superClass);
116
+ if (superClass.type !== "CallExpression")
117
+ return null;
118
+ const factory = unwrapExpression(superClass.callee);
119
+ if (factory.type !== "CallExpression" || moduleMemberName(unwrapExpression(factory.callee), names, "Context") !== "Service") {
120
+ return null;
121
+ }
122
+ const optionsArgument = superClass.arguments[1];
123
+ const options = optionsArgument !== undefined && optionsArgument.type !== "SpreadElement"
124
+ ? unwrapExpression(optionsArgument)
125
+ : null;
126
+ return {
127
+ node,
128
+ name: node.id?.name ?? null,
129
+ options: options?.type === "ObjectExpression" ? options : null,
130
+ };
131
+ }
132
+ /** The innermost class whose body contains `node`, or null. */
133
+ export function enclosingClass(node) {
134
+ let current = node.parent;
135
+ while (current !== null) {
136
+ if (current.type === "ClassBody")
137
+ return current.parent.type === "ClassDeclaration" || current.parent.type === "ClassExpression" ? current.parent : null;
138
+ current = current.parent;
139
+ }
140
+ return null;
141
+ }
142
+ /** Whether `node` names the service class: `this` inside its static members, or its class name. */
143
+ function isClassReference(node, service) {
144
+ if (node === null || node === undefined)
145
+ return false;
146
+ const expression = unwrapNode(node);
147
+ if (expression.type === "ThisExpression")
148
+ return true;
149
+ return expression.type === "Identifier" && service.name !== null && expression.name === service.name;
150
+ }
151
+ /** The member name when `node` is `this.<member>` or `<ClassName>.<member>`, else null. */
152
+ export function classMemberName(node, service) {
153
+ if (node === null || node === undefined)
154
+ return null;
155
+ const expression = unwrapNode(node);
156
+ if (expression.type !== "MemberExpression" ||
157
+ expression.computed ||
158
+ expression.property.type !== "Identifier" ||
159
+ !isClassReference(expression.object, service)) {
160
+ return null;
161
+ }
162
+ return expression.property.name;
163
+ }
164
+ /** The name of a non-computed property key, or null. */
165
+ export function keyName(key) {
166
+ if (key.type === "Identifier" || key.type === "PrivateIdentifier")
167
+ return key.name;
168
+ if (key.type === "Literal" && typeof key.value === "string")
169
+ return key.value;
170
+ return null;
171
+ }
172
+ /** The `name` property of an object expression, or null. */
173
+ function objectProperty(object, name) {
174
+ for (const property of object.properties) {
175
+ if (property.type === "Property" && !property.computed && keyName(property.key) === name)
176
+ return property;
177
+ }
178
+ return null;
179
+ }
180
+ /** Every non-computed static member of a class. */
181
+ export function staticMembers(node) {
182
+ const members = [];
183
+ for (const element of node.body.body) {
184
+ if ((element.type !== "PropertyDefinition" && element.type !== "MethodDefinition") || !element.static || element.computed)
185
+ continue;
186
+ const name = keyName(element.key);
187
+ if (name === null)
188
+ continue;
189
+ members.push({ name, node: element, value: element.value });
190
+ }
191
+ return members;
192
+ }
193
+ /** The expressions that construct the service: the options `make` and a static `make`. */
194
+ export function serviceMakes(service) {
195
+ const makes = [];
196
+ const optionsMake = service.options === null ? null : objectProperty(service.options, "make");
197
+ if (optionsMake !== null)
198
+ makes.push(optionsMake.value);
199
+ for (const member of staticMembers(service.node)) {
200
+ if (member.name === "make" && member.value !== null)
201
+ makes.push(member.value);
202
+ }
203
+ return makes;
204
+ }
205
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
206
+ /** Whether the file is a `*.test.*` or `*.spec.*` file. */
207
+ export const isTestFile = (filename) => TEST_FILE.test(filename.replaceAll("\\", "/"));
208
+ const skippedKeys = new Set(["parent", "loc", "range", "start", "end"]);
209
+ const isNode = (value) => typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
210
+ /** Visit every descendant of `node`. Return false from `visit` to skip a node's children. */
211
+ export function walk(node, visit) {
212
+ if (!visit(node))
213
+ return;
214
+ for (const [key, value] of Object.entries(node)) {
215
+ if (skippedKeys.has(key))
216
+ continue;
217
+ if (Array.isArray(value)) {
218
+ for (const item of value) {
219
+ if (isNode(item))
220
+ walk(item, visit);
221
+ }
222
+ }
223
+ else if (isNode(value)) {
224
+ walk(value, visit);
225
+ }
226
+ }
227
+ }
228
+ /** Whether any descendant of `node`, including itself, satisfies `predicate`. */
229
+ export function contains(node, predicate) {
230
+ let found = false;
231
+ walk(node, (current) => {
232
+ if (found)
233
+ return false;
234
+ if (predicate(current))
235
+ found = true;
236
+ return !found;
237
+ });
238
+ return found;
239
+ }
240
+ /** Whether `node` is a function expression, arrow, or declaration. */
241
+ export const isFunction = (node) => node?.type === "ArrowFunctionExpression" ||
242
+ node?.type === "FunctionExpression" ||
243
+ node?.type === "FunctionDeclaration";
244
+ /** The return statements of a function body, without descending into nested functions. */
245
+ export function ownReturns(body) {
246
+ const returns = [];
247
+ walk(body, (node) => {
248
+ if (node !== body && isFunction(node))
249
+ return false;
250
+ if (node.type === "ReturnStatement")
251
+ returns.push(node);
252
+ return true;
253
+ });
254
+ return returns;
255
+ }
256
+ /** The expressions a function produces: its expression body or the arguments of its own returns. */
257
+ export function returnedExpressions(fn) {
258
+ if (fn.body === null)
259
+ return [];
260
+ if (fn.body.type !== "BlockStatement")
261
+ return [fn.body];
262
+ return ownReturns(fn.body).flatMap((statement) => (statement.argument === null ? [] : [statement.argument]));
263
+ }
264
+ const isPipeMember = (node) => node.type === "MemberExpression" &&
265
+ !node.computed &&
266
+ node.property.type === "Identifier" &&
267
+ node.property.name === "pipe";
268
+ /** For `x.pipe(...)`, the receiver `x`; otherwise null. */
269
+ export function pipeReceiver(node) {
270
+ if (node.type !== "CallExpression")
271
+ return null;
272
+ const callee = unwrapExpression(node.callee);
273
+ return isPipeMember(callee) ? unwrapExpression(callee.object) : null;
274
+ }
275
+ /**
276
+ * The steps that run before `call` when it is an argument of a pipeline-like call such as `x.pipe(a, call)`,
277
+ * `pipe(x, a, call)`, or `Effect.fn("name")(body, a, call)`, including earlier `.pipe(...)` receivers.
278
+ */
279
+ export function precedingSteps(call) {
280
+ const parent = call.parent;
281
+ if (parent?.type !== "CallExpression")
282
+ return [];
283
+ const index = parent.arguments.findIndex((argument) => argument === call);
284
+ if (index < 0)
285
+ return [];
286
+ const steps = [];
287
+ let receiver = pipeReceiver(parent);
288
+ while (receiver !== null) {
289
+ steps.push(receiver);
290
+ if (receiver.type === "CallExpression")
291
+ steps.push(...receiver.arguments);
292
+ receiver = pipeReceiver(receiver);
293
+ }
294
+ steps.push(...parent.arguments.slice(0, index));
295
+ return steps;
296
+ }
297
+ /** The initializer of the single declarator an identifier resolves to, or the declared function. */
298
+ export function resolveInitializer(sourceCode, identifier) {
299
+ const variable = resolveIdentifier(sourceCode, identifier);
300
+ if (variable === null || variable.defs.length !== 1)
301
+ return null;
302
+ const [definition] = variable.defs;
303
+ if (definition === undefined)
304
+ return null;
305
+ if (definition.type === "FunctionName" && definition.node.type === "FunctionDeclaration")
306
+ return definition.node;
307
+ if (definition.type !== "Variable" || definition.node.type !== "VariableDeclarator")
308
+ return null;
309
+ return definition.node.init ?? null;
310
+ }
311
+ /** The generator passed to `Effect.gen(...)`, or null when `node` is not such a call. */
312
+ export function genFunction(node, names) {
313
+ if (moduleCallName(node, names, "Effect") !== "gen" || node.type !== "CallExpression")
314
+ return null;
315
+ const body = node.arguments.at(-1);
316
+ return body?.type === "FunctionExpression" ? body : null;
317
+ }
318
+ /**
319
+ * The generator body that builds a service from a make expression: `Effect.gen(function* () {...})`, optionally
320
+ * followed by `.pipe(...)`, or an arrow that returns one.
321
+ */
322
+ export function makeGenerator(make, names) {
323
+ let expression = unwrapExpression(make);
324
+ if (expression.type === "ArrowFunctionExpression" || expression.type === "FunctionExpression") {
325
+ const [returned] = returnedExpressions(expression);
326
+ if (returned === undefined)
327
+ return null;
328
+ expression = unwrapExpression(returned);
329
+ }
330
+ let receiver = pipeReceiver(expression);
331
+ while (receiver !== null) {
332
+ expression = receiver;
333
+ receiver = pipeReceiver(expression);
334
+ }
335
+ return genFunction(expression, names);
336
+ }
@@ -1,4 +1,7 @@
1
1
  import { eslintCompatPlugin } from "@oxlint/plugins";
2
+ import { commentsRule } from "./rules/comments.js";
3
+ import { noDisabledTypeAssertionRulesRule } from "./rules/no-disabled-type-assertion-rules.js";
4
+ import { requireSuppressionReasonRule } from "./rules/require-suppression-reason.js";
2
5
  import { noReduceAccumulatorCopyRule } from "./rules/no-reduce-accumulator-copy.js";
3
6
  import { noChainedTypeAssertionsRule } from "./rules/no-chained-type-assertions.js";
4
7
  import { noConditionalEmptyObjectSpreadRule } from "./rules/no-conditional-empty-object-spread.js";
@@ -20,9 +23,11 @@ import { requireSafetyCommentForTypeAssertionRule } from "./rules/require-safety
20
23
  const antiSlopPlugin = eslintCompatPlugin({
21
24
  meta: { name: "anti-slop" },
22
25
  rules: {
26
+ comments: commentsRule,
23
27
  "no-reduce-accumulator-copy": noReduceAccumulatorCopyRule,
24
28
  "no-chained-type-assertions": noChainedTypeAssertionsRule,
25
29
  "no-conditional-empty-object-spread": noConditionalEmptyObjectSpreadRule,
30
+ "no-disabled-type-assertion-rules": noDisabledTypeAssertionRulesRule,
26
31
  "no-known-value-widening": noKnownValueWideningRule,
27
32
  "no-module-mocking": noModuleMockingRule,
28
33
  "no-object-parameters": noObjectParametersRule,
@@ -36,6 +41,7 @@ const antiSlopPlugin = eslintCompatPlugin({
36
41
  "no-widen-then-assert": noWidenThenAssertRule,
37
42
  "require-pascal-case-namespace-imports": requirePascalCaseNamespaceImportsRule,
38
43
  "require-readable-spacing": requireReadableSpacingRule,
44
+ "require-suppression-reason": requireSuppressionReasonRule,
39
45
  "require-safety-comment-for-type-assertion": requireSafetyCommentForTypeAssertionRule,
40
46
  },
41
47
  });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Hold comments to a short why: a word budget, at most one cited issue, configured patterns, and
3
+ * no dividers, step labels, commented-out code, untracked TODOs, JSDoc types or comments that only
4
+ * repeat the name below them. `tagged-only` keeps just directives, licence headers, docs on exports
5
+ * and comments that start with an allowed prefix such as `SAFETY:`.
6
+ */
7
+ export declare const commentsRule: import("@oxlint/plugins").Rule;