@hailstails/hone 0.1.0-pre.4 → 0.1.0-pre.5
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/ADOPTING.md +37 -12
- package/MIGRATING.md +4 -4
- package/README.md +35 -16
- package/api/audit.d.ts +3 -2
- package/api/rule-set.d.ts +2 -4
- package/chunks/chunk-3HFJHJDO.js +53 -0
- package/chunks/chunk-7OVV6NEU.js +22 -0
- package/chunks/chunk-7PVPPH4C.js +13 -0
- package/chunks/chunk-HVABJ7T4.js +361 -0
- package/chunks/{chunk-BX6QHLSZ.js → chunk-IIMK5BCL.js} +57 -4
- package/chunks/{chunk-FOAGAYXM.js → chunk-SWPCKTJV.js} +44 -397
- package/chunks/{chunk-RZA3OVOO.js → chunk-VUG3DJHN.js} +5 -3
- package/chunks/{chunk-EYCRDEXX.js → chunk-YBWVUDIG.js} +2 -13
- package/core/check/tool-command.js +356 -81
- package/core/mechanism-port/piece-failure-types.d.ts +14 -0
- package/core/mechanism-port/runner-module-types.d.ts +5 -0
- package/core/rule-set-reader/authored-rule-set-types.d.ts +48 -0
- package/core/values/json-value.d.ts +3 -0
- package/docs/adding-a-discipline-or-mechanism.md +6 -3
- package/docs/extending.md +357 -0
- package/mechanisms/audit/CD-1/any-cast.js +9 -37
- package/mechanisms/audit/CD-19/import-boundaries.js +79 -68
- package/mechanisms/audit/CD-19/piece.json +5 -0
- package/mechanisms/audit/CD-2/cast-expressions.js +14 -37
- package/mechanisms/audit/CD-5/comments-directives.js +137 -55
- package/mechanisms/audit/CD-5/piece.json +7 -0
- package/mechanisms/audit/runner/README.md +1 -0
- package/mechanisms/audit/runner/runner.js +10 -6
- package/mechanisms/audit/runner/typescript-parse.d.ts +6 -0
- package/mechanisms/audit/runner/walker-piece.d.ts +5 -5
- package/mechanisms/eslint/runner/README.md +1 -1
- package/mechanisms/eslint/runner/runner.js +85 -35
- package/package.json +4 -4
- package/rules/CD-1/README.md +5 -5
- package/rules/CD-1/discipline.json +16 -6
- package/rules/CD-19/README.md +13 -3
- package/rules/CD-19/discipline.json +6 -8
- package/rules/CD-2/README.md +8 -4
- package/rules/CD-2/discipline.json +25 -7
- package/rules/CD-5/README.md +17 -5
- package/rules/CD-5/discipline.json +66 -0
- package/core/mechanism-port/runner-failure-types.d.ts +0 -38
- package/core/rule-set-reader/rule-set-types.d.ts +0 -41
- /package/api/{audit.js → audit.mjs} +0 -0
- /package/api/{rule-set.js → rule-set.mjs} +0 -0
|
@@ -1,30 +1,34 @@
|
|
|
1
1
|
import {
|
|
2
2
|
eslintConfigLookupSchema,
|
|
3
3
|
parsedJson
|
|
4
|
-
} from "../../../chunks/chunk-
|
|
4
|
+
} from "../../../chunks/chunk-IIMK5BCL.js";
|
|
5
5
|
import {
|
|
6
6
|
createDefaultPackageLocationPort,
|
|
7
|
-
gatheredOutcomes,
|
|
8
7
|
installRootOfRunnerEntry,
|
|
9
8
|
toolchainBoundEmbeddedRunner
|
|
10
|
-
} from "../../../chunks/chunk-
|
|
9
|
+
} from "../../../chunks/chunk-YBWVUDIG.js";
|
|
10
|
+
import {
|
|
11
|
+
gatheredOutcomes
|
|
12
|
+
} from "../../../chunks/chunk-7PVPPH4C.js";
|
|
11
13
|
import {
|
|
12
|
-
TOOL_IDENTITY,
|
|
13
14
|
absolutePathSchema,
|
|
14
|
-
clauseAddressText,
|
|
15
15
|
createDefaultFileTextPort,
|
|
16
16
|
createDefaultModuleLoaderPort,
|
|
17
17
|
createDefaultPathPort,
|
|
18
|
-
external_exports,
|
|
19
18
|
installFormOf,
|
|
20
19
|
isRepoPathText,
|
|
21
20
|
loadedPeer,
|
|
22
21
|
moduleExtensionOf,
|
|
23
22
|
moduleFileForm,
|
|
24
23
|
repoPathSchema,
|
|
25
|
-
sameClauseAddress,
|
|
26
24
|
versionSupport
|
|
27
|
-
} from "../../../chunks/chunk-
|
|
25
|
+
} from "../../../chunks/chunk-HVABJ7T4.js";
|
|
26
|
+
import {
|
|
27
|
+
TOOL_IDENTITY,
|
|
28
|
+
clauseAddressText,
|
|
29
|
+
external_exports,
|
|
30
|
+
sameClauseAddress
|
|
31
|
+
} from "../../../chunks/chunk-SWPCKTJV.js";
|
|
28
32
|
import {
|
|
29
33
|
__commonJS,
|
|
30
34
|
__toESM
|
|
@@ -2389,7 +2393,11 @@ var resolvedConfigSchema = external_exports.union([
|
|
|
2389
2393
|
rules: external_exports.record(
|
|
2390
2394
|
external_exports.string(),
|
|
2391
2395
|
external_exports.tuple([external_exports.union([external_exports.literal(0), external_exports.literal(1), external_exports.literal(2)])], external_exports.unknown())
|
|
2392
|
-
).optional()
|
|
2396
|
+
).optional(),
|
|
2397
|
+
plugins: external_exports.record(external_exports.string(), external_exports.unknown()).optional(),
|
|
2398
|
+
language: external_exports.unknown().optional(),
|
|
2399
|
+
processor: external_exports.unknown().optional(),
|
|
2400
|
+
languageOptions: external_exports.looseObject({ parser: external_exports.unknown().optional() }).optional()
|
|
2393
2401
|
})
|
|
2394
2402
|
]);
|
|
2395
2403
|
var ruleStateOf = (request) => {
|
|
@@ -2400,7 +2408,8 @@ var ruleStateOf = (request) => {
|
|
|
2400
2408
|
if (entry === void 0) {
|
|
2401
2409
|
return { state: "rule-absent" };
|
|
2402
2410
|
}
|
|
2403
|
-
|
|
2411
|
+
const [severity, ...options] = entry;
|
|
2412
|
+
return { state: "configured", severity, options };
|
|
2404
2413
|
};
|
|
2405
2414
|
|
|
2406
2415
|
// mechanisms/eslint/runner/eslint-plugin-schema.ts
|
|
@@ -2696,7 +2705,7 @@ var governanceConfig = (request) => ({
|
|
|
2696
2705
|
languageOptions: { parser: request.parser },
|
|
2697
2706
|
plugins: {
|
|
2698
2707
|
...request.plugins,
|
|
2699
|
-
[reservedNamespace]: inlineConfigPlugin({ ruleIds: request.
|
|
2708
|
+
[reservedNamespace]: inlineConfigPlugin({ ruleIds: request.watchedRuleIds })
|
|
2700
2709
|
},
|
|
2701
2710
|
rules: Object.fromEntries(
|
|
2702
2711
|
[...request.rules, { ruleId: INLINE_CONFIG_RULE_ID, options: [] }].map(
|
|
@@ -2709,7 +2718,12 @@ var governanceOptions = (request) => ({
|
|
|
2709
2718
|
overrideConfigFile: true,
|
|
2710
2719
|
ignore: false,
|
|
2711
2720
|
allowInlineConfig: false,
|
|
2712
|
-
overrideConfig: governanceConfig({
|
|
2721
|
+
overrideConfig: governanceConfig({
|
|
2722
|
+
plugins: request.plugins,
|
|
2723
|
+
rules: request.rules,
|
|
2724
|
+
watchedRuleIds: request.watchedRuleIds,
|
|
2725
|
+
parser: request.parser
|
|
2726
|
+
})
|
|
2713
2727
|
});
|
|
2714
2728
|
var thrownDetail = (thrown) => thrown instanceof Error ? thrown.message : String(thrown);
|
|
2715
2729
|
var toolFailed = (thrown) => ({
|
|
@@ -2806,7 +2820,8 @@ var sourceCaseVerdicts = (request) => {
|
|
|
2806
2820
|
cwd: request.cwd,
|
|
2807
2821
|
parser: request.toolchain.typescriptParser,
|
|
2808
2822
|
plugins: { [request.pluginNamespace]: request.plugin },
|
|
2809
|
-
rules: [{ ruleId, options: request.options }]
|
|
2823
|
+
rules: [{ ruleId, options: request.options }],
|
|
2824
|
+
watchedRuleIds: [ruleId]
|
|
2810
2825
|
})
|
|
2811
2826
|
}),
|
|
2812
2827
|
act: (eslint) => lintedCasesOf({ eslint, cases: request.cases }),
|
|
@@ -2827,6 +2842,7 @@ var createEslintPort = (options) => ({
|
|
|
2827
2842
|
cwd: request.repoRoot,
|
|
2828
2843
|
plugins: request.plugins,
|
|
2829
2844
|
rules: request.rules,
|
|
2845
|
+
watchedRuleIds: request.watchedRuleIds,
|
|
2830
2846
|
parser: options.toolchain.typescriptParser
|
|
2831
2847
|
})
|
|
2832
2848
|
});
|
|
@@ -2837,7 +2853,7 @@ var createEslintPort = (options) => ({
|
|
|
2837
2853
|
lintSourceCases: (request) => sourceCaseVerdicts({ ...request, toolchain: options.toolchain })
|
|
2838
2854
|
});
|
|
2839
2855
|
var NEAREST_CONFIG_LOOKUPS = [
|
|
2840
|
-
{ releases: { packageName: "eslint", lines: [{ floor: "9.
|
|
2856
|
+
{ releases: { packageName: "eslint", lines: [{ floor: "9.28.0", below: "9.30.0" }] }, flags: ["unstable_config_lookup_from_file"] },
|
|
2841
2857
|
{ releases: { packageName: "eslint", lines: [{ floor: "9.30.0", below: "10.0.0" }] }, flags: ["v10_config_lookup_from_file"] }
|
|
2842
2858
|
];
|
|
2843
2859
|
var lookupFlagsOf = (request) => NEAREST_CONFIG_LOOKUPS.find((lookup) => versionSupport({ requirement: lookup.releases, version: request.version }) === "supported")?.flags ?? [];
|
|
@@ -3303,6 +3319,8 @@ var PROJECTION_PATH = repoPathSchema.parse("disciplines.eslint.mjs");
|
|
|
3303
3319
|
var SOURCE_FILES = "**/*.{ts,tsx,mts,cts}";
|
|
3304
3320
|
var GLOB_SPECIAL_CHARACTERS = /[\\*?[\]{}()!+@]/g;
|
|
3305
3321
|
var PARENT_PREFIX = "../";
|
|
3322
|
+
var FILE_RECORDS_CATEGORY = "file-records";
|
|
3323
|
+
var CLAUSE_SEPARATOR = ", ";
|
|
3306
3324
|
var codeUnitOrder = (request) => {
|
|
3307
3325
|
if (request.left < request.right) {
|
|
3308
3326
|
return -1;
|
|
@@ -3352,13 +3370,24 @@ var pieceBlock = (request) => blockText({
|
|
|
3352
3370
|
var ruleIdsOfClause = (request) => request.pieces.flatMap((piece) => piece.clauses).filter(
|
|
3353
3371
|
(clause) => sameClauseAddress({ left: clause.address, right: request.address }) === "same"
|
|
3354
3372
|
).map((clause) => clause.ruleId).sort((left, right) => codeUnitOrder({ left, right }));
|
|
3355
|
-
var
|
|
3373
|
+
var filesLines = (request) => [
|
|
3374
|
+
" files: [",
|
|
3375
|
+
...request.files.map((file) => ` ${quoted({ text: escapedGlobPath({ path: file }) })},`),
|
|
3376
|
+
" ],"
|
|
3377
|
+
];
|
|
3378
|
+
var fileRecordGroupBlock = (request) => blockText({
|
|
3356
3379
|
lines: [
|
|
3357
|
-
` name: ${quoted({
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3380
|
+
` name: ${quoted({ text: `${reservedNamespace}/${FILE_RECORDS_CATEGORY}/${request.group.clausesText}` })},`,
|
|
3381
|
+
...filesLines({ files: request.group.files }),
|
|
3382
|
+
rulesLine({
|
|
3383
|
+
rules: offLines({
|
|
3384
|
+
ruleIds: [
|
|
3385
|
+
...new Set(
|
|
3386
|
+
request.group.clauses.flatMap((address) => ruleIdsOfClause({ pieces: request.pieces, address }))
|
|
3387
|
+
)
|
|
3388
|
+
]
|
|
3389
|
+
})
|
|
3390
|
+
})
|
|
3362
3391
|
]
|
|
3363
3392
|
});
|
|
3364
3393
|
var clauseWideBlock = (request) => blockText({
|
|
@@ -3369,15 +3398,25 @@ var clauseWideBlock = (request) => blockText({
|
|
|
3369
3398
|
rulesLine({ rules: offLines({ ruleIds: ruleIdsOfClause({ pieces: request.pieces, address: request.record.clause }) }) })
|
|
3370
3399
|
]
|
|
3371
3400
|
});
|
|
3372
|
-
var fileRecordOrder = (request) => codeUnitOrder({
|
|
3373
|
-
left: clauseAddressText({ address: request.left.clause }),
|
|
3374
|
-
right: clauseAddressText({ address: request.right.clause })
|
|
3375
|
-
}) || codeUnitOrder({ left: request.left.file, right: request.right.file });
|
|
3376
3401
|
var clauseWideOrder = (request) => codeUnitOrder({
|
|
3377
3402
|
left: clauseAddressText({ address: request.left.clause }),
|
|
3378
3403
|
right: clauseAddressText({ address: request.right.clause })
|
|
3379
3404
|
});
|
|
3380
|
-
var
|
|
3405
|
+
var fileRecordsOf = (request) => request.records.flatMap((record) => record.kind === "clause-wide-carve-out" ? [] : [record]);
|
|
3406
|
+
var distinctSortedClauses = (request) => [...new Map(request.clauses.map((address) => [clauseAddressText({ address }), address]))].sort(([left], [right]) => codeUnitOrder({ left, right })).map(([, address]) => address);
|
|
3407
|
+
var clausesOfEachFile = (request) => [...Map.groupBy(request.records, (record) => record.file)].map(([file, records]) => {
|
|
3408
|
+
const clauses = distinctSortedClauses({ clauses: records.map((record) => record.clause) });
|
|
3409
|
+
return {
|
|
3410
|
+
file,
|
|
3411
|
+
clauses,
|
|
3412
|
+
clausesText: clauses.map((address) => clauseAddressText({ address })).join(CLAUSE_SEPARATOR)
|
|
3413
|
+
};
|
|
3414
|
+
});
|
|
3415
|
+
var fileRecordGroups = (request) => [...Map.groupBy(clausesOfEachFile({ records: fileRecordsOf(request) }), (fileClauses) => fileClauses.clausesText)].sort(([left], [right]) => codeUnitOrder({ left, right })).map(([clausesText, sharers]) => ({
|
|
3416
|
+
clausesText,
|
|
3417
|
+
clauses: distinctSortedClauses({ clauses: sharers.flatMap((fileClauses) => fileClauses.clauses) }),
|
|
3418
|
+
files: sharers.map((fileClauses) => fileClauses.file).sort((left, right) => codeUnitOrder({ left, right }))
|
|
3419
|
+
}));
|
|
3381
3420
|
var sortedClauseWideRecords = (request) => request.records.flatMap((record) => record.kind === "clause-wide-carve-out" ? [record] : []).sort((left, right) => clauseWideOrder({ left, right }));
|
|
3382
3421
|
var sortedPieces = (request) => [...request.pieces].sort(
|
|
3383
3422
|
(left, right) => codeUnitOrder({ left: left.pluginNamespace, right: right.pluginNamespace })
|
|
@@ -3385,8 +3424,8 @@ var sortedPieces = (request) => [...request.pieces].sort(
|
|
|
3385
3424
|
var importLines = (request) => request.pieces.map((piece, index) => `import piece${index} from ${quoted({ text: piece.pluginImport })};`);
|
|
3386
3425
|
var configBlocks = (request) => [
|
|
3387
3426
|
...request.pieces.map((piece, index) => pieceBlock({ piece, importName: `piece${index}` })),
|
|
3388
|
-
...
|
|
3389
|
-
(
|
|
3427
|
+
...fileRecordGroups({ records: request.records }).map(
|
|
3428
|
+
(group) => fileRecordGroupBlock({ group, pieces: request.pieces })
|
|
3390
3429
|
),
|
|
3391
3430
|
...sortedClauseWideRecords({ records: request.records }).map(
|
|
3392
3431
|
(record) => clauseWideBlock({ record, pieces: request.pieces })
|
|
@@ -3888,7 +3927,7 @@ var messageFindings = (request) => {
|
|
|
3888
3927
|
map: (nativeExceptions) => [{ hits: [], nativeExceptions }]
|
|
3889
3928
|
});
|
|
3890
3929
|
}
|
|
3891
|
-
const clause = request.
|
|
3930
|
+
const clause = request.running.find((entry) => entry.ruleId === request.message.ruleId);
|
|
3892
3931
|
if (clause === void 0) {
|
|
3893
3932
|
return { outcome: "ok", value: [] };
|
|
3894
3933
|
}
|
|
@@ -3907,7 +3946,7 @@ var lintedFindings = (request) => {
|
|
|
3907
3946
|
});
|
|
3908
3947
|
return gatheredOutcomes({
|
|
3909
3948
|
outcomes: request.linted.messages.map(
|
|
3910
|
-
(message) => messageFindings({ message, file: file.value, selected: request.selected, sourceLines })
|
|
3949
|
+
(message) => messageFindings({ message, file: file.value, selected: request.selected, running: request.running, sourceLines })
|
|
3911
3950
|
)
|
|
3912
3951
|
});
|
|
3913
3952
|
};
|
|
@@ -3997,19 +4036,26 @@ var recordsUnderCheck = (request) => request.records.filter(
|
|
|
3997
4036
|
(record) => record.kind === "clause-wide-carve-out" || request.checked.some((checked) => checked.file === record.file)
|
|
3998
4037
|
);
|
|
3999
4038
|
var governedLint = (request) => {
|
|
4000
|
-
if (request.run.files.length === 0 || request.
|
|
4039
|
+
if (request.run.files.length === 0 || request.running.length === 0) {
|
|
4001
4040
|
return Promise.resolve({ outcome: "ok", value: [] });
|
|
4002
4041
|
}
|
|
4003
4042
|
return request.eslint.createGovernanceInstance({
|
|
4004
4043
|
repoRoot: request.run.repoRoot,
|
|
4005
4044
|
plugins: pluginsByNamespace({ selected: request.selected }),
|
|
4006
|
-
rules: governedRulesOf({ selected: request.
|
|
4045
|
+
rules: governedRulesOf({ selected: request.running }),
|
|
4046
|
+
watchedRuleIds: ruleIdsOf({ selected: request.selected })
|
|
4007
4047
|
}).lintFiles({ files: request.run.files });
|
|
4008
4048
|
};
|
|
4009
4049
|
var governedReport = (request) => {
|
|
4010
4050
|
const findings = gatheredOutcomes({
|
|
4011
4051
|
outcomes: request.lintedFiles.map(
|
|
4012
|
-
(linted) => lintedFindings({
|
|
4052
|
+
(linted) => lintedFindings({
|
|
4053
|
+
linted,
|
|
4054
|
+
selected: request.selected,
|
|
4055
|
+
running: request.running,
|
|
4056
|
+
ports: request.ports,
|
|
4057
|
+
repoRoot: request.run.repoRoot
|
|
4058
|
+
})
|
|
4013
4059
|
)
|
|
4014
4060
|
});
|
|
4015
4061
|
if (findings.outcome === "failed") {
|
|
@@ -4038,7 +4084,7 @@ var governedReport = (request) => {
|
|
|
4038
4084
|
}
|
|
4039
4085
|
};
|
|
4040
4086
|
};
|
|
4041
|
-
var lintedReport = (request) => governedLint({ run: request.run, selected: request.selected, eslint: request.ports.eslint }).then(
|
|
4087
|
+
var lintedReport = (request) => governedLint({ run: request.run, selected: request.selected, running: request.running, eslint: request.ports.eslint }).then(
|
|
4042
4088
|
(lintedFiles) => lintedFiles.outcome === "failed" ? lintedFiles : governedReport({ ...request, lintedFiles: lintedFiles.value })
|
|
4043
4089
|
);
|
|
4044
4090
|
var queriedReport = (request) => {
|
|
@@ -4074,6 +4120,9 @@ var presentProjectionState = (request) => projectionState({
|
|
|
4074
4120
|
current: request.current,
|
|
4075
4121
|
generated: generatedProjection({ configured: request.selected, records: request.records })
|
|
4076
4122
|
}) === "current" ? "current" : "out-of-date";
|
|
4123
|
+
var runningClauses = (request) => request.selected.filter(
|
|
4124
|
+
(entry) => request.clauses.some((clause) => sameClauseAddress({ left: clause.address, right: entry.clause.address }) === "same")
|
|
4125
|
+
);
|
|
4077
4126
|
var selectedRun = (request) => {
|
|
4078
4127
|
const current = currentProjection({
|
|
4079
4128
|
fileText: request.ports.fileText,
|
|
@@ -4088,6 +4137,7 @@ var selectedRun = (request) => {
|
|
|
4088
4137
|
}
|
|
4089
4138
|
return governedRun({
|
|
4090
4139
|
...request,
|
|
4140
|
+
running: runningClauses({ selected: request.selected, clauses: request.run.clauses }),
|
|
4091
4141
|
projection: presentProjectionState({
|
|
4092
4142
|
current: current.value,
|
|
4093
4143
|
selected: request.selected,
|
|
@@ -4162,7 +4212,7 @@ var ranClauses = (request) => {
|
|
|
4162
4212
|
return Promise.resolve(origin);
|
|
4163
4213
|
}
|
|
4164
4214
|
return selectedClauses({
|
|
4165
|
-
clauses: request.run.
|
|
4215
|
+
clauses: request.run.projectedClauses,
|
|
4166
4216
|
path: request.ports.path,
|
|
4167
4217
|
origin: origin.value,
|
|
4168
4218
|
modules: request.ports.modules
|
|
@@ -4184,7 +4234,7 @@ var ESLINT_REQUIREMENT = {
|
|
|
4184
4234
|
packageName: "eslint",
|
|
4185
4235
|
peer: "optional",
|
|
4186
4236
|
lines: [
|
|
4187
|
-
{ floor: "9.
|
|
4237
|
+
{ floor: "9.28.0", below: "10.0.0" },
|
|
4188
4238
|
{ floor: "10.0.0", below: "11.0.0" }
|
|
4189
4239
|
]
|
|
4190
4240
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hailstails/hone",
|
|
3
|
-
"version": "0.1.0-pre.
|
|
3
|
+
"version": "0.1.0-pre.5",
|
|
4
4
|
"description": "Checks a repository against the disciplines it selects, applies its recorded exceptions and prints one verdict.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"disciplines",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"./package.json": "./package.json",
|
|
31
31
|
"./audit": {
|
|
32
32
|
"types": "./api/audit.d.ts",
|
|
33
|
-
"default": "./api/audit.
|
|
33
|
+
"default": "./api/audit.mjs"
|
|
34
34
|
},
|
|
35
35
|
"./rule-set": {
|
|
36
36
|
"types": "./api/rule-set.d.ts",
|
|
37
|
-
"default": "./api/rule-set.
|
|
37
|
+
"default": "./api/rule-set.mjs"
|
|
38
38
|
},
|
|
39
39
|
"./mechanisms/eslint/CD-1/cd1/cd1.eslint-plugin.js": "./mechanisms/eslint/CD-1/cd1/cd1.eslint-plugin.js",
|
|
40
40
|
"./mechanisms/eslint/CD-10/cd10/cd10.eslint-plugin.js": "./mechanisms/eslint/CD-10/cd10/cd10.eslint-plugin.js",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"@typescript-eslint/eslint-plugin": "^8.56.0",
|
|
69
69
|
"@typescript-eslint/parser": "^8.56.0",
|
|
70
|
-
"eslint": "^9.
|
|
70
|
+
"eslint": "^9.28.0 || ^10.0.0",
|
|
71
71
|
"typescript": ">=4.8.4 <7.0.0"
|
|
72
72
|
},
|
|
73
73
|
"peerDependenciesMeta": {
|
package/rules/CD-1/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Rule
|
|
4
4
|
|
|
5
|
-
`any` is the absence of a type: it tells the compiler to stop checking, and that hole propagates silently through every call site that consumes the value. The whole reason a type system exists — catching shape errors before runtime — is forfeited at each `any`. Reach for `unknown` and narrow at the read site, or a precise union.
|
|
5
|
+
`any` is the absence of a type: it tells the compiler to stop checking, and that hole propagates silently through every call site that consumes the value. The whole reason a type system exists — catching shape errors before runtime — is forfeited at each `any`. Reach for `unknown` and narrow at the read site, or a precise union. Every `any` is a violation regardless of stated reason: no code form or setting permits one. Debt a repository carries while adopting the rule is held only in exception records.
|
|
6
6
|
|
|
7
7
|
The sections below describe what the audit and ESLint checks cover.
|
|
8
8
|
|
|
@@ -10,7 +10,7 @@ The sections below describe what the audit and ESLint checks cover.
|
|
|
10
10
|
|
|
11
11
|
| Clause | Mechanism | Checks |
|
|
12
12
|
| --- | --- | --- |
|
|
13
|
-
| `CD-1#any-cast` | audit | a type assertion whose
|
|
13
|
+
| `CD-1#any-cast` | audit | a type assertion whose type contains `any` |
|
|
14
14
|
| `CD-1#explicit-any` | eslint | an `any` type anywhere in a type position |
|
|
15
15
|
| `CD-1#implicit-any-let` | eslint | a `let` or `var` with neither a type annotation nor an initialiser |
|
|
16
16
|
|
|
@@ -18,9 +18,9 @@ Review lens: [type-soundness](../../methods/lenses/type-soundness.md). The lens
|
|
|
18
18
|
|
|
19
19
|
## What the check flags
|
|
20
20
|
- `.ts` and `.tsx` files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
21
|
-
- A type assertion (`x as T` or `<T>x`)
|
|
22
|
-
-
|
|
23
|
-
- A
|
|
21
|
+
- A type assertion (`x as T` or `<T>x`) whose type contains the `any` keyword at any depth: `as any`, `<any>x`, `as Array<any>`, `as Record<string, any>`, `as Map<string, any>` or `as { field: any }`. The check reads the syntax tree, so an `any` elsewhere on the line is not attributed to the cast.
|
|
22
|
+
- CD-1 judges these before CD-2 and has no settings; every other assertion is CD-2's.
|
|
23
|
+
- A bare annotation such as `let value: any` is not flagged by this clause; `CD-1#explicit-any` covers it.
|
|
24
24
|
|
|
25
25
|
## What the ESLint check flags
|
|
26
26
|
Needs ESLint adopted through the projection; see [the ESLint piece](../../mechanisms/eslint/CD-1/README.md).
|
|
@@ -37,15 +37,25 @@
|
|
|
37
37
|
"expectedLines": [
|
|
38
38
|
3
|
|
39
39
|
]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "array of any over a property value",
|
|
43
|
+
"fileName": "array-of-any.ts",
|
|
44
|
+
"source": "declare const result: { readonly value: unknown };\nexport const rows = result.value as Array<any>;\n",
|
|
45
|
+
"expectedLines": [
|
|
46
|
+
2
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"name": "record of any",
|
|
51
|
+
"fileName": "record-of-any.ts",
|
|
52
|
+
"source": "declare const candidate: unknown;\nexport const fields = candidate as Record<string, any>;\n",
|
|
53
|
+
"expectedLines": [
|
|
54
|
+
2
|
|
55
|
+
]
|
|
40
56
|
}
|
|
41
57
|
],
|
|
42
58
|
"allow": [
|
|
43
|
-
{
|
|
44
|
-
"name": "as unknown assertion",
|
|
45
|
-
"fileName": "unknown.ts",
|
|
46
|
-
"source": "export const parsed = JSON.parse(text) as unknown;\n",
|
|
47
|
-
"expectedLines": []
|
|
48
|
-
},
|
|
49
59
|
{
|
|
50
60
|
"name": "const assertion",
|
|
51
61
|
"fileName": "const-assertion.ts",
|
package/rules/CD-19/README.md
CHANGED
|
@@ -10,17 +10,27 @@ The sections below describe what the audit check covers.
|
|
|
10
10
|
|
|
11
11
|
| Clause | Mechanism | Checks |
|
|
12
12
|
| --- | --- | --- |
|
|
13
|
-
| `CD-19#import-boundaries` | audit | imports of
|
|
13
|
+
| `CD-19#import-boundaries` | audit | imports of the packages the repository confines, and any `node:` import |
|
|
14
14
|
|
|
15
15
|
Review lens: [function-first](../../methods/lenses/function-first.md). The lens reviews the whole rule, including what no check flags.
|
|
16
16
|
|
|
17
17
|
## What the check flags
|
|
18
18
|
- `.ts` and `.tsx` files, including tests and declaration files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
19
|
-
- A line with `from "<
|
|
19
|
+
- A line with `from "<specifier>"` where the specifier is a package listed in the clause's `confinedPackages` setting (see [Settings](#settings)) or a subpath of one: `hono` covers `hono` and `hono/cors`, and `@scope/name` covers `@scope/name` and `@scope/name/client`. A longer name is a different package, so `hono` does not cover `honox` or `hono-extra`. With no packages listed, which is the default, no library import is flagged. Type-only imports and matches inside strings are flagged too.
|
|
20
20
|
- A `node:` specifier in an import, `export ... from`, `import("node:...")`, `import type`, `import x = require(...)` or `require("node:...")`. Unprefixed `fs` is not detected.
|
|
21
|
-
- The source rule covers every third-party dependency; the check covers only the
|
|
21
|
+
- The source rule covers every third-party dependency; the check covers only the listed packages. The rest is left to review.
|
|
22
|
+
|
|
23
|
+
## Settings
|
|
24
|
+
List each package the repository confines behind a wrapping port in `disciplines.json`, then record each wrapping file as an `authorised-location`:
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
"clauseSettings": {
|
|
28
|
+
"CD-19#import-boundaries": { "confinedPackages": ["winston", "uuid"] }
|
|
29
|
+
}
|
|
30
|
+
```
|
|
22
31
|
|
|
23
32
|
## Example violation
|
|
33
|
+
With `"confinedPackages": ["uuid"]`, both lines are flagged; with the default, only the first.
|
|
24
34
|
```ts
|
|
25
35
|
import { readFileSync } from "node:fs";
|
|
26
36
|
import { v4 } from "uuid";
|
|
@@ -14,14 +14,6 @@
|
|
|
14
14
|
},
|
|
15
15
|
"cases": {
|
|
16
16
|
"flag": [
|
|
17
|
-
{
|
|
18
|
-
"name": "banned library import",
|
|
19
|
-
"fileName": "imports-winston.ts",
|
|
20
|
-
"source": "import winston from \"winston\";\n\nexport const useWinston = (): unknown => winston;\n",
|
|
21
|
-
"expectedLines": [
|
|
22
|
-
1
|
|
23
|
-
]
|
|
24
|
-
},
|
|
25
17
|
{
|
|
26
18
|
"name": "node: import",
|
|
27
19
|
"fileName": "reads-file.ts",
|
|
@@ -40,6 +32,12 @@
|
|
|
40
32
|
}
|
|
41
33
|
],
|
|
42
34
|
"allow": [
|
|
35
|
+
{
|
|
36
|
+
"name": "library import while no specifier is confined",
|
|
37
|
+
"fileName": "imports-winston.ts",
|
|
38
|
+
"source": "import winston from \"winston\";\n\nexport const useWinston = (): unknown => winston;\n",
|
|
39
|
+
"expectedLines": []
|
|
40
|
+
},
|
|
43
41
|
{
|
|
44
42
|
"name": "project-owned import",
|
|
45
43
|
"fileName": "own.ts",
|
package/rules/CD-2/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Rule
|
|
4
4
|
|
|
5
|
-
A type assertion tells the compiler the value is something the compiler cannot see — it is a claim the type system can no longer check. Casting is therefore permitted only at a closed, enumerated list of sites where an external boundary genuinely forces it
|
|
5
|
+
A type assertion tells the compiler the value is something the compiler cannot see — it is a claim the type system can no longer check. Casting is therefore permitted only at a closed, enumerated list of sites where an external boundary genuinely forces it, each one an exception record for the file at that boundary. Everywhere else a cast is a design smell: the type is wrong, so fix the type rather than assert over it. Adding a site to the permitted list is a deliberate, recorded amendment, not an inline decision.
|
|
6
6
|
|
|
7
7
|
The sections below describe what the audit check covers.
|
|
8
8
|
|
|
@@ -16,9 +16,11 @@ Review lens: [type-soundness](../../methods/lenses/type-soundness.md). The lens
|
|
|
16
16
|
|
|
17
17
|
## What the check flags
|
|
18
18
|
- `.ts` and `.tsx` files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
19
|
-
- Every `x as T` and `<T>x` assertion except
|
|
20
|
-
-
|
|
21
|
-
-
|
|
19
|
+
- Every `x as T` and `<T>x` assertion except a const assertion, `as const` or `<const>x`. Assertions whose type contains `any` are CD-1's and are not repeated here.
|
|
20
|
+
- `as unknown` and `<unknown>x` are flagged. Widening never needs an assertion: annotate instead, `const parsed: unknown = JSON.parse(text)`.
|
|
21
|
+
- A cast through `unknown`, such as `raw as unknown as User`, `(<unknown>raw) as User` or one wrapped in `!` or `satisfies`, is flagged with its own message, and so is its `unknown` half. It is the escape hatch that turns any value into any type; check the value's shape at runtime at the boundary instead.
|
|
22
|
+
- Test files, test helpers and scripts are checked like any other source; a test that needs a cast needs a typed fake or a narrower port.
|
|
23
|
+
- There are no settings: a boundary that forces a cast is an exception record, as below.
|
|
22
24
|
|
|
23
25
|
## Example violation
|
|
24
26
|
```ts
|
|
@@ -31,6 +33,8 @@ const user = userSchema.parse(response);
|
|
|
31
33
|
```
|
|
32
34
|
Parse or narrow the value so the type follows from a check rather than from an assertion.
|
|
33
35
|
|
|
36
|
+
When handing a value across a boundary truly forces a cast, such as a library that types its schemas loosely or a database driver that returns unparsed rows, put the cast in the one adapter file at that boundary and record that file as an `authorised-location` with a why-chain. With clean boundaries that is one file and one record; casts scattered across many files are the sign the boundary is missing.
|
|
37
|
+
|
|
34
38
|
## Exceptions
|
|
35
39
|
Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file sits on an external boundary that forces an assertion, such as an adapter. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
|
|
36
40
|
|
|
@@ -37,15 +37,33 @@
|
|
|
37
37
|
"expectedLines": [
|
|
38
38
|
3
|
|
39
39
|
]
|
|
40
|
-
}
|
|
41
|
-
],
|
|
42
|
-
"allow": [
|
|
40
|
+
},
|
|
43
41
|
{
|
|
44
42
|
"name": "as unknown",
|
|
45
43
|
"fileName": "unknown.ts",
|
|
46
44
|
"source": "export const parsed = JSON.parse(text) as unknown;\n",
|
|
47
|
-
"expectedLines": [
|
|
45
|
+
"expectedLines": [
|
|
46
|
+
1
|
|
47
|
+
]
|
|
48
48
|
},
|
|
49
|
+
{
|
|
50
|
+
"name": "double cast through unknown",
|
|
51
|
+
"fileName": "double-cast.ts",
|
|
52
|
+
"source": "interface User { readonly id: string }\ndeclare const raw: string;\nexport const user = raw as unknown as User;\n",
|
|
53
|
+
"expectedLines": [
|
|
54
|
+
3
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"name": "as a name imported from a package",
|
|
59
|
+
"fileName": "package-type-cast.ts",
|
|
60
|
+
"source": "import { z } from \"zod\";\ndeclare const raw: unknown;\nexport const schema = raw as z;\n",
|
|
61
|
+
"expectedLines": [
|
|
62
|
+
3
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
"allow": [
|
|
49
67
|
{
|
|
50
68
|
"name": "as const",
|
|
51
69
|
"fileName": "const-assertion.ts",
|
|
@@ -53,9 +71,9 @@
|
|
|
53
71
|
"expectedLines": []
|
|
54
72
|
},
|
|
55
73
|
{
|
|
56
|
-
"name": "
|
|
57
|
-
"fileName": "
|
|
58
|
-
"source": "
|
|
74
|
+
"name": "angle-bracket const",
|
|
75
|
+
"fileName": "angle-const-assertion.ts",
|
|
76
|
+
"source": "export const PERMITTED_LITERAL = <const>\"permitted\";\n",
|
|
59
77
|
"expectedLines": []
|
|
60
78
|
}
|
|
61
79
|
]
|
package/rules/CD-5/README.md
CHANGED
|
@@ -16,12 +16,24 @@ Review lens: [naming](../../methods/lenses/naming.md). The lens reviews the whol
|
|
|
16
16
|
|
|
17
17
|
## What the check flags
|
|
18
18
|
- `.ts` and `.tsx` files, including tests and declaration files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
19
|
-
- `// TODO` not followed
|
|
20
|
-
- A comment starting with `biome-ignore`, `eslint-disable`, `eslint-enable`, `eslint-disable-line`, `eslint-disable-next-line`, an `oxlint-` equivalent or `eslint <config>`, unless the comment
|
|
21
|
-
-
|
|
22
|
-
-
|
|
19
|
+
- `// TODO` not followed, after optional spaces, by a tracked reference, for example `// TODO(#42) ...`.
|
|
20
|
+
- A comment starting with `biome-ignore`, `eslint-disable`, `eslint-enable`, `eslint-disable-line`, `eslint-disable-next-line`, an `oxlint-` equivalent or `eslint <config>`, unless the comment carries a tracked reference.
|
|
21
|
+
- A TypeScript directive without a tracked reference after it, in each form the compiler honours: `@ts-expect-error` or `@ts-ignore` opening a `//` or `///` comment, or opening the last line of a block comment after any `/` and `*`; and `@ts-nocheck`, in any letter case, opening a `//` or `///` comment among the comments that start the file. As in the compiler, `@ts-ignore` and `@ts-expect-error` are matched as written, so `@ts-ignored` counts and `@Ts-Ignore` does not. Forms the compiler ignores, such as `/* @ts-nocheck */`, a directive above a block comment's closing line, or `////`, are not flagged. `@ts-check` turns checking on and is not flagged.
|
|
22
|
+
- A tracked reference is a parenthesised token with no spaces that contains a digit, such as `(#42)`, `(PROJ-7)`, `(spec-42)` or `(https://tracker.example/issues/42)`. `()`, `(legacy)` and `(issue 42)` are not tracked references.
|
|
23
|
+
- TODO is matched on raw lines, so the same text inside a string is flagged too; linter and type directives are read from comments only.
|
|
23
24
|
- Ordinary explanatory comments and JSDoc are not flagged; keeping them out is left to review.
|
|
24
25
|
|
|
26
|
+
## Settings
|
|
27
|
+
`trackerPatterns` narrows which tracked references count, for example to your own tracker's format. Each entry is a regular expression, as JavaScript source text, tested against each tracked reference with its parentheses; a reference counts when any entry matches. The test is an unanchored search unless the pattern anchors itself with `^` and `$`. The default, `["^\\(\\S+\\)$"]`, lets every tracked reference count.
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
"clauseSettings": {
|
|
31
|
+
"CD-5#comments-directives": { "trackerPatterns": ["^\\(spec-\\d+\\)$", "^\\(#\\d+\\)$"] }
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The patterns only narrow: a reference must still be a parenthesised token with no spaces that contains a digit, so a pattern such as `.*` cannot make `(legacy)` count. The same measure applies to TODO, where the reference must come right after `TODO`. Each entry must be a non-empty string that compiles as a regular expression; otherwise the check stops with a piece-invalid failure naming the clause and the entry.
|
|
36
|
+
|
|
25
37
|
## Example violation
|
|
26
38
|
```ts
|
|
27
39
|
// biome-ignore lint/style/noNonNullAssertion: legacy
|
|
@@ -32,7 +44,7 @@ const first = items[0]!;
|
|
|
32
44
|
```ts
|
|
33
45
|
const first = items[0];
|
|
34
46
|
```
|
|
35
|
-
Remove the need for the directive. If it must stay, add the
|
|
47
|
+
Remove the need for the directive. If it must stay, add the tracked reference: `// biome-ignore lint/style/noNonNullAssertion: legacy (#42)`.
|
|
36
48
|
|
|
37
49
|
## Exceptions
|
|
38
50
|
Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file legitimately carries untracked directives, such as generated code. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
|
|
@@ -37,6 +37,54 @@
|
|
|
37
37
|
"expectedLines": [
|
|
38
38
|
1
|
|
39
39
|
]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "eslint-disable with blank parentheses",
|
|
43
|
+
"fileName": "blank-tracker.ts",
|
|
44
|
+
"source": "// eslint-disable-next-line no-console ( )\nconsole.log(1);\n",
|
|
45
|
+
"expectedLines": [
|
|
46
|
+
1
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"name": "biome-ignore with a word in parentheses",
|
|
51
|
+
"fileName": "word-tracker.ts",
|
|
52
|
+
"source": "// biome-ignore lint/style/noMagicNumbers: literal port (legacy)\nexport const portNumber = 8080;\n",
|
|
53
|
+
"expectedLines": [
|
|
54
|
+
1
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"name": "todo with empty parentheses",
|
|
59
|
+
"fileName": "empty-todo.ts",
|
|
60
|
+
"source": "// TODO() rename this\nexport const someValue = 1;\n",
|
|
61
|
+
"expectedLines": [
|
|
62
|
+
1
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"name": "ts-ignore without tracker",
|
|
67
|
+
"fileName": "ts-ignore.ts",
|
|
68
|
+
"source": "// @ts-ignore\nexport const broken: number = \"text\";\n",
|
|
69
|
+
"expectedLines": [
|
|
70
|
+
1
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"name": "ts-nocheck in a triple-slash comment without tracker",
|
|
75
|
+
"fileName": "ts-nocheck.ts",
|
|
76
|
+
"source": "/// @ts-nocheck\nexport const broken: number = \"text\";\n",
|
|
77
|
+
"expectedLines": [
|
|
78
|
+
1
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"name": "ts-ignore on the last line of a block comment without tracker",
|
|
83
|
+
"fileName": "block-ts-ignore.ts",
|
|
84
|
+
"source": "/*\n * legacy shape\n * @ts-ignore */\nexport const broken: number = \"text\";\n",
|
|
85
|
+
"expectedLines": [
|
|
86
|
+
1
|
|
87
|
+
]
|
|
40
88
|
}
|
|
41
89
|
],
|
|
42
90
|
"allow": [
|
|
@@ -52,6 +100,24 @@
|
|
|
52
100
|
"source": "// biome-ignore lint/style/noMagicNumbers: literal port (spec-7)\nexport const portNumber = 8080;\n",
|
|
53
101
|
"expectedLines": []
|
|
54
102
|
},
|
|
103
|
+
{
|
|
104
|
+
"name": "biome-ignore with issue reference",
|
|
105
|
+
"fileName": "issue-ignore.ts",
|
|
106
|
+
"source": "// biome-ignore lint/style/noMagicNumbers: literal port (#42)\nexport const portNumber = 8080;\n",
|
|
107
|
+
"expectedLines": []
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"name": "ts-expect-error with ticket reference",
|
|
111
|
+
"fileName": "tracked-expect-error.ts",
|
|
112
|
+
"source": "// @ts-expect-error legacy shape (PROJ-7)\nexport const broken: number = \"text\";\n",
|
|
113
|
+
"expectedLines": []
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"name": "ts-nocheck in a block comment, which TypeScript does not honour",
|
|
117
|
+
"fileName": "block-ts-nocheck.ts",
|
|
118
|
+
"source": "/* @ts-nocheck */\nexport const checked: number = 1;\n",
|
|
119
|
+
"expectedLines": []
|
|
120
|
+
},
|
|
55
121
|
{
|
|
56
122
|
"name": "ordinary comment is left to review",
|
|
57
123
|
"fileName": "plain.ts",
|