@goodbones/oxlint 0.1.0-beta.7 → 0.1.0-beta.9

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.
@@ -0,0 +1,4 @@
1
+ import { type LoadedPolicy } from "@goodbones/core";
2
+ import { type OxlintRule } from "./oxlint-api.js";
3
+ export declare const makeCampaignsRule: (policy: LoadedPolicy) => OxlintRule;
4
+ //# sourceMappingURL=campaigns-rule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"campaigns-rule.d.ts","sourceRoot":"","sources":["../../src/campaigns-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,YAAY,EAGlB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAEL,KAAK,UAAU,EAIhB,MAAM,iBAAiB,CAAC;AAsCzB,eAAO,MAAM,iBAAiB,WAAY,YAAY,KAAG,UAuExD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"config-loader.d.ts","sourceRoot":"","sources":["../../src/config-loader.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,YAAY,EAIlB,MAAM,iBAAiB,CAAC;AAIzB,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAOpD,eAAO,MAAM,kBAAkB,aACnB,MAAM,mBACC,MAAM,KACtB,OAAO,CAAC,YAAY,CAkBtB,CAAC"}
1
+ {"version":3,"file":"config-loader.d.ts","sourceRoot":"","sources":["../../src/config-loader.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,YAAY,EAOlB,MAAM,iBAAiB,CAAC;AAIzB,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAmBpD,eAAO,MAAM,kBAAkB,aACnB,MAAM,mBACC,MAAM,KACtB,OAAO,CAAC,YAAY,CA4CtB,CAAC"}
@@ -5,6 +5,7 @@ export declare const rules: {
5
5
  readonly members: OxlintRule;
6
6
  readonly structure: OxlintRule;
7
7
  readonly surface: OxlintRule;
8
+ readonly campaigns: OxlintRule;
8
9
  };
9
10
  declare const plugin: {
10
11
  readonly meta: {
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAoBlD,eAAO,MAAM,KAAK,EAAE;IAClB,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;CAO9B,CAAC;AAEF,QAAA,MAAM,MAAM,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,KAAK,CAAA;CAGrF,CAAC;eAEa,MAAM"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAoBlD,eAAO,MAAM,KAAK,EAAE;IAClB,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;CAQhC,CAAC;AAEF,QAAA,MAAM,MAAM,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,KAAK,CAAA;CAGrF,CAAC;eAEa,MAAM"}
@@ -0,0 +1,102 @@
1
+ import { campaignsSelecting, evaluateCampaigns, formatMessage, leafTermsOf, reconcile, ReportUnavailable, } from "@goodbones/core";
2
+ import { sourceFactsOf } from "@goodbones/typescript";
3
+ import { factsOfProgram, toRepoRelative, } from "./oxlint-api.js";
4
+ // The campaigns family, one file at a time: every hit of a campaign selecting
5
+ // the file that its ledger does not carry, reported at the match's position
6
+ // with the campaign's `how` as the message. The facts come from oxlint's tree
7
+ // through the pack's reader, as the other rules read them; the `syntax` term
8
+ // is answered by the same matcher the CLI uses, over `sourceCode.text` —
9
+ // "one engine" is this family's parity contract, rather than a corpus.
10
+ // Whether a hit is carried by the ledger, judged against the file's hits
11
+ // alone: entries are per file, so a file's reconciliation is the whole
12
+ // campaign's restricted to it.
13
+ const unledgered = (policy, selected, hits) => {
14
+ const carried = new Set();
15
+ for (const rule of selected) {
16
+ const ledger = policy.ledgers.get(rule.id);
17
+ if (ledger === undefined)
18
+ continue;
19
+ const own = hits.filter((hit) => hit.campaign === rule.id).map((hit) => hit.violation);
20
+ for (const one of reconcile(ledger, own, rule.unit).ledgered)
21
+ carried.add(one);
22
+ }
23
+ return hits.filter((hit) => !carried.has(hit.violation));
24
+ };
25
+ // A `report` a campaign names that cannot be read — a command the kernel
26
+ // refused to spawn, a file no step wrote — is one fact about the run, not
27
+ // one about each file the campaign selects. The live source keeps the
28
+ // failure per spec; this keeps which failures have been said, so the first
29
+ // selected file carries the notice and the rest stay quiet. Without it, a
30
+ // lint of eight hundred files is eight hundred copies of oxlint's generic
31
+ // "error running JS plugin", with the cause dropped by the terser formats.
32
+ const aside = (cause) => `A report a campaign names could not be read, so no campaign naming it is judged in this ` +
33
+ `run: ${cause.message}`;
34
+ export const makeCampaignsRule = (policy) => {
35
+ // Per rule instance, which is per plugin load — one process — rather than
36
+ // per `createOnce`, which a host may call more often than that.
37
+ const said = new Set();
38
+ return {
39
+ meta: {
40
+ type: "problem",
41
+ docs: {
42
+ description: "the campaigns: every place a pattern the repository is migrating away from still occurs, that its ledger does not carry",
43
+ },
44
+ schema: [],
45
+ },
46
+ createOnce(context) {
47
+ let file = "";
48
+ let selected = [];
49
+ return {
50
+ before() {
51
+ file = toRepoRelative(policy.repoRoot, context.filename);
52
+ if (file.startsWith(".."))
53
+ return false;
54
+ selected = campaignsSelecting(policy.campaignRules, file);
55
+ return selected.length > 0;
56
+ },
57
+ Program(node) {
58
+ const text = context.sourceCode.text;
59
+ const needsSyntax = selected.some((rule) => leafTermsOf(rule.detect).some((leaf) => leaf === "syntax" || leaf === "report" || leaf === "fn"));
60
+ const input = {
61
+ file,
62
+ text,
63
+ facts: sourceFactsOf(factsOfProgram(file, node)),
64
+ resolver: policy.resolver,
65
+ fileSystem: policy.fileSystem,
66
+ syntax: needsSyntax ? policy.syntax.parse(file, text) : null,
67
+ functions: policy.functions,
68
+ reports: policy.reports,
69
+ };
70
+ // One campaign at a time, so a report one of them cannot read costs
71
+ // that campaign's answer for this file and not its neighbours'.
72
+ const hits = [];
73
+ for (const rule of selected) {
74
+ try {
75
+ for (const hit of evaluateCampaigns([rule], input))
76
+ hits.push(hit);
77
+ }
78
+ catch (cause) {
79
+ if (!(cause instanceof ReportUnavailable))
80
+ throw cause;
81
+ const message = aside(cause);
82
+ if (said.has(message))
83
+ continue;
84
+ said.add(message);
85
+ context.report({ message, loc: { line: 1, column: 0 } });
86
+ }
87
+ }
88
+ for (const hit of unledgered(policy, selected, hits)) {
89
+ // A match lands where it was found; a file-unit hit, on line 1, as
90
+ // the structure rule places a finding about the file itself.
91
+ const at = hit.range ?? { start: { line: 0, column: 0 } };
92
+ context.report({
93
+ message: formatMessage(hit.violation),
94
+ loc: { line: at.start.line + 1, column: at.start.column },
95
+ });
96
+ }
97
+ },
98
+ };
99
+ },
100
+ };
101
+ };
102
+ //# sourceMappingURL=campaigns-rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file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,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC;wBACrD,mEAAmE;wBACnE,6DAA6D;wBAC7D,MAAM,EAAE,GAAG,GAAG,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;wBAC1D,OAAO,CAAC,MAAM,CAAC;4BACb,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC;4BACrC,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE;yBAC1D,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -1,7 +1,20 @@
1
1
  import * as path from "node:path";
2
- import { findManifestFile, loadPolicy, makeFileSystemLive, readManifestFile, } from "@goodbones/core";
2
+ import { astGrepMatcher } from "@goodbones/ast-grep";
3
+ import { findManifestFile, loadCampaignFunctions, loadPolicy, makeFileSystemLive, makeReportSourceLive, readManifestFile, reportSpecsOf, ReportUnavailable, } from "@goodbones/core";
3
4
  import { typescriptLanguage } from "@goodbones/typescript";
4
5
  import * as Result from "effect/Result";
6
+ // The clock the campaigns are judged by; `ARCHITECTURE_NOW` pins it, as it
7
+ // does for the CLI.
8
+ const hostNow = () => {
9
+ const pinned = process.env.ARCHITECTURE_NOW;
10
+ if (pinned === undefined || pinned === "")
11
+ return Date.now();
12
+ const parsed = /^\d+$/.test(pinned) ? Number(pinned) : Date.parse(pinned);
13
+ if (Number.isNaN(parsed)) {
14
+ throw new Error(`ARCHITECTURE_NOW is ${JSON.stringify(pinned)}, which is not a date.`);
15
+ }
16
+ return parsed;
17
+ };
5
18
  // The plugin's composition root: read the manifest file, construct the
6
19
  // language packs and the live file system, and hand them to the loader. A load
7
20
  // failure throws out of here and out of oxlint's import of the plugin — a
@@ -14,16 +27,44 @@ export const loadPolicyFromFile = async (repoRoot, configFilename) => {
14
27
  ? findManifestFile(repoRoot)
15
28
  : path.resolve(repoRoot, configFilename);
16
29
  const read = await readManifestFile(configPath);
30
+ // The `fn` terms are imported here, before the policy loads, as the CLI
31
+ // does; the pack is composed with ast-grep for the campaigns family's
32
+ // `syntax` term, and the plugin parses with it for that family only.
33
+ const { functions, manifest } = await loadCampaignFunctions(configPath, read.manifest);
17
34
  const loaded = loadPolicy({
18
35
  repoRoot,
19
36
  configPath,
20
- manifest: read.manifest,
37
+ manifest,
21
38
  locate: read.locate,
22
- languages: [typescriptLanguage()],
39
+ languages: [typescriptLanguage({ syntax: astGrepMatcher() })],
23
40
  fileSystem: makeFileSystemLive(repoRoot),
41
+ functions,
42
+ // A `report` command runs once per process — once per editor session
43
+ // for oxlint's language server, which then sees that report until it
44
+ // restarts. A report the build writes to a file is the predictable form.
45
+ reports: makeReportSourceLive(repoRoot),
46
+ now: hostNow(),
24
47
  });
25
48
  if (Result.isFailure(loaded))
26
49
  throw loaded.failure;
27
- return loaded.success;
50
+ const policy = loaded.success;
51
+ // Every `report` a campaign names is read now, while oxlint has linted
52
+ // nothing. A `command` forks this process, and once the linter is running
53
+ // Linux can refuse the fork: the linter's per-thread AST buffers merge
54
+ // into one mapping larger than RAM and swap together, which the default
55
+ // overcommit heuristic refuses to duplicate. The source caches the answer,
56
+ // and a failure, so the rules read what was read here. A report that
57
+ // cannot be read is not a load failure — the campaigns rule reports it
58
+ // once, on the first file a campaign naming it selects.
59
+ for (const spec of reportSpecsOf(policy.campaignRules)) {
60
+ try {
61
+ policy.reports.diagnosticsOf(spec, "");
62
+ }
63
+ catch (cause) {
64
+ if (!(cause instanceof ReportUnavailable))
65
+ throw cause;
66
+ }
67
+ }
68
+ return policy;
28
69
  };
29
70
  //# sourceMappingURL=config-loader.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config-loader.js","sourceRoot":"","sources":["../../src/config-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EACL,gBAAgB,EAEhB,UAAU,EACV,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAIxC,uEAAuE;AACvE,+EAA+E;AAC/E,0EAA0E;AAC1E,iEAAiE;AACjE,2CAA2C;AAC3C,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EACrC,QAAgB,EAChB,cAAuB,EACA,EAAE;IACzB,wEAAwE;IACxE,uCAAuC;IACvC,MAAM,UAAU,GACd,cAAc,KAAK,SAAS;QAC1B,CAAC,CAAC,gBAAgB,CAAC,QAAQ,CAAC;QAC5B,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IAC7C,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAChD,MAAM,MAAM,GAAG,UAAU,CAAC;QACxB,QAAQ;QACR,UAAU;QACV,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,SAAS,EAAE,CAAC,kBAAkB,EAAE,CAAC;QACjC,UAAU,EAAE,kBAAkB,CAAC,QAAQ,CAAC;KACzC,CAAC,CAAC;IACH,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;QAAE,MAAM,MAAM,CAAC,OAAO,CAAC;IACnD,OAAO,MAAM,CAAC,OAAO,CAAC;AACxB,CAAC,CAAC"}
1
+ {"version":3,"file":"config-loader.js","sourceRoot":"","sources":["../../src/config-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EACL,gBAAg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js";
2
3
  import { makeExportsRule } from "./exports-rule.js";
3
4
  import { makeImportsRule } from "./imports-rule.js";
@@ -21,6 +22,7 @@ export const rules = {
21
22
  members: makeMembersRule(policy),
22
23
  structure: makeStructureRule(policy),
23
24
  surface: makeSurfaceRule(policy),
25
+ campaigns: makeCampaignsRule(policy),
24
26
  };
25
27
  const plugin = {
26
28
  meta: { name: "architecture" },
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,gFAAgF;AAChF,gFAAgF;AAChF,+EAA+E;AAC/E,+EAA+E;AAC/E,YAAY;AACZ,MAAM,MAAM,GAAG,MAAM,kBAAkB,CACrC,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,OAAO,CAAC,GAAG,EAAE,EAC9C,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAChC,CAAC;AAEF,6EAA6E;AAC7E,mCAAmC;AACnC,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;IACpC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,8BAA8B,MAAM,IAAI,CAAC,CAAC;AACjE,CAAC;AAED,MAAM,CAAC,MAAM,KAAK,GAMd;IACF,OAAO,EAAE,eAAe,CAAC,MAAM,CAAC;IAChC,OAAO,EAAE,eAAe,CAAC,MAAM,CAAC;IAChC,OAAO,EAAE,eAAe,CAAC,MAAM,CAAC;IAChC,SAAS,EAAE,iBAAiB,CAAC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C;IACpC,OAAO,EAAE,eAAe,CAAC,MAAM,CAAC;IAChC,SAAS,EAAE,iBAAiB,CAAC,MAAM,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,GAA+E;IACzF,IAAI,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE;IAC9B,KAAK;CACN,CAAC;AAEF,eAAe,MAAM,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodbones/oxlint",
3
- "version": "0.1.0-beta.7",
3
+ "version": "0.1.0-beta.9",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "The oxlint plugin for @goodbones/core: the imports, exports, members, structure and surface families as five oxlint rules, evaluated in the editor and in CI from the same manifest the CLI reads.",
@@ -44,8 +44,9 @@
44
44
  ],
45
45
  "dependencies": {
46
46
  "effect": "4.0.0-beta.94",
47
- "@goodbones/core": "0.1.0-beta.7",
48
- "@goodbones/typescript": "0.1.0-beta.7"
47
+ "@goodbones/ast-grep": "0.1.1",
48
+ "@goodbones/core": "0.1.0-beta.9",
49
+ "@goodbones/typescript": "0.1.0-beta.9"
49
50
  },
50
51
  "peerDependencies": {
51
52
  "oxlint": ">=1.77.0"
@@ -0,0 +1,129 @@
1
+ import {
2
+ type CampaignHit,
3
+ campaignsSelecting,
4
+ type CompiledCampaign,
5
+ evaluateCampaigns,
6
+ formatMessage,
7
+ leafTermsOf,
8
+ type LoadedPolicy,
9
+ reconcile,
10
+ ReportUnavailable,
11
+ } from "@goodbones/core";
12
+ import { sourceFactsOf } from "@goodbones/typescript";
13
+
14
+ import {
15
+ factsOfProgram,
16
+ type OxlintRule,
17
+ type Program,
18
+ type RuleContext,
19
+ toRepoRelative,
20
+ } from "./oxlint-api.js";
21
+
22
+ // The campaigns family, one file at a time: every hit of a campaign selecting
23
+ // the file that its ledger does not carry, reported at the match's position
24
+ // with the campaign's `how` as the message. The facts come from oxlint's tree
25
+ // through the pack's reader, as the other rules read them; the `syntax` term
26
+ // is answered by the same matcher the CLI uses, over `sourceCode.text` —
27
+ // "one engine" is this family's parity contract, rather than a corpus.
28
+
29
+ // Whether a hit is carried by the ledger, judged against the file's hits
30
+ // alone: entries are per file, so a file's reconciliation is the whole
31
+ // campaign's restricted to it.
32
+ const unledgered = (
33
+ policy: LoadedPolicy,
34
+ selected: ReadonlyArray<CompiledCampaign>,
35
+ hits: ReadonlyArray<CampaignHit>,
36
+ ): ReadonlyArray<CampaignHit> => {
37
+ const carried = new Set<CampaignHit["violation"]>();
38
+ for (const rule of selected) {
39
+ const ledger = policy.ledgers.get(rule.id);
40
+ if (ledger === undefined) continue;
41
+ const own = hits.filter((hit) => hit.campaign === rule.id).map((hit) => hit.violation);
42
+ for (const one of reconcile(ledger, own, rule.unit).ledgered) carried.add(one);
43
+ }
44
+ return hits.filter((hit) => !carried.has(hit.violation));
45
+ };
46
+
47
+ // A `report` a campaign names that cannot be read — a command the kernel
48
+ // refused to spawn, a file no step wrote — is one fact about the run, not
49
+ // one about each file the campaign selects. The live source keeps the
50
+ // failure per spec; this keeps which failures have been said, so the first
51
+ // selected file carries the notice and the rest stay quiet. Without it, a
52
+ // lint of eight hundred files is eight hundred copies of oxlint's generic
53
+ // "error running JS plugin", with the cause dropped by the terser formats.
54
+ const aside = (cause: ReportUnavailable): string =>
55
+ `A report a campaign names could not be read, so no campaign naming it is judged in this ` +
56
+ `run: ${cause.message}`;
57
+
58
+ export const makeCampaignsRule = (policy: LoadedPolicy): OxlintRule => {
59
+ // Per rule instance, which is per plugin load — one process — rather than
60
+ // per `createOnce`, which a host may call more often than that.
61
+ const said = new Set<string>();
62
+ return {
63
+ meta: {
64
+ type: "problem" as const,
65
+ docs: {
66
+ description:
67
+ "the campaigns: every place a pattern the repository is migrating away from still occurs, that its ledger does not carry",
68
+ },
69
+ schema: [],
70
+ },
71
+
72
+ createOnce(context: RuleContext) {
73
+ let file = "";
74
+ let selected: ReadonlyArray<CompiledCampaign> = [];
75
+
76
+ return {
77
+ before() {
78
+ file = toRepoRelative(policy.repoRoot, context.filename);
79
+ if (file.startsWith("..")) return false;
80
+ selected = campaignsSelecting(policy.campaignRules, file);
81
+ return selected.length > 0;
82
+ },
83
+
84
+ Program(node: Program) {
85
+ const text = context.sourceCode.text;
86
+ const needsSyntax = selected.some((rule) =>
87
+ leafTermsOf(rule.detect).some(
88
+ (leaf) => leaf === "syntax" || leaf === "report" || leaf === "fn",
89
+ ),
90
+ );
91
+ const input = {
92
+ file,
93
+ text,
94
+ facts: sourceFactsOf(factsOfProgram(file, node)),
95
+ resolver: policy.resolver,
96
+ fileSystem: policy.fileSystem,
97
+ syntax: needsSyntax ? policy.syntax.parse(file, text) : null,
98
+ functions: policy.functions,
99
+ reports: policy.reports,
100
+ };
101
+ // One campaign at a time, so a report one of them cannot read costs
102
+ // that campaign's answer for this file and not its neighbours'.
103
+ const hits: Array<CampaignHit> = [];
104
+ for (const rule of selected) {
105
+ try {
106
+ for (const hit of evaluateCampaigns([rule], input)) hits.push(hit);
107
+ } catch (cause) {
108
+ if (!(cause instanceof ReportUnavailable)) throw cause;
109
+ const message = aside(cause);
110
+ if (said.has(message)) continue;
111
+ said.add(message);
112
+ context.report({ message, loc: { line: 1, column: 0 } });
113
+ }
114
+ }
115
+
116
+ for (const hit of unledgered(policy, selected, hits)) {
117
+ // A match lands where it was found; a file-unit hit, on line 1, as
118
+ // the structure rule places a finding about the file itself.
119
+ const at = hit.range ?? { start: { line: 0, column: 0 } };
120
+ context.report({
121
+ message: formatMessage(hit.violation),
122
+ loc: { line: at.start.line + 1, column: at.start.column },
123
+ });
124
+ }
125
+ },
126
+ };
127
+ },
128
+ };
129
+ };
@@ -1,17 +1,34 @@
1
1
  import * as path from "node:path";
2
2
 
3
+ import { astGrepMatcher } from "@goodbones/ast-grep";
3
4
  import {
4
5
  findManifestFile,
6
+ loadCampaignFunctions,
5
7
  type LoadedPolicy,
6
8
  loadPolicy,
7
9
  makeFileSystemLive,
10
+ makeReportSourceLive,
8
11
  readManifestFile,
12
+ reportSpecsOf,
13
+ ReportUnavailable,
9
14
  } from "@goodbones/core";
10
15
  import { typescriptLanguage } from "@goodbones/typescript";
11
16
  import * as Result from "effect/Result";
12
17
 
13
18
  export type { LoadedPolicy } from "@goodbones/core";
14
19
 
20
+ // The clock the campaigns are judged by; `ARCHITECTURE_NOW` pins it, as it
21
+ // does for the CLI.
22
+ const hostNow = (): number => {
23
+ const pinned = process.env.ARCHITECTURE_NOW;
24
+ if (pinned === undefined || pinned === "") return Date.now();
25
+ const parsed = /^\d+$/.test(pinned) ? Number(pinned) : Date.parse(pinned);
26
+ if (Number.isNaN(parsed)) {
27
+ throw new Error(`ARCHITECTURE_NOW is ${JSON.stringify(pinned)}, which is not a date.`);
28
+ }
29
+ return parsed;
30
+ };
31
+
15
32
  // The plugin's composition root: read the manifest file, construct the
16
33
  // language packs and the live file system, and hand them to the loader. A load
17
34
  // failure throws out of here and out of oxlint's import of the plugin — a
@@ -28,14 +45,40 @@ export const loadPolicyFromFile = async (
28
45
  ? findManifestFile(repoRoot)
29
46
  : path.resolve(repoRoot, configFilename);
30
47
  const read = await readManifestFile(configPath);
48
+ // The `fn` terms are imported here, before the policy loads, as the CLI
49
+ // does; the pack is composed with ast-grep for the campaigns family's
50
+ // `syntax` term, and the plugin parses with it for that family only.
51
+ const { functions, manifest } = await loadCampaignFunctions(configPath, read.manifest);
31
52
  const loaded = loadPolicy({
32
53
  repoRoot,
33
54
  configPath,
34
- manifest: read.manifest,
55
+ manifest,
35
56
  locate: read.locate,
36
- languages: [typescriptLanguage()],
57
+ languages: [typescriptLanguage({ syntax: astGrepMatcher() })],
37
58
  fileSystem: makeFileSystemLive(repoRoot),
59
+ functions,
60
+ // A `report` command runs once per process — once per editor session
61
+ // for oxlint's language server, which then sees that report until it
62
+ // restarts. A report the build writes to a file is the predictable form.
63
+ reports: makeReportSourceLive(repoRoot),
64
+ now: hostNow(),
38
65
  });
39
66
  if (Result.isFailure(loaded)) throw loaded.failure;
40
- return loaded.success;
67
+ const policy = loaded.success;
68
+ // Every `report` a campaign names is read now, while oxlint has linted
69
+ // nothing. A `command` forks this process, and once the linter is running
70
+ // Linux can refuse the fork: the linter's per-thread AST buffers merge
71
+ // into one mapping larger than RAM and swap together, which the default
72
+ // overcommit heuristic refuses to duplicate. The source caches the answer,
73
+ // and a failure, so the rules read what was read here. A report that
74
+ // cannot be read is not a load failure — the campaigns rule reports it
75
+ // once, on the first file a campaign naming it selects.
76
+ for (const spec of reportSpecsOf(policy.campaignRules)) {
77
+ try {
78
+ policy.reports.diagnosticsOf(spec, "");
79
+ } catch (cause) {
80
+ if (!(cause instanceof ReportUnavailable)) throw cause;
81
+ }
82
+ }
83
+ return policy;
41
84
  };
package/src/plugin.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { makeCampaignsRule } from "./campaigns-rule.js";
1
2
  import { loadPolicyFromFile } from "./config-loader.js";
2
3
  import { makeExportsRule } from "./exports-rule.js";
3
4
  import { makeImportsRule } from "./imports-rule.js";
@@ -28,12 +29,14 @@ export const rules: {
28
29
  readonly members: OxlintRule;
29
30
  readonly structure: OxlintRule;
30
31
  readonly surface: OxlintRule;
32
+ readonly campaigns: OxlintRule;
31
33
  } = {
32
34
  imports: makeImportsRule(policy),
33
35
  exports: makeExportsRule(policy),
34
36
  members: makeMembersRule(policy),
35
37
  structure: makeStructureRule(policy),
36
38
  surface: makeSurfaceRule(policy),
39
+ campaigns: makeCampaignsRule(policy),
37
40
  };
38
41
 
39
42
  const plugin: { readonly meta: { readonly name: string }; readonly rules: typeof rules } = {