@goodbones/oxlint 0.1.0-beta.6 → 0.1.0-beta.8
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/build/dts/campaigns-rule.d.ts +4 -0
- package/build/dts/campaigns-rule.d.ts.map +1 -0
- package/build/dts/config-loader.d.ts.map +1 -1
- package/build/dts/exports-rule.d.ts.map +1 -1
- package/build/dts/imports-rule.d.ts.map +1 -1
- package/build/dts/members-rule.d.ts.map +1 -1
- package/build/dts/oxlint-api.d.ts +4 -33
- package/build/dts/oxlint-api.d.ts.map +1 -1
- package/build/dts/plugin.d.ts +1 -0
- package/build/dts/plugin.d.ts.map +1 -1
- package/build/dts/surface-rule.d.ts.map +1 -1
- package/build/esm/campaigns-rule.js +70 -0
- package/build/esm/campaigns-rule.js.map +1 -0
- package/build/esm/config-loader.js +26 -3
- package/build/esm/config-loader.js.map +1 -1
- package/build/esm/exports-rule.js +15 -71
- package/build/esm/exports-rule.js.map +1 -1
- package/build/esm/imports-rule.js +14 -26
- package/build/esm/imports-rule.js.map +1 -1
- package/build/esm/members-rule.js +10 -112
- package/build/esm/members-rule.js.map +1 -1
- package/build/esm/oxlint-api.js +22 -20
- package/build/esm/oxlint-api.js.map +1 -1
- package/build/esm/plugin.js +2 -0
- package/build/esm/plugin.js.map +1 -1
- package/build/esm/surface-rule.js +11 -127
- package/build/esm/surface-rule.js.map +1 -1
- package/package.json +4 -3
- package/src/campaigns-rule.ts +98 -0
- package/src/config-loader.ts +27 -2
- package/src/exports-rule.ts +19 -106
- package/src/imports-rule.ts +16 -35
- package/src/members-rule.ts +11 -165
- package/src/oxlint-api.ts +31 -47
- package/src/plugin.ts +3 -0
- package/src/surface-rule.ts +15 -189
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"campaigns-rule.d.ts","sourceRoot":"","sources":["../../src/campaigns-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,YAAY,EAElB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAEL,KAAK,UAAU,EAIhB,MAAM,iBAAiB,CAAC;AA2BzB,eAAO,MAAM,iBAAiB,WAAY,YAAY,KAAG,UAoDvD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-loader.d.ts","sourceRoot":"","sources":["../../src/config-loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config-loader.d.ts","sourceRoot":"","sources":["../../src/config-loader.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,YAAY,EAKlB,MAAM,iBAAiB,CAAC;AAIzB,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAmBpD,eAAO,MAAM,kBAAkB,aACnB,MAAM,mBACC,MAAM,KACtB,OAAO,CAAC,YAAY,CA4BtB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports-rule.d.ts","sourceRoot":"","sources":["../../src/exports-rule.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"exports-rule.d.ts","sourceRoot":"","sources":["../../src/exports-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,YAAY,EAElB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAIL,KAAK,UAAU,EAIhB,MAAM,iBAAiB,CAAC;AAYzB,eAAO,MAAM,eAAe,WAAY,YAAY,KAAG,UA6ErD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imports-rule.d.ts","sourceRoot":"","sources":["../../src/imports-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,YAAY,EAGlB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"imports-rule.d.ts","sourceRoot":"","sources":["../../src/imports-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,YAAY,EAGlB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAGL,KAAK,UAAU,EAIhB,MAAM,iBAAiB,CAAC;AAOzB,eAAO,MAAM,eAAe,WAAY,YAAY,KAAG,UAoDrD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"members-rule.d.ts","sourceRoot":"","sources":["../../src/members-rule.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"members-rule.d.ts","sourceRoot":"","sources":["../../src/members-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,YAAY,EAElB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAGL,KAAK,UAAU,EAIhB,MAAM,iBAAiB,CAAC;AAEzB,eAAO,MAAM,eAAe,WAAY,YAAY,KAAG,UAiCrD,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ReadFacts, type SyntaxNode } from "@goodbones/typescript";
|
|
1
2
|
import type { RuleTester } from "oxlint/plugins-dev";
|
|
2
3
|
export type OxlintRule = Parameters<RuleTester["run"]>[1];
|
|
3
4
|
export type RuleContext = Parameters<Extract<OxlintRule, {
|
|
@@ -8,39 +9,9 @@ export type ReportableNode = Extract<Diagnostic, {
|
|
|
8
9
|
node: unknown;
|
|
9
10
|
}>["node"];
|
|
10
11
|
export type Fixer = Parameters<NonNullable<Diagnostic["fix"]>>[0];
|
|
11
|
-
export type
|
|
12
|
-
readonly source?: {
|
|
13
|
-
readonly value?: unknown;
|
|
14
|
-
} | null;
|
|
15
|
-
};
|
|
12
|
+
export type Program = RuleContext["sourceCode"]["ast"];
|
|
16
13
|
export declare const toRepoRelative: (repoRoot: string, filename: string) => string;
|
|
17
|
-
export declare const
|
|
18
|
-
export
|
|
19
|
-
readonly callee?: {
|
|
20
|
-
readonly type: string;
|
|
21
|
-
readonly name?: unknown;
|
|
22
|
-
} | null;
|
|
23
|
-
readonly arguments?: ReadonlyArray<{
|
|
24
|
-
readonly type: string;
|
|
25
|
-
readonly value?: unknown;
|
|
26
|
-
}> | null;
|
|
27
|
-
};
|
|
28
|
-
export type ImportExpressionNode = ReportableNode & {
|
|
29
|
-
readonly source?: {
|
|
30
|
-
readonly type?: string;
|
|
31
|
-
readonly value?: unknown;
|
|
32
|
-
} | null;
|
|
33
|
-
};
|
|
34
|
-
export type ImportEqualsNode = ReportableNode & {
|
|
35
|
-
readonly moduleReference?: {
|
|
36
|
-
readonly type: string;
|
|
37
|
-
readonly expression?: {
|
|
38
|
-
readonly value?: unknown;
|
|
39
|
-
} | null;
|
|
40
|
-
} | null;
|
|
41
|
-
};
|
|
42
|
-
export declare const requireSpecifierOf: (node: CallNode) => string | null;
|
|
43
|
-
export declare const importExpressionSpecifierOf: (node: ImportExpressionNode) => string | null;
|
|
44
|
-
export declare const importEqualsSpecifierOf: (node: ImportEqualsNode) => string | null;
|
|
14
|
+
export declare const at: (node: SyntaxNode) => ReportableNode;
|
|
15
|
+
export declare const factsOfProgram: (file: string, program: Program) => ReadFacts;
|
|
45
16
|
export {};
|
|
46
17
|
//# sourceMappingURL=oxlint-api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oxlint-api.d.ts","sourceRoot":"","sources":["../../src/oxlint-api.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAKrD,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1D,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC,UAAU,EAAE;IAAE,UAAU,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEpG,KAAK,UAAU,GAAG,UAAU,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvD,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,UAAU,EAAE;IAAE,IAAI,EAAE,OAAO,CAAA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build/dts/plugin.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"
|
|
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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"surface-rule.d.ts","sourceRoot":"","sources":["../../src/surface-rule.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"surface-rule.d.ts","sourceRoot":"","sources":["../../src/surface-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,YAAY,EAElB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAGL,KAAK,UAAU,EAIhB,MAAM,iBAAiB,CAAC;AAEzB,eAAO,MAAM,eAAe,WAAY,YAAY,KAAG,UA4CrD,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { campaignsSelecting, evaluateCampaigns, formatMessage, leafTermsOf, reconcile, } 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
|
+
export const makeCampaignsRule = (policy) => ({
|
|
26
|
+
meta: {
|
|
27
|
+
type: "problem",
|
|
28
|
+
docs: {
|
|
29
|
+
description: "the campaigns: every place a pattern the repository is migrating away from still occurs, that its ledger does not carry",
|
|
30
|
+
},
|
|
31
|
+
schema: [],
|
|
32
|
+
},
|
|
33
|
+
createOnce(context) {
|
|
34
|
+
let file = "";
|
|
35
|
+
let selected = [];
|
|
36
|
+
return {
|
|
37
|
+
before() {
|
|
38
|
+
file = toRepoRelative(policy.repoRoot, context.filename);
|
|
39
|
+
if (file.startsWith(".."))
|
|
40
|
+
return false;
|
|
41
|
+
selected = campaignsSelecting(policy.campaignRules, file);
|
|
42
|
+
return selected.length > 0;
|
|
43
|
+
},
|
|
44
|
+
Program(node) {
|
|
45
|
+
const text = context.sourceCode.text;
|
|
46
|
+
const needsSyntax = selected.some((rule) => leafTermsOf(rule.detect).some((leaf) => leaf === "syntax" || leaf === "report" || leaf === "fn"));
|
|
47
|
+
const hits = evaluateCampaigns(selected, {
|
|
48
|
+
file,
|
|
49
|
+
text,
|
|
50
|
+
facts: sourceFactsOf(factsOfProgram(file, node)),
|
|
51
|
+
resolver: policy.resolver,
|
|
52
|
+
fileSystem: policy.fileSystem,
|
|
53
|
+
syntax: needsSyntax ? policy.syntax.parse(file, text) : null,
|
|
54
|
+
functions: policy.functions,
|
|
55
|
+
reports: policy.reports,
|
|
56
|
+
});
|
|
57
|
+
for (const hit of unledgered(policy, selected, hits)) {
|
|
58
|
+
// A match lands where it was found; a file-unit hit, on line 1, as
|
|
59
|
+
// the structure rule places a finding about the file itself.
|
|
60
|
+
const at = hit.range ?? { start: { line: 0, column: 0 } };
|
|
61
|
+
context.report({
|
|
62
|
+
message: formatMessage(hit.violation),
|
|
63
|
+
loc: { line: at.start.line + 1, column: at.start.column },
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=campaigns-rule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"campaigns-rule.js","sourceRoot":"","sources":["../../src/campaigns-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAElB,iBAAiB,EACjB,aAAa,EACb,WAAW,EAEX,SAAS,GACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,EACL,cAAc,EAId,cAAc,GACf,MAAM,iBAAiB,CAAC;AAEzB,8EAA8E;AAC9E,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7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,GAAG,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;oBAC1D,OAAO,CAAC,MAAM,CAAC;wBACb,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC;wBACrC,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE;qBAC1D,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
|
-
import {
|
|
2
|
+
import { astGrepMatcher } from "@goodbones/ast-grep";
|
|
3
|
+
import { findManifestFile, loadCampaignFunctions, loadPolicy, makeFileSystemLive, makeReportSourceLive, readManifestFile, } 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,13 +27,23 @@ 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
|
|
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;
|
|
@@ -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,
|
|
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,gBAAgB,EAChB,qBAAqB,EAErB,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,gBAAg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MAAM,qBAAqB,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvF,MAAM,MAAM,GAAG,UAAU,CAAC;QACxB,QAAQ;QACR,UAAU;QACV,QAAQ;QACR,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,SAAS,EAAE,CAAC,kBAAkB,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,EAAE,CAAC,CAAC;QAC7D,UAAU,EAAE,kBAAkB,CAAC,QAAQ,CAAC;QACxC,SAAS;QACT,qEAAqE;QACrE,qEAAqE;QACrE,yEAAyE;QACzE,OAAO,EAAE,oBAAoB,CAAC,QAAQ,CAAC;QACvC,GAAG,EAAE,OAAO,EAAE;KACf,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,49 +1,6 @@
|
|
|
1
1
|
import { evaluateSelectedBindings, exportRulesSelecting, formatMessage, } from "@goodbones/core";
|
|
2
2
|
import * as Result from "effect/Result";
|
|
3
|
-
import {
|
|
4
|
-
const nameOf = (node) => {
|
|
5
|
-
if (node === null || node === undefined)
|
|
6
|
-
return null;
|
|
7
|
-
if (typeof node.name === "string")
|
|
8
|
-
return node.name;
|
|
9
|
-
// `import { "a-b" as ab }` — a string-literal export name.
|
|
10
|
-
return typeof node.value === "string" ? node.value : null;
|
|
11
|
-
};
|
|
12
|
-
// The whole module, as one binding. `export * from "m"`, `export * as ns from
|
|
13
|
-
// "m"`, `import x = require("m")`, `import("m")` and `require("m")` all carry
|
|
14
|
-
// every export of `m` at once, exactly as `import * as ns` does — and are the
|
|
15
|
-
// same way around a rule about a name. A side-effect import carries nothing.
|
|
16
|
-
const wholeModule = (node, local = "") => ({
|
|
17
|
-
symbol: "*",
|
|
18
|
-
kind: "namespace",
|
|
19
|
-
node,
|
|
20
|
-
local,
|
|
21
|
-
});
|
|
22
|
-
const boundOf = (specifier) => {
|
|
23
|
-
const local = nameOf(specifier.local) ?? "";
|
|
24
|
-
switch (specifier.type) {
|
|
25
|
-
case "ImportSpecifier": {
|
|
26
|
-
const symbol = nameOf(specifier.imported);
|
|
27
|
-
return symbol === null ? null : { symbol, kind: "named", node: specifier, local };
|
|
28
|
-
}
|
|
29
|
-
case "ImportDefaultSpecifier":
|
|
30
|
-
return { symbol: "default", kind: "default", node: specifier, local };
|
|
31
|
-
case "ImportNamespaceSpecifier":
|
|
32
|
-
return { symbol: "*", kind: "namespace", node: specifier, local };
|
|
33
|
-
// `export { a } from "…"` — `local` is the name in the source module.
|
|
34
|
-
case "ExportSpecifier": {
|
|
35
|
-
const symbol = nameOf(specifier.local);
|
|
36
|
-
return symbol === null ? null : { symbol, kind: "named", node: specifier, local: symbol };
|
|
37
|
-
}
|
|
38
|
-
default:
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const specifierOf = (node) => {
|
|
43
|
-
const value = node.source?.value;
|
|
44
|
-
return typeof value === "string" ? value : null;
|
|
45
|
-
};
|
|
46
|
-
const boundSpecifiers = (node) => (node.specifiers ?? []).map(boundOf).filter((one) => one !== null);
|
|
3
|
+
import { at, factsOfProgram, toRepoRelative, } from "./oxlint-api.js";
|
|
47
4
|
// `import { A, B as C } from "pkg"` becomes `import * as A from "pkg/A"` and
|
|
48
5
|
// `import * as C from "pkg/B"`. Only whole-declaration rewrites are offered: a
|
|
49
6
|
// declaration mixing restricted named imports with a default or namespace one
|
|
@@ -64,15 +21,16 @@ export const makeExportsRule = (policy) => ({
|
|
|
64
21
|
createOnce(context) {
|
|
65
22
|
let importer = "";
|
|
66
23
|
let selected = [];
|
|
67
|
-
// `
|
|
68
|
-
//
|
|
69
|
-
//
|
|
70
|
-
const check = (
|
|
71
|
-
|
|
24
|
+
// Only an `import` declaration can be rewritten into subpath namespace
|
|
25
|
+
// imports. `export *` and the whole-module forms are reported and left
|
|
26
|
+
// for the author.
|
|
27
|
+
const check = (edge) => {
|
|
28
|
+
const { bindings: bound, node, specifier } = edge;
|
|
29
|
+
if (bound.length === 0)
|
|
72
30
|
return;
|
|
73
31
|
const outcome = evaluateSelectedBindings(selected, policy.resolver, {
|
|
74
32
|
importer,
|
|
75
|
-
specifier
|
|
33
|
+
specifier,
|
|
76
34
|
bindings: bound,
|
|
77
35
|
});
|
|
78
36
|
if (Result.isFailure(outcome)) {
|
|
@@ -87,20 +45,20 @@ export const makeExportsRule = (policy) => ({
|
|
|
87
45
|
// The rewrite is `import * as X from "pkg/<name>"`, which only means
|
|
88
46
|
// something for a named binding — a namespace one has no name to put
|
|
89
47
|
// in the subpath.
|
|
90
|
-
const rewritable =
|
|
48
|
+
const rewritable = edge.form === "import" &&
|
|
91
49
|
rule.fix === "subpath-namespace-import" &&
|
|
92
50
|
offending.length === bound.length &&
|
|
93
51
|
offending.every((one) => one.kind === "named");
|
|
94
52
|
if (rewritable) {
|
|
95
53
|
context.report({
|
|
96
|
-
node,
|
|
54
|
+
node: at(node),
|
|
97
55
|
message: formatMessage(violation),
|
|
98
|
-
fix: (fixer) => fixer.replaceText(node, subpathNamespaceImport(
|
|
56
|
+
fix: (fixer) => fixer.replaceText(at(node), subpathNamespaceImport(specifier, offending)),
|
|
99
57
|
});
|
|
100
58
|
continue;
|
|
101
59
|
}
|
|
102
60
|
context.report({
|
|
103
|
-
node: offending[0]?.node ?? node,
|
|
61
|
+
node: at(offending[0]?.node ?? node),
|
|
104
62
|
message: formatMessage(violation),
|
|
105
63
|
});
|
|
106
64
|
}
|
|
@@ -113,23 +71,9 @@ export const makeExportsRule = (policy) => ({
|
|
|
113
71
|
selected = exportRulesSelecting(policy.exportRules, importer);
|
|
114
72
|
return selected.length > 0;
|
|
115
73
|
},
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
ExportNamedDeclaration(node) {
|
|
120
|
-
check(node, specifierOf(node), boundSpecifiers(node), false);
|
|
121
|
-
},
|
|
122
|
-
ExportAllDeclaration(node) {
|
|
123
|
-
check(node, specifierOf(node), [wholeModule(node, nameOf(node.exported) ?? "")], false);
|
|
124
|
-
},
|
|
125
|
-
ImportExpression(node) {
|
|
126
|
-
check(node, importExpressionSpecifierOf(node), [wholeModule(node)], false);
|
|
127
|
-
},
|
|
128
|
-
CallExpression(node) {
|
|
129
|
-
check(node, requireSpecifierOf(node), [wholeModule(node)], false);
|
|
130
|
-
},
|
|
131
|
-
TSImportEqualsDeclaration(node) {
|
|
132
|
-
check(node, importEqualsSpecifierOf(node), [wholeModule(node)], false);
|
|
74
|
+
Program(node) {
|
|
75
|
+
for (const edge of factsOfProgram(importer, node).edges)
|
|
76
|
+
check(edge);
|
|
133
77
|
},
|
|
134
78
|
};
|
|
135
79
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports-rule.js","sourceRoot":"","sources":["../../src/exports-rule.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"exports-rule.js","sourceRoot":"","sources":["../../src/exports-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,aAAa,GAGd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EACL,EAAE,EACF,cAAc,EAKd,cAAc,GACf,MAAM,iBAAiB,CAAC;AAEzB,6EAA6E;AAC7E,+EAA+E;AAC/E,8EAA8E;AAC9E,gFAAgF;AAChF,uDAAuD;AACvD,MAAM,sBAAsB,GAAG,CAAC,SAAiB,EAAE,KAAiC,EAAU,EAAE,CAC9F,KAAK;KACF,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,eAAe,OAAO,CAAC,KAAK,UAAU,SAAS,IAAI,OAAO,CAAC,MAAM,IAAI,CAAC;KACvF,IAAI,CAAC,IAAI,CAAC,CAAC;AAEhB,MAAM,CAAC,MAAM,eAAe,GAAG,CAA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AAK;oBAAE,KAAK,CAAC,IAAI,CAAC,CAAC;YACvE,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { evaluateSelectedEdge, formatMessage, rulesSelecting, } from "@goodbones/core";
|
|
2
2
|
import * as Result from "effect/Result";
|
|
3
|
-
import {
|
|
3
|
+
import { at, factsOfProgram, toRepoRelative, } from "./oxlint-api.js";
|
|
4
4
|
const unresolvedMessage = (specifier, detail) => `[unresolved-import] "${specifier}" could not be resolved, so every import rule about it ` +
|
|
5
5
|
`enforces nothing. Fix the resolve scope in the architecture config, or list the specifier ` +
|
|
6
6
|
`in resolve.ignoreUnresolved. (${detail})`;
|
|
@@ -18,31 +18,29 @@ export const makeImportsRule = (policy) => ({
|
|
|
18
18
|
createOnce(context) {
|
|
19
19
|
let importer = "";
|
|
20
20
|
let selected = [];
|
|
21
|
-
const check = (
|
|
22
|
-
|
|
23
|
-
return;
|
|
21
|
+
const check = (edge) => {
|
|
22
|
+
const { specifier } = edge;
|
|
24
23
|
const outcome = evaluateSelectedEdge(selected, policy.resolver, { importer, specifier });
|
|
25
24
|
if (Result.isFailure(outcome)) {
|
|
26
25
|
if (policy.config.resolve.unresolved === "off")
|
|
27
26
|
return;
|
|
28
27
|
if (policy.ignoreUnresolved.some((pattern) => pattern.test(specifier)))
|
|
29
28
|
return;
|
|
30
|
-
context.report({
|
|
29
|
+
context.report({
|
|
30
|
+
node: at(edge.node),
|
|
31
|
+
message: unresolvedMessage(specifier, outcome.failure.detail),
|
|
32
|
+
});
|
|
31
33
|
return;
|
|
32
34
|
}
|
|
33
35
|
for (const violation of outcome.success) {
|
|
34
36
|
if (policy.baseline.isBaselined(violation))
|
|
35
37
|
continue;
|
|
36
|
-
context.report({ node, message: formatMessage(violation) });
|
|
38
|
+
context.report({ node: at(edge.node), message: formatMessage(violation) });
|
|
37
39
|
}
|
|
38
40
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// Every form that names a module is an edge. The CLI adapter reads the same
|
|
43
|
-
// five out of TypeScript's tree, and the parity suite holds the two to it: a
|
|
44
|
-
// `require` the plugin skipped would be a rule that enforces nothing under
|
|
45
|
-
// `oxlint` while failing under `architecture check`.
|
|
41
|
+
// Every form that names a module is an edge, and the pack's reader is
|
|
42
|
+
// what says which forms those are — the same reader the CLI reads a file
|
|
43
|
+
// through, so a form one host sees the other sees too.
|
|
46
44
|
return {
|
|
47
45
|
before() {
|
|
48
46
|
importer = toRepoRelative(policy.repoRoot, context.filename);
|
|
@@ -51,19 +49,9 @@ export const makeImportsRule = (policy) => ({
|
|
|
51
49
|
selected = rulesSelecting(policy.importRules, importer);
|
|
52
50
|
return selected.length > 0;
|
|
53
51
|
},
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// `import("m")` with a literal argument. A computed one is not a fact a
|
|
58
|
-
// static policy can speak about, in either adapter.
|
|
59
|
-
ImportExpression(node) {
|
|
60
|
-
check(node, importExpressionSpecifierOf(node));
|
|
61
|
-
},
|
|
62
|
-
CallExpression(node) {
|
|
63
|
-
check(node, requireSpecifierOf(node));
|
|
64
|
-
},
|
|
65
|
-
TSImportEqualsDeclaration(node) {
|
|
66
|
-
check(node, importEqualsSpecifierOf(node));
|
|
52
|
+
Program(node) {
|
|
53
|
+
for (const edge of factsOfProgram(importer, node).edges)
|
|
54
|
+
check(edge);
|
|
67
55
|
},
|
|
68
56
|
};
|
|
69
57
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imports-rule.js","sourceRoot":"","sources":["../../src/imports-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,aAAa,EAEb,cAAc,GAEf,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"imports-rule.js","sourceRoot":"","sources":["../../src/imports-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,aAAa,EAEb,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AAE,iBAAiB,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;iBAC9D,CAAC,CAAC;gBACH,OAAO;YACT,CAAC;YAED,KAAK,MAAM,SAAS,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;gBACxC,IAAI,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,SAAS,CAAC;oBAAE,SAAS;gBACrD,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;YAC7E,CAAC;QACH,CAAC,CAAC;QAEF,sEAAsE;QACtE,yEAAyE;QACzE,uDAAuD;QACvD,OAAO;YACL,MAAM;gBACJ,QAAQ,GAAG,cAAc,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;gBAC7D,IAAI,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC;oBAAE,OAAO,KAAK,CAAC;gBAC5C,QAAQ,GAAG,cAAc,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;gBACxD,OAAO,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;YAC7B,CAAC;YACD,OAAO,CAAC,IAAa;gBACnB,KAAK,MAAM,IAAI,IAAI,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,KAAK;oBAAE,KAAK,CAAC,IAAI,CAAC,CAAC;YACvE,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -1,59 +1,5 @@
|
|
|
1
1
|
import { evaluateMemberSite, formatMessage, memberRulesSelecting, } from "@goodbones/core";
|
|
2
|
-
import { toRepoRelative, } from "./oxlint-api.js";
|
|
3
|
-
const isMemberList = (value) => Array.isArray(value);
|
|
4
|
-
// The member shapes that carry a name a vocabulary rule can speak about: a
|
|
5
|
-
// property or method signature in a type, a property, method or accessor in a
|
|
6
|
-
// class. Mirrors the CLI's `isNamedMember`.
|
|
7
|
-
const DECLARED_MEMBER_TYPES = new Set([
|
|
8
|
-
"TSPropertySignature",
|
|
9
|
-
"TSMethodSignature",
|
|
10
|
-
"PropertyDefinition",
|
|
11
|
-
"MethodDefinition",
|
|
12
|
-
"TSAbstractPropertyDefinition",
|
|
13
|
-
"TSAbstractMethodDefinition",
|
|
14
|
-
]);
|
|
15
|
-
// The type literals written in a type, through intersections, unions and
|
|
16
|
-
// parentheses. A reference is not followed: its members are declared where it
|
|
17
|
-
// is, and reported there under its own name. Mirrors the CLI's `literalsOf`.
|
|
18
|
-
const literalsOf = (node) => {
|
|
19
|
-
if (node === null || node === undefined)
|
|
20
|
-
return [];
|
|
21
|
-
switch (node.type) {
|
|
22
|
-
case "TSTypeLiteral":
|
|
23
|
-
return [node];
|
|
24
|
-
case "TSIntersectionType":
|
|
25
|
-
case "TSUnionType":
|
|
26
|
-
return (node.types ?? []).flatMap(literalsOf);
|
|
27
|
-
case "TSParenthesizedType":
|
|
28
|
-
return literalsOf(node.typeAnnotation);
|
|
29
|
-
default:
|
|
30
|
-
return [];
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
const nameOf = (node) => {
|
|
34
|
-
if (node === null || node === undefined)
|
|
35
|
-
return null;
|
|
36
|
-
if (typeof node.name === "string")
|
|
37
|
-
return node.name;
|
|
38
|
-
return typeof node.value === "string" ? node.value : null;
|
|
39
|
-
};
|
|
40
|
-
// The name a call is made by: `f()` and `x.f()` are both `f`. `x[f]()` and
|
|
41
|
-
// `x["f"]()` are not — a computed property is not a name a vocabulary rule can
|
|
42
|
-
// speak about — and neither is a private `x.#f()`. The CLI reads the same
|
|
43
|
-
// three cases out of TypeScript's tree; the parity suite keeps them agreeing.
|
|
44
|
-
const calleeName = (node) => {
|
|
45
|
-
const callee = node.callee;
|
|
46
|
-
if (callee === null || callee === undefined)
|
|
47
|
-
return null;
|
|
48
|
-
if (callee.type === "Identifier" && typeof callee.name === "string")
|
|
49
|
-
return callee.name;
|
|
50
|
-
if (callee.type !== "MemberExpression" || callee.computed === true)
|
|
51
|
-
return null;
|
|
52
|
-
const property = callee.property;
|
|
53
|
-
if (property?.type !== "Identifier")
|
|
54
|
-
return null;
|
|
55
|
-
return nameOf(property);
|
|
56
|
-
};
|
|
2
|
+
import { at, factsOfProgram, toRepoRelative, } from "./oxlint-api.js";
|
|
57
3
|
export const makeMembersRule = (policy) => ({
|
|
58
4
|
meta: {
|
|
59
5
|
type: "problem",
|
|
@@ -65,36 +11,8 @@ export const makeMembersRule = (policy) => ({
|
|
|
65
11
|
createOnce(context) {
|
|
66
12
|
let file = "";
|
|
67
13
|
let selected = [];
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
file,
|
|
71
|
-
subject: declaration === undefined ? "calls" : "members",
|
|
72
|
-
name,
|
|
73
|
-
...(declaration === undefined
|
|
74
|
-
? {}
|
|
75
|
-
: { in: declaration.name, declares: declaration.declares }),
|
|
76
|
-
});
|
|
77
|
-
for (const violation of violations) {
|
|
78
|
-
if (policy.baseline.isBaselined(violation))
|
|
79
|
-
continue;
|
|
80
|
-
context.report({ node, message: formatMessage(violation) });
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
// The members written in a declaration, under that declaration's name and
|
|
84
|
-
// kind. A computed key is not a name a vocabulary rule can speak about;
|
|
85
|
-
// neither is a private `#name`, an index, call or construct signature, or
|
|
86
|
-
// a constructor.
|
|
87
|
-
const declared = (declaration, declares, members) => {
|
|
88
|
-
for (const member of members) {
|
|
89
|
-
if (member.computed === true || !DECLARED_MEMBER_TYPES.has(member.type))
|
|
90
|
-
continue;
|
|
91
|
-
if (member.key?.type === "PrivateIdentifier" || member.kind === "constructor")
|
|
92
|
-
continue;
|
|
93
|
-
const name = nameOf(member.key);
|
|
94
|
-
if (name !== null)
|
|
95
|
-
report(member.key ?? member, name, { name: declaration, declares });
|
|
96
|
-
}
|
|
97
|
-
};
|
|
14
|
+
// A declared member is reported at its key, a call at the call — the nodes
|
|
15
|
+
// the pack's reader hands back with each site.
|
|
98
16
|
return {
|
|
99
17
|
before() {
|
|
100
18
|
file = toRepoRelative(policy.repoRoot, context.filename);
|
|
@@ -103,35 +21,15 @@ export const makeMembersRule = (policy) => ({
|
|
|
103
21
|
selected = memberRulesSelecting(policy.memberRules, file);
|
|
104
22
|
return selected.length > 0;
|
|
105
23
|
},
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
24
|
+
Program(node) {
|
|
25
|
+
for (const site of factsOfProgram(file, node).memberSites) {
|
|
26
|
+
for (const violation of evaluateMemberSite(selected, site)) {
|
|
27
|
+
if (policy.baseline.isBaselined(violation))
|
|
28
|
+
continue;
|
|
29
|
+
context.report({ node: at(site.node), message: formatMessage(violation) });
|
|
30
|
+
}
|
|
112
31
|
}
|
|
113
32
|
},
|
|
114
|
-
TSInterfaceDeclaration(node) {
|
|
115
|
-
const declaration = nameOf(node.id);
|
|
116
|
-
const members = node.body?.body;
|
|
117
|
-
if (declaration === null || !isMemberList(members))
|
|
118
|
-
return;
|
|
119
|
-
declared(declaration, "interface", members);
|
|
120
|
-
},
|
|
121
|
-
// A named class only, as the CLI reads it: an anonymous default class has
|
|
122
|
-
// no name for `in`, and a class expression is a value.
|
|
123
|
-
ClassDeclaration(node) {
|
|
124
|
-
const declaration = nameOf(node.id);
|
|
125
|
-
const members = node.body?.body;
|
|
126
|
-
if (declaration === null || !isMemberList(members))
|
|
127
|
-
return;
|
|
128
|
-
declared(declaration, "class", members);
|
|
129
|
-
},
|
|
130
|
-
CallExpression(node) {
|
|
131
|
-
const name = calleeName(node);
|
|
132
|
-
if (name !== null)
|
|
133
|
-
report(node, name);
|
|
134
|
-
},
|
|
135
33
|
};
|
|
136
34
|
},
|
|
137
35
|
});
|