@interfere/landmines 0.0.0-stage → 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Interfere, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,120 @@
1
- # Temporary Holding Version
1
+ # landmines
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Oxlint rules that keep AI-written code honest.
4
+
5
+ Coding agents are fast, and they optimise for green checks. Left alone, they
6
+ mock the thing under test, sleep until a race usually goes their way, retry
7
+ the flake, raise the timeout, and narrate the diff in comments. Every one of
8
+ those passes CI. None of them is true.
9
+
10
+ `landmines` makes the honest path the only one that lints. Each rule fails
11
+ with a message that tells the agent (or the human) what to do instead, so the
12
+ fix lands in the same loop that tripped it.
13
+
14
+ Built and used in production at [Interfere](https://interfere.com).
15
+
16
+ ## Install
17
+
18
+ ```sh
19
+ bun add -d oxlint @interfere/landmines
20
+ ```
21
+
22
+ Extend the recommended configuration in `.oxlintrc.json`:
23
+
24
+ ```json
25
+ {
26
+ "extends": ["./node_modules/@interfere/landmines/configs/recommended.json"]
27
+ }
28
+ ```
29
+
30
+ Or register only the plugins you want:
31
+
32
+ ```json
33
+ {
34
+ "jsPlugins": [
35
+ { "name": "landmines-testing", "specifier": "@interfere/landmines/testing" }
36
+ ],
37
+ "rules": {
38
+ "landmines-testing/no-test-doubles": "error"
39
+ }
40
+ }
41
+ ```
42
+
43
+ Requires Oxlint 1.81 or later and Node 22.18 or later.
44
+
45
+ ## Rules
46
+
47
+ ### `landmines-testing`
48
+
49
+ Tests that can't lie.
50
+
51
+ | Rule | What it stops |
52
+ | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
53
+ | `no-test-doubles` | Replacing dependency behaviour in tests: module mocks, `vi.fn(impl)`, stubbed globals, patched prototypes, hand-written bindings and fake responses. Use the real implementation and MSW for the network. Observation-only spies are allowed. |
54
+ | `strict-msw` | Starting MSW without `onUnhandledRequest: "error"`, so unmocked requests silently reach the network. |
55
+ | `no-fixed-sleep` | Awaiting a fixed real-time delay in a test or hook. Await the operation or a signal it emits. |
56
+ | `no-unsignaled-poll` | `expect.poll` and `vi.waitFor` on request recorders and spy state, which race a deadline instead of awaiting an event. |
57
+ | `no-flake-masking` | Test retries and raised timeouts. A test that passes on rerun is a flake to fix. |
58
+
59
+ `no-fixed-sleep`, `strict-msw` and `no-flake-masking` accept a per-file
60
+ allowlist with an exact count, so you can adopt them in an existing codebase
61
+ and ratchet down:
62
+
63
+ ```json
64
+ {
65
+ "landmines-testing/no-flake-masking": [
66
+ "error",
67
+ { "allow": { "src/legacy/slow.test.ts": 2 } }
68
+ ]
69
+ }
70
+ ```
71
+
72
+ The rule reports when a file has fewer violations than its allowance, so the
73
+ list only shrinks.
74
+
75
+ ### `landmines-style`
76
+
77
+ | Rule | What it stops |
78
+ | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
79
+ | `no-comments` | Prose comments. Allowed: functional directives (`oxlint-disable`, `@ts-expect-error`, `/* @__PURE__ */`, licence headers…), single-line `// WARNING:` comments for dangerous recurring footguns, and TSDoc on exported public API. Rationale belongs in the PR. |
80
+
81
+ Pass `publicApi` (regular expressions matched against the file path) to allow
82
+ TSDoc only in your published packages:
83
+
84
+ ```json
85
+ {
86
+ "landmines-style/no-comments": ["error", { "publicApi": ["/packages/sdk/"] }]
87
+ }
88
+ ```
89
+
90
+ ### `landmines-structure`
91
+
92
+ | Rule | What it stops |
93
+ | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
94
+ | `colocated-tests` | Tests detached from the implementation they import. Tests live beside their subject or in its local `tests/` directory. |
95
+ | `test-file-names` | `.spec.ts`, `.tests.ts`, `helpers.ts`, `mocks.ts` and friends. Use `.test.ts`, `.fixture.ts` and `.test-utils.ts`. |
96
+ | `package-exports` | Unrestricted source exports such as `"./*": "./src/*.ts"`. Declare explicit entrypoints or named public namespaces in `package.json`. |
97
+
98
+ ### `landmines-types`
99
+
100
+ | Rule | What it stops |
101
+ | -------------------------- | ------------------------------------------------------------------------------------------------------------------ |
102
+ | `no-explicit-return-types` | Annotated return types on implementations. Let them be inferred; pin a contract with `satisfies` where it matters. |
103
+
104
+ ## Pairs well with
105
+
106
+ - [anti-slop](https://github.com/dmmulroy/anti-slop) for type-level slop:
107
+ chained assertions, unsafe dictionaries, `unknown` plumbing.
108
+
109
+ ## Contributing
110
+
111
+ ```sh
112
+ bun install
113
+ bun run lint && bun run typecheck && bun run test
114
+ ```
115
+
116
+ Add a changeset with `bun changeset` for any user-facing change.
117
+
118
+ ## License
119
+
120
+ MIT
@@ -0,0 +1,26 @@
1
+ {
2
+ "jsPlugins": [
3
+ {
4
+ "name": "landmines-testing",
5
+ "specifier": "@interfere/landmines/testing"
6
+ },
7
+ { "name": "landmines-style", "specifier": "@interfere/landmines/style" },
8
+ {
9
+ "name": "landmines-structure",
10
+ "specifier": "@interfere/landmines/structure"
11
+ },
12
+ { "name": "landmines-types", "specifier": "@interfere/landmines/types" }
13
+ ],
14
+ "rules": {
15
+ "landmines-testing/no-fixed-sleep": "error",
16
+ "landmines-testing/no-flake-masking": "error",
17
+ "landmines-testing/no-test-doubles": "error",
18
+ "landmines-testing/no-unsignaled-poll": "error",
19
+ "landmines-testing/strict-msw": "error",
20
+ "landmines-style/no-comments": "error",
21
+ "landmines-structure/colocated-tests": "error",
22
+ "landmines-structure/package-exports": "error",
23
+ "landmines-structure/test-file-names": "error",
24
+ "landmines-types/no-explicit-return-types": "error"
25
+ }
26
+ }
@@ -0,0 +1,2 @@
1
+ declare const plugin: import("@oxlint/plugins").Plugin;
2
+ export { plugin as default };
@@ -0,0 +1,272 @@
1
+ import { definePlugin, defineRule } from "@oxlint/plugins";
2
+ import { basename, dirname, extname, join, posix, relative, sep } from "node:path";
3
+ import { z } from "zod";
4
+ import { existsSync, readFileSync, realpathSync } from "node:fs";
5
+ import { ResolverFactory } from "oxc-resolver";
6
+ import { parse } from "@babel/parser";
7
+ import { traverseFast } from "@babel/types";
8
+ // src/lib/test-owner.ts
9
+ const companion = /\.(?:test|e2e|fixture|test-utils)\./u;
10
+ const testDirectories$1 = /* @__PURE__ */ new Set([
11
+ "test",
12
+ "tests",
13
+ "__tests__"
14
+ ]);
15
+ const resolver = new ResolverFactory({
16
+ tsconfig: "auto",
17
+ symlinks: false,
18
+ conditionNames: [
19
+ "monorepo",
20
+ "import",
21
+ "node",
22
+ "default"
23
+ ],
24
+ extensions: [
25
+ ".ts",
26
+ ".tsx",
27
+ ".mts",
28
+ ".cts",
29
+ ".js",
30
+ ".jsx",
31
+ ".mjs",
32
+ ".cjs"
33
+ ],
34
+ extensionAlias: {
35
+ ".js": [
36
+ ".ts",
37
+ ".tsx",
38
+ ".js"
39
+ ],
40
+ ".mjs": [".mts", ".mjs"],
41
+ ".cjs": [".cts", ".cjs"]
42
+ }
43
+ });
44
+ function packageDirectory(directory) {
45
+ let current = directory;
46
+ while (!existsSync(join(current, "package.json"))) {
47
+ const parent = dirname(current);
48
+ if (parent === current) return current;
49
+ current = parent;
50
+ }
51
+ return current;
52
+ }
53
+ function companionImports(filename) {
54
+ const imports = [];
55
+ let file;
56
+ try {
57
+ file = parse(readFileSync(filename, "utf8"), {
58
+ sourceType: "unambiguous",
59
+ plugins: ["typescript", "jsx"]
60
+ });
61
+ } catch (error) {
62
+ if (error instanceof SyntaxError) return;
63
+ throw error;
64
+ }
65
+ traverseFast(file, (node) => {
66
+ if (node.type === "ImportDeclaration") {
67
+ if (!(node.importKind === "type" || node.specifiers.length > 0 && node.specifiers.every((specifier) => specifier.type === "ImportSpecifier" && specifier.importKind === "type"))) imports.push(node.source.value);
68
+ } else if ((node.type === "ExportNamedDeclaration" || node.type === "ExportAllDeclaration") && node.exportKind !== "type" && node.source) {
69
+ if (!(node.type === "ExportNamedDeclaration" && node.specifiers.length > 0 && node.specifiers.every((specifier) => specifier.type === "ExportSpecifier" && specifier.exportKind === "type"))) imports.push(node.source.value);
70
+ } else if (node.type === "ImportExpression" && node.source.type === "StringLiteral") imports.push(node.source.value);
71
+ });
72
+ return imports;
73
+ }
74
+ function companionDirectory(filename, source) {
75
+ const parts = relative(source, dirname(filename)).split(sep);
76
+ const support = parts.findIndex((part) => testDirectories$1.has(part));
77
+ return support === -1 ? dirname(filename) : join(source, ...parts.slice(0, support));
78
+ }
79
+ function testOwner(testFilename, imports) {
80
+ const filename = realpathSync(testFilename);
81
+ const directory = packageDirectory(dirname(filename));
82
+ const source = join(directory, "src");
83
+ const visited = /* @__PURE__ */ new Set([filename]);
84
+ const local = /* @__PURE__ */ new Set();
85
+ const invalidCompanions = /* @__PURE__ */ new Set();
86
+ const inferredOwners = /* @__PURE__ */ new Set();
87
+ const ambiguousOwners = /* @__PURE__ */ new Set();
88
+ function resolve(importer, specifiers) {
89
+ return specifiers.flatMap((specifier) => {
90
+ const target = resolver.resolveFileSync(importer, specifier).path;
91
+ if (!target?.startsWith(`${directory}${sep}`) || !/\.[cm]?[jt]sx?$/u.test(target) || /\.d\.[cm]?ts$/u.test(target) || packageDirectory(dirname(target)) !== directory) return [];
92
+ return [target];
93
+ });
94
+ }
95
+ function isCompanion(target) {
96
+ return companion.test(target) || relative(source, target).split(sep).slice(0, -1).some((part) => testDirectories$1.has(part));
97
+ }
98
+ function addSubject(target) {
99
+ if (![
100
+ "index",
101
+ "app",
102
+ "worker"
103
+ ].some((entry) => dirname(target) === source && basename(target, extname(target)) === entry)) local.add(dirname(target));
104
+ }
105
+ function collectCompanion(target, owner) {
106
+ if (visited.has(target)) return;
107
+ visited.add(target);
108
+ const nested = companionImports(target);
109
+ if (nested === void 0) {
110
+ invalidCompanions.add(target);
111
+ return;
112
+ }
113
+ for (const imported of resolve(target, nested)) {
114
+ if (isCompanion(imported)) {
115
+ if (companionDirectory(imported, source) === owner) collectCompanion(imported, owner);
116
+ else ambiguousOwners.add(owner);
117
+ } else if (dirname(imported) === owner) inferredOwners.add(owner);
118
+ else ambiguousOwners.add(owner);
119
+ if (!isCompanion(imported) && isOwnedTest(filename, dirname(imported))) addSubject(imported);
120
+ }
121
+ }
122
+ const resolved = resolve(filename, imports);
123
+ const companions = resolved.filter((target) => target.startsWith(`${source}${sep}`) && isCompanion(target));
124
+ const packageHarness = resolved.some((target) => !target.startsWith(`${source}${sep}`) && isCompanion(target));
125
+ const ownedCompanions = companions.filter((target) => isOwnedTest(filename, companionDirectory(target, source)));
126
+ for (const target of resolved.filter((candidate) => candidate.startsWith(`${source}${sep}`) && !isCompanion(candidate))) addSubject(target);
127
+ for (const target of ownedCompanions.length > 0 ? ownedCompanions : companions) collectCompanion(target, companionDirectory(target, source));
128
+ if (invalidCompanions.size > 0) return;
129
+ for (const owner of inferredOwners) if (isOwnedTest(filename, owner) || !ambiguousOwners.has(owner) && !packageHarness) local.add(owner);
130
+ const owned = [...local].find((owner) => isOwnedTest(filename, owner));
131
+ if (owned !== void 0) return owned;
132
+ const [first] = local;
133
+ if (first === void 0) return;
134
+ let owner = first;
135
+ for (const target of local) while (target !== owner && !target.startsWith(`${owner}${sep}`)) owner = dirname(owner);
136
+ return owner !== source && local.has(owner) ? owner : void 0;
137
+ }
138
+ function isOwnedTest(filename, owner) {
139
+ const location = relative(owner, dirname(realpathSync(filename))).split(sep);
140
+ return location[0] === "" || testDirectories$1.has(location[0] ?? "");
141
+ }
142
+ // src/rules/colocated-tests.ts
143
+ const colocatedTests = defineRule({
144
+ meta: {
145
+ type: "suggestion",
146
+ schema: [],
147
+ docs: { description: "Keep module tests beside their implementation or in its local tests directory." },
148
+ messages: { detached: "This test has an implementation owner in {{owner}}. Move it beside that implementation or into its local tests directory, including any test-specific fixtures and snapshots." }
149
+ },
150
+ create(context) {
151
+ const filename = context.physicalFilename;
152
+ const imports = [];
153
+ if (!/\.test\.[cm]?[jt]sx?$/u.test(filename)) return {};
154
+ return {
155
+ ImportDeclaration(node) {
156
+ if (!(node.importKind === "type" || node.specifiers.length > 0 && node.specifiers.every((specifier) => specifier.type === "ImportSpecifier" && specifier.importKind === "type"))) imports.push(node.source.value);
157
+ },
158
+ ImportExpression(node) {
159
+ if (node.source.type === "Literal") {
160
+ const parsed = z.string().safeParse(node.source.value);
161
+ if (parsed.success) imports.push(parsed.data);
162
+ }
163
+ },
164
+ "Program:exit"(node) {
165
+ const owner = testOwner(filename, imports);
166
+ if (owner !== void 0 && !isOwnedTest(filename, owner)) context.report({
167
+ node,
168
+ messageId: "detached",
169
+ data: { owner: relative(context.cwd, owner) }
170
+ });
171
+ }
172
+ };
173
+ }
174
+ });
175
+ // src/rules/package-exports.ts
176
+ const manifestSchema = z.object({ exports: z.json().optional() });
177
+ function unrestrictedSourceExports(value) {
178
+ const pending = [value];
179
+ const violations = /* @__PURE__ */ new Set();
180
+ while (pending.length > 0) {
181
+ const current = pending.pop();
182
+ const target = z.string().safeParse(current);
183
+ if (target.success) {
184
+ if (/^(?:src\/)?\*(?:\.[cm]?[jt]sx?)?$/u.test(posix.normalize(target.data))) violations.add(target.data);
185
+ continue;
186
+ }
187
+ const array = z.array(z.json()).safeParse(current);
188
+ if (array.success) {
189
+ pending.push(...array.data);
190
+ continue;
191
+ }
192
+ const object = z.record(z.string(), z.json()).safeParse(current);
193
+ if (object.success) pending.push(...Object.values(object.data));
194
+ }
195
+ return [...violations];
196
+ }
197
+ const packageExports = defineRule({
198
+ meta: {
199
+ type: "problem",
200
+ schema: [],
201
+ docs: { description: "Declare intentional package interfaces instead of unrestricted source exports." },
202
+ messages: { unrestricted: "{{manifest}} exposes arbitrary implementation files through {{targets}}. Declare explicit entrypoints or named public namespaces in package.json." }
203
+ },
204
+ create(context) {
205
+ const directory = packageDirectory(dirname(context.physicalFilename));
206
+ const path = join(directory, "package.json");
207
+ if (!existsSync(path)) return {};
208
+ const targets = unrestrictedSourceExports(manifestSchema.parse(JSON.parse(readFileSync(path, "utf8"))).exports);
209
+ return { Program(node) {
210
+ if (targets.length > 0) context.report({
211
+ node,
212
+ messageId: "unrestricted",
213
+ data: {
214
+ manifest: path,
215
+ targets: targets.join(", ")
216
+ }
217
+ });
218
+ } };
219
+ }
220
+ });
221
+ // src/rules/test-file-names.ts
222
+ const extension = String.raw`\.[cm]?[jt]sx?$`;
223
+ const misnamedTest = new RegExp(String.raw`\.(?:spec|specs|tests)${extension}`, "u");
224
+ const fixtureWord = new RegExp(String.raw`(?:^|[-_.])fixtures?${extension}`, "u");
225
+ const namedFixture = new RegExp(String.raw`.\.fixture${extension}`, "u");
226
+ const misnamedHelper = new RegExp(String.raw`\.(?:test-helpers?|test-util|testutils?|test-utilities|helpers?|mocks?|stubs?|harness)${extension}`, "u");
227
+ const testDirectories = /* @__PURE__ */ new Set(["tests", "__tests__"]);
228
+ function nameKind(name) {
229
+ if (misnamedTest.test(name)) return "test";
230
+ if (fixtureWord.test(name) && !namedFixture.test(name)) return "fixture";
231
+ return misnamedHelper.test(name) ? "helper" : void 0;
232
+ }
233
+ const testFileNames = defineRule({
234
+ meta: {
235
+ type: "suggestion",
236
+ schema: [],
237
+ docs: { description: "Name tests, fixtures and test helpers with the repository's suffixes." },
238
+ messages: {
239
+ test: "Name test files <subject>.test.ts, adding a runtime infix such as .browser.test.tsx when a Vitest project needs one.",
240
+ fixture: "Name test data <subject>.fixture.ts.",
241
+ helper: "Name test helpers, harnesses and mocks <subject>.test-utils.ts.",
242
+ directory: "Put tests in a test directory, not {{directory}}."
243
+ }
244
+ },
245
+ create(context) {
246
+ return { Program(node) {
247
+ const filename = context.physicalFilename;
248
+ const directory = dirname(filename);
249
+ const messageId = nameKind(basename(filename));
250
+ const misplaced = relative(packageDirectory(directory), directory).split(sep).find((part) => testDirectories.has(part));
251
+ if (messageId) context.report({
252
+ node,
253
+ messageId
254
+ });
255
+ if (misplaced) context.report({
256
+ node,
257
+ messageId: "directory",
258
+ data: { directory: misplaced }
259
+ });
260
+ } };
261
+ }
262
+ });
263
+ // src/plugins/structure.ts
264
+ const plugin = definePlugin({
265
+ meta: { name: "landmines-structure" },
266
+ rules: {
267
+ "colocated-tests": colocatedTests,
268
+ "package-exports": packageExports,
269
+ "test-file-names": testFileNames
270
+ }
271
+ });
272
+ export { plugin as default };
@@ -0,0 +1,2 @@
1
+ declare const plugin: import("@oxlint/plugins").Plugin;
2
+ export { plugin as default };
package/dist/style.mjs ADDED
@@ -0,0 +1,139 @@
1
+ import { definePlugin, defineRule } from "@oxlint/plugins";
2
+ import { z } from "zod";
3
+ // src/rules/no-comments.ts
4
+ const directives = [
5
+ /^(?:eslint|oxlint)-(?:disable|enable)(?:-next-line|-line)?(?:\s|$)/u,
6
+ /^@ts-(?:expect-error|ignore|nocheck|check)(?:\s|$)/u,
7
+ /^(?:prettier|oxfmt)-ignore(?:-start|-end)?(?:\s|$)/u,
8
+ /^(?:c8|v8|istanbul)\s+ignore\b/u,
9
+ /^(?:@|#)__(?:PURE|NO_SIDE_EFFECTS|INLINE|NOINLINE)__$/u,
10
+ /^@vite-ignore$/u,
11
+ /^webpack(?:ChunkName|Mode|Prefetch|Preload|Ignore|Include|Exclude|Exports|FetchPriority):/u,
12
+ /^(?:@jsx|@jsxFrag|@jsxImportSource|@jsxRuntime)\s+\S/u,
13
+ /^\/\s*<(?:reference|amd-module|amd-dependency)\s/u,
14
+ /^#\s*source(?:Mapping)?URL=/u,
15
+ /^nosemgrep(?:\s|:|$)/u,
16
+ /^(?:SPDX-License-Identifier:|@license\b)/mu
17
+ ];
18
+ function isDirective(comment) {
19
+ const value = comment.value.replace(/^!/u, "").replaceAll(/^\s*\*\s?/gmu, "").trim();
20
+ return comment.type === "Shebang" || directives.some((pattern) => pattern.test(value));
21
+ }
22
+ function isWarning(comment) {
23
+ return comment.type === "Line" && comment.loc.start.line === comment.loc.end.line && /^\s*WARNING:\s*\S/u.test(comment.value);
24
+ }
25
+ const noCommentsOptions = z.tuple([z.object({ publicApi: z.array(z.string()).optional() })]).or(z.tuple([]));
26
+ const noComments = defineRule({
27
+ meta: {
28
+ type: "suggestion",
29
+ schema: [{
30
+ type: "object",
31
+ properties: { publicApi: {
32
+ type: "array",
33
+ items: { type: "string" }
34
+ } },
35
+ additionalProperties: false
36
+ }],
37
+ docs: { description: "Allow only functional directives, single-line WARNING: footguns, and exported public API TSDoc." },
38
+ messages: { forbidden: "Remove this comment; express meaning in code and rationale in the PR. Keep functional directives, single-line WARNING: comments for dangerous recurring footguns, or TSDoc on exported public API symbols." }
39
+ },
40
+ create(context) {
41
+ const source = context.sourceCode;
42
+ const [options] = noCommentsOptions.parse(context.options);
43
+ const filename = context.physicalFilename.replaceAll("\\", "/");
44
+ const publicFile = options?.publicApi === void 0 || options.publicApi.some((pattern) => new RegExp(pattern, "u").test(filename));
45
+ const documented = /* @__PURE__ */ new Set();
46
+ const declarations = /* @__PURE__ */ new Set();
47
+ const members = [];
48
+ const references = [];
49
+ function document(node) {
50
+ const comments = source.getCommentsBefore(node);
51
+ let [start] = node.range;
52
+ while (comments.length > 0) {
53
+ const last = comments.at(-1);
54
+ if (!last || !isDirective(last)) break;
55
+ if (source.text.slice(last.range[1], start).trim() !== "") return;
56
+ [start] = last.range;
57
+ comments.pop();
58
+ }
59
+ const comment = comments.at(-1);
60
+ if (comment?.type === "Block" && comment.value.startsWith("*") && !/@(?:internal|private)\b/u.test(comment.value) && source.text.slice(comment.range[1], start).trim() === "") documented.add(comment.range[0]);
61
+ }
62
+ function collectMember(node) {
63
+ members.push(node);
64
+ }
65
+ function isExposed(node) {
66
+ let ancestor = node;
67
+ while (!declarations.has(ancestor)) {
68
+ if (ancestor.type === "Program" || ancestor.type === "BlockStatement" || ancestor.type === "StaticBlock" || "accessibility" in ancestor && (ancestor.accessibility === "private" || ancestor.accessibility === "protected") || "key" in ancestor && ancestor.key.type === "PrivateIdentifier" || ancestor.parent.type === "ArrowFunctionExpression" && ancestor.parent.body === ancestor) return false;
69
+ ancestor = ancestor.parent;
70
+ }
71
+ return true;
72
+ }
73
+ return {
74
+ Property: collectMember,
75
+ TSInterfaceDeclaration: collectMember,
76
+ TSTypeAliasDeclaration: collectMember,
77
+ TSPropertySignature: collectMember,
78
+ TSMethodSignature: collectMember,
79
+ TSCallSignatureDeclaration: collectMember,
80
+ TSConstructSignatureDeclaration: collectMember,
81
+ TSIndexSignature: collectMember,
82
+ TSEnumMember: collectMember,
83
+ MethodDefinition: collectMember,
84
+ PropertyDefinition: collectMember,
85
+ TSTypeReference(node) {
86
+ references.push(node);
87
+ },
88
+ "Program:exit"(program) {
89
+ if (publicFile) {
90
+ const exportedNames = /* @__PURE__ */ new Set();
91
+ const ambientFile = /\.d\.[cm]?ts$/u.test(context.physicalFilename) && program.body.every((node) => node.type !== "ImportDeclaration" && !node.type.startsWith("Export"));
92
+ for (const node of program.body) {
93
+ if (ambientFile || node.type === "TSModuleDeclaration" && node.declare) declarations.add(node);
94
+ if (node.type === "ExportNamedDeclaration") {
95
+ document(node);
96
+ if (node.declaration) declarations.add(node.declaration);
97
+ else if (node.source === null) {
98
+ for (const specifier of node.specifiers) if (specifier.local.type === "Identifier") exportedNames.add(specifier.local.name);
99
+ }
100
+ } else if (node.type === "ExportDefaultDeclaration") {
101
+ document(node);
102
+ if (node.declaration.type === "Identifier") exportedNames.add(node.declaration.name);
103
+ else declarations.add(node.declaration);
104
+ } else if (node.type === "ExportAllDeclaration") document(node);
105
+ }
106
+ for (const node of program.body) if (source.getDeclaredVariables(node).some((variable) => exportedNames.has(variable.name))) declarations.add(node);
107
+ let previousSize = -1;
108
+ while (previousSize !== declarations.size) {
109
+ previousSize = declarations.size;
110
+ for (const reference of references) {
111
+ if (reference.typeName.type !== "Identifier" || !isExposed(reference)) continue;
112
+ let scope = source.getScope(reference);
113
+ while (scope) {
114
+ const variable = scope.set.get(reference.typeName.name);
115
+ if (variable) {
116
+ for (const definition of variable.defs) if (definition.node.type === "TSInterfaceDeclaration" || definition.node.type === "TSTypeAliasDeclaration") declarations.add(definition.node);
117
+ break;
118
+ }
119
+ scope = scope.upper;
120
+ }
121
+ }
122
+ }
123
+ for (const node of declarations) document(node);
124
+ for (const node of members) if (isExposed(node)) document(node);
125
+ }
126
+ for (const comment of source.getAllComments()) if (!isDirective(comment) && !isWarning(comment) && !documented.has(comment.range[0])) context.report({
127
+ loc: comment.loc,
128
+ messageId: "forbidden"
129
+ });
130
+ }
131
+ };
132
+ }
133
+ });
134
+ // src/plugins/style.ts
135
+ const plugin = definePlugin({
136
+ meta: { name: "landmines-style" },
137
+ rules: { "no-comments": noComments }
138
+ });
139
+ export { plugin as default };
@@ -0,0 +1,2 @@
1
+ declare const plugin: import("@oxlint/plugins").Plugin;
2
+ export { plugin as default };