Skip to content

Commit 6ebcceb

Browse files
committed
🧪 Keep banned-word regressions in the existing policy suite
1 parent 3127546 commit 6ebcceb

2 files changed

Lines changed: 167 additions & 174 deletions

File tree

‎scripts/tests/banned-words.test.ts‎

Lines changed: 0 additions & 173 deletions
This file was deleted.

‎scripts/tests/oxlint-policy.test.ts‎

Lines changed: 167 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { describe, it } from "@executablemd/test-support/bdd";
22
import { expect } from "@executablemd/test-support/expect";
3-
import { ensureDir, readTextFile, writeTextFile } from "@effectionx/fs";
3+
import { copyFile, ensureDir, readTextFile, writeTextFile } from "@effectionx/fs";
4+
import { exec } from "@effectionx/process";
5+
import { until } from "effection";
6+
import { symlink } from "node:fs/promises";
47
import type { Operation } from "effection";
58
import path from "node:path";
69
import { useTempDirectory } from "@executablemd/test-support/temp";
710

811
import { ROOT, runOxlint } from "./oxlint.ts";
12+
import { BANNED_WORDS } from "../banned-words.js";
913
import {
1014
categorizeRule,
1115
SENSOR_RULES,
@@ -443,3 +447,165 @@ describe("Oxlint policy", () => {
443447
expect(output).not.toContain('"rules"');
444448
});
445449
});
450+
451+
const RULE = "local(no-banned-jsdoc-words)";
452+
453+
interface Diagnostic {
454+
code: string;
455+
message: string;
456+
filename: string;
457+
labels: { span: { line: number; column: number; length: number; offset: number } }[];
458+
}
459+
460+
function diagnostics(source: string): Diagnostic[] {
461+
const report: { diagnostics: Diagnostic[] } = JSON.parse(source);
462+
return report.diagnostics.filter((item) => item.code === RULE);
463+
}
464+
465+
function* subject(source: string, name = "subject.ts"): Operation<string> {
466+
const directory = yield* useTempDirectory("banned-words-");
467+
const file = path.join(directory, name);
468+
yield* writeTextFile(file, source);
469+
return file;
470+
}
471+
472+
function architecture(file: string, script = path.join(ROOT, "scripts/lint-architecture.js")) {
473+
return exec("node", { arguments: [script, file], cwd: ROOT }).join();
474+
}
475+
476+
describe("banned prose words", () => {
477+
it("rejects every explicit variant through the repository Oxlint config", function* () {
478+
const source =
479+
BANNED_WORDS.map((word) => `/** ${word.toUpperCase()}. */`).join("\n") + "\nexport {};\n";
480+
const file = yield* subject(source);
481+
const run = yield* runOxlint(".oxlintrc.json", ["--format=json", file]);
482+
const found = diagnostics(run.stdout);
483+
expect(run.code).not.toBe(0);
484+
expect(found.map((item) => item.labels[0].span)).toEqual(
485+
BANNED_WORDS.map((word, index) => ({
486+
line: index + 1,
487+
column: 5,
488+
length: word.length,
489+
offset: source.indexOf(word.toUpperCase()),
490+
})),
491+
);
492+
expect(found.every((item) => item.filename === file)).toBe(true);
493+
for (let index = 0; index < BANNED_WORDS.length; index++) {
494+
expect(found[index].message).toContain(BANNED_WORDS[index].toUpperCase());
495+
}
496+
});
497+
498+
it("maps multiline CRLF prose back to exact source columns", function* () {
499+
const file = yield* subject(
500+
"/**\r\n * Intro.\r\n * A CLAIM, then claimed.\r\n * @returns claims remain prose.\r\n */\r\nexport {};\r\n",
501+
);
502+
const run = yield* runOxlint(".oxlintrc.json", ["--format=json", file]);
503+
expect(diagnostics(run.stdout).map((item) => item.labels[0].span)).toEqual([
504+
{ line: 3, column: 6, length: 5, offset: 21 },
505+
{ line: 3, column: 18, length: 7, offset: 33 },
506+
{ line: 4, column: 13, length: 6, offset: 55 },
507+
]);
508+
});
509+
510+
it("preserves code, annotations, other comments and containing words", function* () {
511+
const file = yield* subject(
512+
[
513+
"// claim claims",
514+
"/* claim */",
515+
'export const claim = "claimed";',
516+
"/** A disclaimer and claimsConfiguration remain ordinary names.",
517+
" * Literal `claim(invocation)` and ``claims `claim` `` are references.",
518+
" * {@link IdentityClaimant} and {@link claim|the operation} name code.",
519+
" *",
520+
" * ```ts",
521+
' * const claimed = "claim";',
522+
" * ```",
523+
" *",
524+
' * claim("claims");',
525+
" *",
526+
" * @param {IdentityClaimant} claim the callback",
527+
" * @type {claim}",
528+
" * @type {{",
529+
' * claim: "}",',
530+
" * claimed: string",
531+
" * }}",
532+
" * @template Claim, Claimant",
533+
" * @example",
534+
' * claim("claimed");',
535+
" */",
536+
"export function use(claim: unknown) { return claim; }",
537+
].join("\n"),
538+
);
539+
const run = yield* runOxlint(".oxlintrc.json", ["--format=json", file]);
540+
expect(diagnostics(run.stdout)).toEqual([]);
541+
});
542+
543+
it("rejects architectural prose with locations while preserving Markdown code", function* () {
544+
const bad = yield* subject("# Design\r\n\r\nA Claim remains.\r\n", "architecture.md");
545+
const rejected = yield* architecture(bad);
546+
expect(rejected.code).not.toBe(0);
547+
expect(rejected.stderr).toContain(`${bad}:3:3: forbidden prose word "Claim"`);
548+
549+
const good = yield* subject(
550+
[
551+
"# Design",
552+
"A disclaimer beside `claim(carrier)`.",
553+
"",
554+
"```ts",
555+
'const claim = "claimed";',
556+
"```",
557+
"",
558+
" reclaim();",
559+
].join("\n"),
560+
"architecture.md",
561+
);
562+
expect((yield* architecture(good)).code).toBe(0);
563+
});
564+
565+
it("takes an added list entry through both consumers without shared mutation", function* () {
566+
const directory = yield* useTempDirectory("banned-words-list-");
567+
const copies = [
568+
"scripts/banned-words.js",
569+
"scripts/lib/banned-words.js",
570+
"scripts/oxlint-rules/no-banned-jsdoc-words.js",
571+
"scripts/lint-architecture.js",
572+
];
573+
for (const file of copies) {
574+
yield* ensureDir(path.dirname(path.join(directory, file)));
575+
yield* copyFile(path.join(ROOT, file), path.join(directory, file));
576+
}
577+
yield* writeTextFile(path.join(directory, "package.json"), '{"type":"module"}\n');
578+
yield* until(
579+
symlink(path.join(ROOT, "node_modules"), path.join(directory, "node_modules"), "junction"),
580+
);
581+
yield* writeTextFile(
582+
path.join(directory, "plugin.js"),
583+
[
584+
'import { noBannedJsdocWords } from "./scripts/oxlint-rules/no-banned-jsdoc-words.js";',
585+
'export default { rules: { "no-banned-jsdoc-words": noBannedJsdocWords } };',
586+
].join("\n"),
587+
);
588+
const config = path.join(directory, "oxlint.json");
589+
yield* writeTextFile(
590+
config,
591+
JSON.stringify({
592+
categories: { correctness: "off" },
593+
jsPlugins: [{ name: "local", specifier: "./plugin.js" }],
594+
rules: { "local/no-banned-jsdoc-words": "error" },
595+
}),
596+
);
597+
const source = yield* subject("/** jargonprobe */\nexport {};\n");
598+
const document = yield* subject("jargonprobe\n", "architecture.md");
599+
const script = path.join(directory, "scripts/lint-architecture.js");
600+
expect((yield* runOxlint(config, ["--format=json", source])).code).toBe(0);
601+
expect((yield* architecture(document, script)).code).toBe(0);
602+
603+
const list = path.join(directory, "scripts/banned-words.js");
604+
const original = yield* readTextFile(list);
605+
yield* writeTextFile(list, original.replace("];", ' "JARGONPROBE",\n];'));
606+
const linted = yield* runOxlint(config, ["--format=json", source]);
607+
expect(linted.code).not.toBe(0);
608+
expect(diagnostics(linted.stdout)[0].message).toContain("jargonprobe");
609+
expect((yield* architecture(document, script)).code).not.toBe(0);
610+
});
611+
});

0 commit comments

Comments
 (0)