@yearofthedan/warp 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -7
- package/dist/{analysis → adapters/analysis}/complexity.d.ts +1 -1
- package/dist/adapters/analysis/folders.d.ts +2 -0
- package/dist/{app/facts.d.ts → adapters/analysis/freshFacts.d.ts} +1 -2
- package/dist/{app/facts.js → adapters/analysis/freshFacts.js} +0 -10
- package/dist/{analysis → adapters/analysis}/imports.d.ts +2 -1
- package/dist/{analysis → adapters/analysis}/imports.js +52 -18
- package/dist/{analysis → adapters/analysis}/members.d.ts +1 -1
- package/dist/adapters/analysis/specifiers.d.ts +10 -0
- package/dist/adapters/analysis/specifiers.js +39 -0
- package/dist/adapters/analysis/typescript.d.ts +2 -0
- package/dist/{analysis → adapters/analysis}/typescript.js +10 -4
- package/dist/{config → adapters/config}/loadConfig.d.ts +2 -7
- package/dist/{config → adapters/config}/loadConfig.js +5 -4
- package/dist/{git → adapters/git}/cache.d.ts +1 -1
- package/dist/adapters/git/factsStore.d.ts +2 -0
- package/dist/adapters/git/factsStore.js +10 -0
- package/dist/{git → adapters/git}/repository.d.ts +1 -1
- package/dist/{config → adapters/git}/toolDigest.js +1 -1
- package/dist/{reporters → adapters/reporters}/model.d.ts +2 -2
- package/dist/{reporters → adapters/reporters}/reporter.d.ts +2 -2
- package/dist/{reporters → adapters/reporters}/text.d.ts +2 -2
- package/dist/app/check.d.ts +5 -6
- package/dist/app/check.js +3 -3
- package/dist/app/checkModel.d.ts +5 -5
- package/dist/app/checkModel.js +4 -5
- package/dist/app/configLines.d.ts +1 -1
- package/dist/app/diff.d.ts +1 -1
- package/dist/app/diff.js +1 -1
- package/dist/app/failures.d.ts +6 -0
- package/dist/app/failures.js +15 -0
- package/dist/app/load.d.ts +11 -5
- package/dist/app/load.js +22 -59
- package/dist/app/ports.d.ts +13 -3
- package/dist/builtins/advice.d.ts +4 -4
- package/dist/builtins/advice.js +1 -1
- package/dist/builtins/cognitive-complexity/{cognitiveComplexity.d.ts → rule.d.ts} +1 -1
- package/dist/builtins/cognitive-complexity/{cognitiveComplexity.js → rule.js} +1 -1
- package/dist/builtins/components.d.ts +1 -1
- package/dist/builtins/dependency-direction/rule.d.ts +2 -0
- package/dist/builtins/dependency-direction/{dependencyDirection.js → rule.js} +3 -3
- package/dist/builtins/file-cohesion/{fileCohesion.d.ts → rule.d.ts} +1 -1
- package/dist/builtins/file-cohesion/{fileCohesion.js → rule.js} +1 -1
- package/dist/builtins/function-cohesion/{functionCohesion.d.ts → rule.d.ts} +1 -1
- package/dist/builtins/function-cohesion/{functionCohesion.js → rule.js} +1 -1
- package/dist/builtins/index.d.ts +2 -2
- package/dist/builtins/index.js +18 -13
- package/dist/builtins/loops.d.ts +1 -1
- package/dist/builtins/loops.js +1 -1
- package/dist/builtins/module-cycle/{moduleCycle.d.ts → rule.d.ts} +1 -1
- package/dist/builtins/module-externals/rule.d.ts +2 -0
- package/dist/builtins/module-externals/{moduleExternals.js → rule.js} +3 -3
- package/dist/builtins/no-cross-module-reexport/rule.d.ts +2 -0
- package/dist/builtins/no-cross-module-reexport/{noCrossModuleReexport.js → rule.js} +1 -1
- package/dist/builtins/no-cycle/{noCycle.d.ts → rule.d.ts} +1 -1
- package/dist/builtins/no-double-export/rule.d.ts +2 -0
- package/dist/builtins/no-double-export/{noDoubleExport.js → rule.js} +1 -1
- package/dist/builtins/packages.d.ts +1 -1
- package/dist/builtins/place.d.ts +1 -1
- package/dist/builtins/shared.d.ts +1 -1
- package/dist/builtins/unclassified/rule.d.ts +2 -0
- package/dist/builtins/unclassified/rule.js +15 -0
- package/dist/builtins/unresolved-import/rule.d.ts +2 -0
- package/dist/builtins/unresolved-import/{unresolvedImport.js → rule.js} +1 -1
- package/dist/builtins/unused-declaration/declarations.d.ts +3 -3
- package/dist/builtins/unused-declaration/empty.d.ts +1 -1
- package/dist/builtins/unused-declaration/empty.js +1 -1
- package/dist/builtins/unused-declaration/grants.d.ts +1 -1
- package/dist/builtins/unused-declaration/grants.js +42 -10
- package/dist/builtins/unused-declaration/rule.d.ts +2 -0
- package/dist/builtins/unused-declaration/{unusedDeclaration.js → rule.js} +1 -1
- package/dist/builtins/unused-declaration/surfaces.d.ts +1 -1
- package/dist/builtins/unused-declaration/surfaces.js +1 -1
- package/dist/cli.js +34 -54
- package/dist/{model/archetype → domain/fixes}/fixes.d.ts +2 -2
- package/dist/{model/archetype → domain/fixes}/fixes.js +2 -6
- package/dist/domain/language/compile.d.ts +11 -0
- package/dist/domain/language/compile.js +58 -0
- package/dist/{model/archetype → domain/language}/references.d.ts +3 -6
- package/dist/{model/archetype → domain/language}/references.js +16 -21
- package/dist/{model/archetype → domain/language}/requirements.d.ts +3 -3
- package/dist/{model/archetype → domain/language}/requirements.js +2 -1
- package/dist/domain/language/rulesets.d.ts +10 -0
- package/dist/domain/language/rulesets.js +60 -0
- package/dist/{model/archetype/language.d.ts → domain/language/structure.d.ts} +4 -3
- package/dist/{model/archetype/language.js → domain/language/structure.js} +32 -12
- package/dist/{model/archetype → domain/model}/data.d.ts +9 -6
- package/dist/{model/archetype → domain/model}/reach.d.ts +1 -0
- package/dist/{model/archetype → domain/model}/reach.js +3 -7
- package/dist/{model/archetype → domain/model}/resolve.d.ts +2 -0
- package/dist/{model/archetype → domain/model}/resolve.js +6 -1
- package/dist/{model/archetype → domain/model}/settings.d.ts +0 -1
- package/dist/domain/model/settings.js +82 -0
- package/dist/domain/model/text.d.ts +4 -0
- package/dist/domain/model/text.js +13 -0
- package/dist/{rules → domain/rules}/registry.d.ts +1 -0
- package/dist/{rules → domain/rules}/registry.js +10 -0
- package/dist/{rules → domain/rules}/rule.d.ts +10 -4
- package/dist/index.d.ts +6 -6
- package/dist/index.js +2 -2
- package/package.json +1 -1
- package/dist/analysis/folders.d.ts +0 -2
- package/dist/analysis/specifiers.d.ts +0 -2
- package/dist/analysis/specifiers.js +0 -6
- package/dist/analysis/typescript.d.ts +0 -2
- package/dist/app/unclassified.d.ts +0 -5
- package/dist/app/unclassified.js +0 -13
- package/dist/builtins/dependency-direction/dependencyDirection.d.ts +0 -2
- package/dist/builtins/module-externals/moduleExternals.d.ts +0 -2
- package/dist/builtins/no-cross-module-reexport/noCrossModuleReexport.d.ts +0 -2
- package/dist/builtins/no-double-export/noDoubleExport.d.ts +0 -2
- package/dist/builtins/unresolved-import/unresolvedImport.d.ts +0 -2
- package/dist/builtins/unused-declaration/unusedDeclaration.d.ts +0 -2
- package/dist/model/archetype/rulesets.d.ts +0 -5
- package/dist/model/archetype/rulesets.js +0 -139
- package/dist/model/archetype/settings.js +0 -54
- /package/dist/{analysis → adapters/analysis}/complexity.js +0 -0
- /package/dist/{analysis → adapters/analysis}/folders.js +0 -0
- /package/dist/{analysis → adapters/analysis}/members.js +0 -0
- /package/dist/{analysis → adapters/analysis}/source.d.ts +0 -0
- /package/dist/{analysis → adapters/analysis}/source.js +0 -0
- /package/dist/{git → adapters/git}/cache.js +0 -0
- /package/dist/{git → adapters/git}/repository.js +0 -0
- /package/dist/{config → adapters/git}/toolDigest.d.ts +0 -0
- /package/dist/{reporters → adapters/reporters}/agent.d.ts +0 -0
- /package/dist/{reporters → adapters/reporters}/agent.js +0 -0
- /package/dist/{reporters → adapters/reporters}/claudeHook.d.ts +0 -0
- /package/dist/{reporters → adapters/reporters}/claudeHook.js +0 -0
- /package/dist/{reporters → adapters/reporters}/index.d.ts +0 -0
- /package/dist/{reporters → adapters/reporters}/index.js +0 -0
- /package/dist/{reporters → adapters/reporters}/json.d.ts +0 -0
- /package/dist/{reporters → adapters/reporters}/json.js +0 -0
- /package/dist/{reporters → adapters/reporters}/model.js +0 -0
- /package/dist/{reporters → adapters/reporters}/omp.d.ts +0 -0
- /package/dist/{reporters → adapters/reporters}/omp.js +0 -0
- /package/dist/{reporters → adapters/reporters}/reporter.js +0 -0
- /package/dist/{reporters → adapters/reporters}/sarif.d.ts +0 -0
- /package/dist/{reporters → adapters/reporters}/sarif.js +0 -0
- /package/dist/{reporters → adapters/reporters}/text.js +0 -0
- /package/dist/builtins/module-cycle/{moduleCycle.js → rule.js} +0 -0
- /package/dist/builtins/no-cycle/{noCycle.js → rule.js} +0 -0
- /package/dist/{model → domain/facts}/facts.d.ts +0 -0
- /package/dist/{model → domain/facts}/facts.js +0 -0
- /package/dist/{model → domain/model}/configError.d.ts +0 -0
- /package/dist/{model → domain/model}/configError.js +0 -0
- /package/dist/{model/archetype → domain/model}/data.js +0 -0
- /package/dist/{model/archetype → domain/model}/shared.d.ts +0 -0
- /package/dist/{model/archetype → domain/model}/shared.js +0 -0
- /package/dist/{rules → domain/rules}/diff.d.ts +0 -0
- /package/dist/{rules → domain/rules}/diff.js +0 -0
- /package/dist/{rules → domain/rules}/rule.js +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { show } from './
|
|
2
|
-
import { declarationOf, fillPattern, globRegex } from './resolve.js';
|
|
1
|
+
import { show } from './text.js';
|
|
2
|
+
import { ancestors, declarationOf, fillPattern, globRegex, subtree } from './resolve.js';
|
|
3
3
|
export const grantText = ({ owner, ref }) => (ref === undefined ? owner : `${owner} uses ${ref}`);
|
|
4
4
|
const none = new Set();
|
|
5
5
|
const union = (sets) => {
|
|
@@ -9,14 +9,11 @@ const union = (sets) => {
|
|
|
9
9
|
all.add(file);
|
|
10
10
|
return all;
|
|
11
11
|
};
|
|
12
|
-
const ancestors = function* (module) {
|
|
13
|
-
for (let at = module.parent; at; at = at.parent)
|
|
14
|
-
yield at;
|
|
15
|
-
};
|
|
16
12
|
export const verdicts = (config, model) => {
|
|
17
13
|
const state = { config, model, surfaces: new Map(), reaches: new Map() };
|
|
18
14
|
return {
|
|
19
15
|
reach: (file) => reach(state, file),
|
|
16
|
+
grants: (module, view = 'production') => using(state, module, view),
|
|
20
17
|
exposes: (module) => exposes(state, module),
|
|
21
18
|
surface: (module, name, view = 'production') => surface(state, module, name, view),
|
|
22
19
|
verdict: (from, to) => verdict(state, from, to),
|
|
@@ -194,7 +191,6 @@ const filesTests = (state, module, of) => {
|
|
|
194
191
|
...[holder, ...ancestors(holder)].flatMap((at) => testKit(state, at)),
|
|
195
192
|
];
|
|
196
193
|
};
|
|
197
|
-
const subtree = (module) => [module, ...module.children.flatMap(subtree)];
|
|
198
194
|
const testKit = (state, at) => grants(state, at, `${at.archetype}.test.provides`, state.config.archetypes[at.archetype].testUsing ?? [], 'test');
|
|
199
195
|
const using = (state, module, view) => {
|
|
200
196
|
const declared = declarationOf(state.config, module);
|
|
@@ -28,3 +28,5 @@ export declare const fillPattern: (pattern: string, captures: Record<string, str
|
|
|
28
28
|
export declare const resolveModel: (config: ConfigData, folders: Folders, files: readonly string[]) => Model;
|
|
29
29
|
export declare const specificity: (pattern: string) => number;
|
|
30
30
|
export declare const globRegex: (pattern: string) => RegExp;
|
|
31
|
+
export declare const ancestors: (module: ModuleView) => Generator<ModuleView>;
|
|
32
|
+
export declare const subtree: (module: ModuleView) => ModuleView[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConfigError } from '
|
|
1
|
+
import { ConfigError } from './configError.js';
|
|
2
2
|
export const declarationOf = (config, module) => module.parent && config.archetypes[module.parent.archetype].modules.find((data) => data.name === module.name);
|
|
3
3
|
export const rootId = '(root)';
|
|
4
4
|
const placeholders = /\{(\w+)\}/g;
|
|
@@ -301,3 +301,8 @@ export const globRegex = (pattern) => {
|
|
|
301
301
|
globCache.set(pattern, regex);
|
|
302
302
|
return regex;
|
|
303
303
|
};
|
|
304
|
+
export const ancestors = function* (module) {
|
|
305
|
+
for (let at = module.parent; at; at = at.parent)
|
|
306
|
+
yield at;
|
|
307
|
+
};
|
|
308
|
+
export const subtree = (module) => [module, ...module.children.flatMap(subtree)];
|
|
@@ -7,7 +7,6 @@ export interface RuleAt {
|
|
|
7
7
|
export interface Settings {
|
|
8
8
|
atFile(file: string, id: string, defaults?: object): RuleAt;
|
|
9
9
|
atModule(module: ModuleView, id: string, defaults?: object): RuleAt;
|
|
10
|
-
decidedAt(module: ModuleView, id: string): boolean | undefined;
|
|
11
10
|
}
|
|
12
11
|
export declare const settings: (config: ConfigData, model: Model) => Settings;
|
|
13
12
|
export type ResolvedRules = Record<string, false | Record<string, unknown>>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { declarationOf } from './resolve.js';
|
|
2
|
+
import { isRecord } from './shared.js';
|
|
3
|
+
const archetypeOf = (config, module) => module.archetype === undefined ? undefined : config.archetypes[module.archetype];
|
|
4
|
+
const own = (config, module) => [
|
|
5
|
+
archetypeOf(config, module)?.ruleset,
|
|
6
|
+
declarationOf(config, module)?.ruleset,
|
|
7
|
+
];
|
|
8
|
+
const ownTests = (config, module) => [
|
|
9
|
+
archetypeOf(config, module)?.testRuleset,
|
|
10
|
+
declarationOf(config, module)?.testRuleset,
|
|
11
|
+
];
|
|
12
|
+
const production = (config, module) => [
|
|
13
|
+
...(module.parent ? production(config, module.parent) : []),
|
|
14
|
+
...own(config, module),
|
|
15
|
+
];
|
|
16
|
+
const tests = (config, module) => [
|
|
17
|
+
...(module.parent ? tests(config, module.parent) : []),
|
|
18
|
+
...ownTests(config, module),
|
|
19
|
+
];
|
|
20
|
+
const filesModuleOf = (config, holder, test) => {
|
|
21
|
+
const of = declarationOf(config, test)?.of;
|
|
22
|
+
return of === undefined ? undefined : archetypeOf(config, holder).modules.find((module) => module.name === of);
|
|
23
|
+
};
|
|
24
|
+
const layersOf = (config, module) => {
|
|
25
|
+
if (!module.test)
|
|
26
|
+
return production(config, module);
|
|
27
|
+
const chain = [];
|
|
28
|
+
let holder = module;
|
|
29
|
+
for (; holder.test && holder.parent; holder = holder.parent)
|
|
30
|
+
chain.unshift(holder);
|
|
31
|
+
const files = filesModuleOf(config, holder, chain[0]);
|
|
32
|
+
return [
|
|
33
|
+
...production(config, holder),
|
|
34
|
+
files?.ruleset,
|
|
35
|
+
...tests(config, holder),
|
|
36
|
+
files?.testRuleset,
|
|
37
|
+
...chain.flatMap((test) => own(config, test)),
|
|
38
|
+
];
|
|
39
|
+
};
|
|
40
|
+
const ruleAt = (layers, id, defaults = {}) => {
|
|
41
|
+
const at = { on: false, options: { ...defaults } };
|
|
42
|
+
for (const layer of layers) {
|
|
43
|
+
const setting = Object.hasOwn(layer, id) ? layer[id] : layer['*'];
|
|
44
|
+
if (setting === undefined)
|
|
45
|
+
continue;
|
|
46
|
+
at.on = setting !== false;
|
|
47
|
+
if (isRecord(setting))
|
|
48
|
+
Object.assign(at.options, setting);
|
|
49
|
+
}
|
|
50
|
+
return at;
|
|
51
|
+
};
|
|
52
|
+
export const settings = (config, model) => {
|
|
53
|
+
const cache = new Map();
|
|
54
|
+
const at = (module) => {
|
|
55
|
+
if (!module)
|
|
56
|
+
return [];
|
|
57
|
+
let found = cache.get(module);
|
|
58
|
+
if (!found)
|
|
59
|
+
cache.set(module, (found = layersOf(config, module).flatMap((ruleset) => ruleset ?? [])));
|
|
60
|
+
return found;
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
atFile: (file, id, defaults) => ruleAt(at(model.moduleOf(file)), id, defaults),
|
|
64
|
+
atModule: (module, id, defaults) => ruleAt(at(module), id, defaults),
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
export const rulesOf = (config, model, rules) => {
|
|
68
|
+
const settled = settings(config, model);
|
|
69
|
+
return {
|
|
70
|
+
defaults: Object.fromEntries(rules.map(({ id, defaults }) => [id, { ...defaults }])),
|
|
71
|
+
module: (module) => Object.fromEntries(rules.map(({ id, defaults }) => {
|
|
72
|
+
const { on, options } = settled.atModule(module, id, defaults);
|
|
73
|
+
return [id, on ? options : false];
|
|
74
|
+
})),
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
const turnsOn = (ruleset) => ruleset !== undefined && ruleset.some((layer) => Object.values(layer).some((setting) => setting !== false));
|
|
78
|
+
const rulesetsOf = (place) => [
|
|
79
|
+
place.ruleset,
|
|
80
|
+
'testRuleset' in place ? place.testRuleset : undefined,
|
|
81
|
+
];
|
|
82
|
+
export const anyRuleOn = (config) => Object.values(config.archetypes).some((archetype) => [archetype, ...archetype.modules].flatMap(rulesetsOf).some(turnsOn));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const packageText = (pattern) => pattern.startsWith('node:') || pattern.startsWith('virtual:') ? pattern : `npm:${pattern}`;
|
|
2
|
+
export const show = (ref) => ref.kind === 'package'
|
|
3
|
+
? packageText(ref.pattern)
|
|
4
|
+
: `${ref.kind === 'module' && ref.top ? 'top.' : ''}${ref.kind === 'required' ? ref.name : ref.module}${ref.surface === undefined ? '' : `.${ref.surface}`}`;
|
|
5
|
+
export const exposesText = (exposes) => {
|
|
6
|
+
if (exposes === undefined)
|
|
7
|
+
return 'nothing';
|
|
8
|
+
if (exposes.kind === 'all')
|
|
9
|
+
return 'all its files';
|
|
10
|
+
if (exposes.kind === 'files')
|
|
11
|
+
return `{ files: [${exposes.patterns.join(', ')}] }`;
|
|
12
|
+
return Object.keys(exposes.surfaces).join(', ');
|
|
13
|
+
};
|
|
@@ -2,4 +2,5 @@ import type { Rule } from './rule.ts';
|
|
|
2
2
|
export declare const registry: <R extends {
|
|
3
3
|
id: string;
|
|
4
4
|
}>(rules: readonly R[]) => ReadonlyMap<string, R>;
|
|
5
|
+
export declare const pluginRulesets: (plugins: Record<string, unknown>) => Record<string, unknown>;
|
|
5
6
|
export declare const pluginRules: (plugins: Record<string, unknown>) => Rule[];
|
|
@@ -9,10 +9,20 @@ export const registry = (rules) => {
|
|
|
9
9
|
return byId;
|
|
10
10
|
};
|
|
11
11
|
const name = /^[a-z][a-z0-9-]*$/;
|
|
12
|
+
export const pluginRulesets = (plugins) => Object.fromEntries(Object.entries(plugins).flatMap(([namespace, plugin]) => {
|
|
13
|
+
const rulesets = plugin.rulesets;
|
|
14
|
+
if (rulesets === undefined)
|
|
15
|
+
return [];
|
|
16
|
+
if (typeof rulesets !== 'object' || rulesets === null || Array.isArray(rulesets))
|
|
17
|
+
throw new ConfigError(`plugins.${namespace}: expected rulesets by name, { recommended: { rules: {...} } }`);
|
|
18
|
+
return Object.entries(rulesets).map(([ruleset, definition]) => [`${namespace}:${ruleset}`, definition]);
|
|
19
|
+
}));
|
|
12
20
|
export const pluginRules = (plugins) => Object.entries(plugins).flatMap(([namespace, plugin]) => namespaced(namespace, plugin, `plugins.${namespace}`));
|
|
13
21
|
const namespaced = (namespace, plugin, at) => {
|
|
14
22
|
if (!name.test(namespace))
|
|
15
23
|
throw new ConfigError(`${at}: a namespace is lowercase letters, digits and dashes`);
|
|
24
|
+
if (namespace === 'warp')
|
|
25
|
+
throw new ConfigError(`${at}: warp is the namespace of warp's own rulesets; name it otherwise`);
|
|
16
26
|
const rules = typeof plugin === 'object' && plugin !== null ? plugin.rules : undefined;
|
|
17
27
|
if (!Array.isArray(rules))
|
|
18
28
|
throw new ConfigError(`${at}: expected a plugin, { rules: Rule[] }, as the default export of its file`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ConfigData } from '../model/
|
|
2
|
-
import type { Verdicts } from '../model/
|
|
3
|
-
import type { Model, ModuleView } from '../model/
|
|
4
|
-
import type { FileFacts, Project } from '../
|
|
1
|
+
import type { ConfigData } from '../model/data.ts';
|
|
2
|
+
import type { Verdicts } from '../model/reach.ts';
|
|
3
|
+
import type { Model, ModuleView } from '../model/resolve.ts';
|
|
4
|
+
import type { FileFacts, Project } from '../facts/facts.ts';
|
|
5
5
|
export interface Site {
|
|
6
6
|
file: string;
|
|
7
7
|
line: number;
|
|
@@ -51,8 +51,14 @@ export interface ProjectRule<Options extends object = object> extends RuleBase<O
|
|
|
51
51
|
check: (context: ProjectContext<Options>) => Finding[];
|
|
52
52
|
}
|
|
53
53
|
export type Rule = FileRule<any> | ProjectRule<any>;
|
|
54
|
+
export type RuleSetting = 'on' | 'off' | boolean | Record<string, unknown>;
|
|
55
|
+
export interface RulesetDefinition {
|
|
56
|
+
extends?: readonly string[];
|
|
57
|
+
rules?: Readonly<Record<string, RuleSetting>>;
|
|
58
|
+
}
|
|
54
59
|
export interface Plugin {
|
|
55
60
|
rules: readonly Rule[];
|
|
61
|
+
rulesets?: Readonly<Record<string, RulesetDefinition>>;
|
|
56
62
|
}
|
|
57
63
|
export declare const noOptions: (raw: Record<string, unknown>, at: string) => Partial<object>;
|
|
58
64
|
export declare const wholeNumberOptions: <Options extends Record<string, number>>(defaults: Options) => (raw: Record<string, unknown>, at: string) => Partial<Options>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { loadConfigData, type LoadedConfigData } from './app/load.ts';
|
|
2
|
-
export type * from './model/
|
|
3
|
-
export type { Complexity, FunctionFacts, ImportEdge, FileFacts, Member, MemberGraph, MemberKind, } from './
|
|
4
|
-
export type { Model, ModuleView } from './model/
|
|
5
|
-
export type { Grant, Refusal, Verdict, Verdicts } from './model/
|
|
6
|
-
export { ConfigError } from './model/configError.ts';
|
|
7
|
-
export { type Finding, type FileContext, type FileRule, type Plugin, type ProjectContext, type ProjectRule, type Rule, type Setting, wholeNumberOptions, } from './rules/rule.ts';
|
|
2
|
+
export type * from './domain/model/data.ts';
|
|
3
|
+
export type { Complexity, FunctionFacts, ImportEdge, FileFacts, Member, MemberGraph, MemberKind, } from './domain/facts/facts.ts';
|
|
4
|
+
export type { Model, ModuleView } from './domain/model/resolve.ts';
|
|
5
|
+
export type { Grant, Refusal, Verdict, Verdicts } from './domain/model/reach.ts';
|
|
6
|
+
export { ConfigError } from './domain/model/configError.ts';
|
|
7
|
+
export { type Finding, type FileContext, type FileRule, type Plugin, type RuleSetting, type RulesetDefinition, type ProjectContext, type ProjectRule, type Rule, type Setting, wholeNumberOptions, } from './domain/rules/rule.ts';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { loadConfigData } from './app/load.js';
|
|
2
|
-
export { ConfigError } from './model/configError.js';
|
|
3
|
-
export { wholeNumberOptions, } from './rules/rule.js';
|
|
2
|
+
export { ConfigError } from './domain/model/configError.js';
|
|
3
|
+
export { wholeNumberOptions, } from './domain/rules/rule.js';
|
package/package.json
CHANGED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { isExportDeclaration, isImportDeclaration, isStringLiteralLikeNode } from 'typescript/ast/is';
|
|
2
|
-
export const moduleSpecifiers = (sourceFile) => sourceFile.statements.flatMap((statement) => (isImportDeclaration(statement) || isExportDeclaration(statement)) &&
|
|
3
|
-
statement.moduleSpecifier &&
|
|
4
|
-
isStringLiteralLikeNode(statement.moduleSpecifier)
|
|
5
|
-
? [statement.moduleSpecifier.text]
|
|
6
|
-
: []);
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { Finding } from '../rules/rule.ts';
|
|
2
|
-
import type { Model } from '../model/archetype/resolve.ts';
|
|
3
|
-
import type { Settings } from '../model/archetype/settings.ts';
|
|
4
|
-
export declare const unclassified = "unclassified";
|
|
5
|
-
export declare const unclassifiedFindings: (model: Model, settled: Settings, docs: string | undefined) => Finding[];
|
package/dist/app/unclassified.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export const unclassified = 'unclassified';
|
|
2
|
-
export const unclassifiedFindings = (model, settled, docs) => model.modules.flatMap((module) => (settled.decidedAt(module, unclassified) ?? module.parent === undefined)
|
|
3
|
-
? module.looseFiles.map((file) => ({
|
|
4
|
-
rule: unclassified,
|
|
5
|
-
key: `${unclassified}:${file}`,
|
|
6
|
-
file,
|
|
7
|
-
line: 1,
|
|
8
|
-
value: 1,
|
|
9
|
-
message: `${file} is in no module of ${module.parent ? `${module.id} (${module.archetype})` : 'the root'}, so nothing says what it may import. ` +
|
|
10
|
-
`Add a files module to ${module.archetype} that matches it, or move it into a module's folder.`,
|
|
11
|
-
...(docs ? { docs } : {}),
|
|
12
|
-
}))
|
|
13
|
-
: []);
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { type ConfigData, type RuleSettingsData } from './data.ts';
|
|
2
|
-
import { type Fail } from './shared.ts';
|
|
3
|
-
export type ParseRules = (value: unknown, at: string) => RuleSettingsData | undefined;
|
|
4
|
-
export declare const withRuleset: (config: ConfigData, rulesets: unknown, name: string | undefined, parse: ParseRules, fail: Fail) => ConfigData;
|
|
5
|
-
export declare const recommended = "warp:recommended";
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { ConfigError } from '../configError.js';
|
|
2
|
-
import { isTestData } from './data.js';
|
|
3
|
-
import { isRecord, list } from './shared.js';
|
|
4
|
-
export const withRuleset = (config, rulesets, name, parse, fail) => {
|
|
5
|
-
const named = rulesetsOf(rulesets, fail);
|
|
6
|
-
if (name !== undefined && !named.has(name)) {
|
|
7
|
-
const names = [...named.keys()];
|
|
8
|
-
throw new ConfigError(`rulesets: no ruleset called ${name}. ${names.length > 0 ? `Rulesets: ${names.join(', ')}` : 'The config declares none'}`);
|
|
9
|
-
}
|
|
10
|
-
const chosen = name ?? 'default';
|
|
11
|
-
if (!named.has(chosen))
|
|
12
|
-
return applied(config, [{ settings: 'off', at: 'rulesets' }], parse, fail);
|
|
13
|
-
const { layers, recommends } = layersOf(config, chosen, named, fail);
|
|
14
|
-
const base = recommends ? [] : [{ settings: 'off', at: `rulesets.${chosen}` }];
|
|
15
|
-
return applied(config, [...base, ...layers], parse, fail);
|
|
16
|
-
};
|
|
17
|
-
export const recommended = 'warp:recommended';
|
|
18
|
-
const rulesetKeys = ['extends', 'rules', 'test', 'on'];
|
|
19
|
-
const rulesetsOf = (value, fail) => {
|
|
20
|
-
const named = new Map();
|
|
21
|
-
if (value === undefined)
|
|
22
|
-
return named;
|
|
23
|
-
if (!isRecord(value)) {
|
|
24
|
-
fail('rulesets: expected rulesets by name, { default: { extends: [warp:recommended] } }');
|
|
25
|
-
return named;
|
|
26
|
-
}
|
|
27
|
-
for (const [name, ruleset] of Object.entries(value)) {
|
|
28
|
-
if (!isRecord(ruleset)) {
|
|
29
|
-
fail(`rulesets.${name}: expected a ruleset, { extends: [warp:recommended], rules: {...} }`);
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
for (const key of Object.keys(ruleset).filter((key) => !rulesetKeys.includes(key)))
|
|
33
|
-
fail(`rulesets.${name}: unknown key ${key}; a ruleset takes ${rulesetKeys.join(', ')}`);
|
|
34
|
-
named.set(name, ruleset);
|
|
35
|
-
}
|
|
36
|
-
return named;
|
|
37
|
-
};
|
|
38
|
-
const layersOf = (config, name, named, fail, seen = []) => {
|
|
39
|
-
const ruleset = named.get(name);
|
|
40
|
-
const at = `rulesets.${name}`;
|
|
41
|
-
const inherited = basesOf(config, name, named, fail, seen);
|
|
42
|
-
const layers = [...inherited.layers];
|
|
43
|
-
if (ruleset.rules !== undefined)
|
|
44
|
-
layers.push({ settings: ruleset.rules, at: `${at}.rules` });
|
|
45
|
-
if (ruleset.test !== undefined)
|
|
46
|
-
for (const target of testTargets(config))
|
|
47
|
-
layers.push({ target, settings: ruleset.test, at: `${at}.test` });
|
|
48
|
-
if (ruleset.on !== undefined)
|
|
49
|
-
layers.push(...onLayers(config, at, ruleset.on, fail));
|
|
50
|
-
return { layers, recommends: inherited.recommends };
|
|
51
|
-
};
|
|
52
|
-
const basesOf = (config, name, named, fail, seen) => {
|
|
53
|
-
const at = `rulesets.${name}`;
|
|
54
|
-
const declared = named.get(name).extends;
|
|
55
|
-
const bases = declared === undefined ? [] : [declared].flat();
|
|
56
|
-
const found = { layers: [], recommends: false };
|
|
57
|
-
for (const base of bases) {
|
|
58
|
-
if (base === recommended)
|
|
59
|
-
found.recommends = true;
|
|
60
|
-
else if (typeof base !== 'string' || !named.has(base))
|
|
61
|
-
fail(`${at}.extends: '${String(base)}' is no ruleset; extend ${list([recommended, ...named.keys()], 'nothing')}`);
|
|
62
|
-
else if (seen.includes(base))
|
|
63
|
-
fail(`${at}.extends: ${[...seen, name, base].join(' extends ')}, a loop`);
|
|
64
|
-
else {
|
|
65
|
-
const extended = layersOf(config, base, named, fail, [...seen, name]);
|
|
66
|
-
found.layers.push(...extended.layers);
|
|
67
|
-
found.recommends ||= extended.recommends;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return found;
|
|
71
|
-
};
|
|
72
|
-
const onLayers = (config, at, on, fail) => {
|
|
73
|
-
if (!isRecord(on)) {
|
|
74
|
-
fail(`${at}.on: expected settings by archetype or module, { app.adapters: {...} }`);
|
|
75
|
-
return [];
|
|
76
|
-
}
|
|
77
|
-
return Object.entries(on).flatMap(([path, settings]) => {
|
|
78
|
-
const target = targetOf(config, path);
|
|
79
|
-
if (target)
|
|
80
|
-
return [{ target, settings, at: `${at}.on.${path}` }];
|
|
81
|
-
fail(`${at}.on.${path}: no archetype or module called ${path}; name an archetype, or archetype.module`);
|
|
82
|
-
return [];
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
const testTargets = (config) => Object.values(config.archetypes).flatMap((archetype) => archetype.modules.filter(isTestData).map((module) => ({ archetype: archetype.name, module: module.name })));
|
|
86
|
-
const targetOf = (config, path) => {
|
|
87
|
-
if (config.archetypes[path])
|
|
88
|
-
return { archetype: path };
|
|
89
|
-
for (let at = path.lastIndexOf('.'); at > 0; at = path.lastIndexOf('.', at - 1)) {
|
|
90
|
-
const archetype = config.archetypes[path.slice(0, at)];
|
|
91
|
-
const module = path.slice(at + 1);
|
|
92
|
-
if (archetype?.modules.some((declared) => declared.name === module))
|
|
93
|
-
return { archetype: archetype.name, module };
|
|
94
|
-
}
|
|
95
|
-
return undefined;
|
|
96
|
-
};
|
|
97
|
-
const applied = (config, layers, parse, fail) => {
|
|
98
|
-
let rules = config.rules;
|
|
99
|
-
const archetypes = Object.fromEntries(Object.entries(config.archetypes).map(([name, data]) => [name, { ...data, modules: [...data.modules] }]));
|
|
100
|
-
for (const { target, settings, at } of layers) {
|
|
101
|
-
const layer = parse(settings, at);
|
|
102
|
-
if (!target) {
|
|
103
|
-
rules = merged(rules, layer);
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
const archetype = archetypes[target.archetype];
|
|
107
|
-
if (!archetype) {
|
|
108
|
-
fail(`${at}: ${target.archetype} is not in the config`);
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
applyTo(archetype, target.module, layer, at, fail);
|
|
112
|
-
}
|
|
113
|
-
return rules === undefined ? { ...config, archetypes } : { ...config, archetypes, rules };
|
|
114
|
-
};
|
|
115
|
-
const applyTo = (archetype, module, layer, at, fail) => {
|
|
116
|
-
if (module === undefined) {
|
|
117
|
-
archetype.rules = merged(archetype.rules, layer);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
const index = archetype.modules.findIndex((declared) => declared.name === module);
|
|
121
|
-
if (index < 0)
|
|
122
|
-
fail(`${at}: ${archetype.name} has modules ${list(archetype.modules.map((declared) => declared.name), 'none')}`);
|
|
123
|
-
else
|
|
124
|
-
archetype.modules[index] = { ...archetype.modules[index], rules: merged(archetype.modules[index].rules, layer) };
|
|
125
|
-
};
|
|
126
|
-
const merged = (base, layer) => {
|
|
127
|
-
if (layer === undefined)
|
|
128
|
-
return base;
|
|
129
|
-
if (layer === 'off')
|
|
130
|
-
return 'off';
|
|
131
|
-
const result = base === 'off' ? { '*': false } : { ...base };
|
|
132
|
-
for (const [id, setting] of Object.entries(layer)) {
|
|
133
|
-
const was = result[id];
|
|
134
|
-
if (setting === true && isRecord(was))
|
|
135
|
-
continue;
|
|
136
|
-
result[id] = isRecord(setting) && isRecord(was) ? { ...was, ...setting } : setting;
|
|
137
|
-
}
|
|
138
|
-
return result;
|
|
139
|
-
};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { declarationOf } from './resolve.js';
|
|
2
|
-
import { isRecord } from './shared.js';
|
|
3
|
-
const own = (config, module) => [
|
|
4
|
-
declarationOf(config, module)?.rules,
|
|
5
|
-
module.archetype === undefined ? undefined : config.archetypes[module.archetype].rules,
|
|
6
|
-
];
|
|
7
|
-
const levels = (config, module) => [
|
|
8
|
-
...own(config, module),
|
|
9
|
-
...(module.parent ? levels(config, module.parent) : [config.rules]),
|
|
10
|
-
];
|
|
11
|
-
export const settings = (config, model) => {
|
|
12
|
-
const fileLevels = (file) => {
|
|
13
|
-
const module = model.moduleOf(file);
|
|
14
|
-
return module ? levels(config, module) : [config.rules];
|
|
15
|
-
};
|
|
16
|
-
return {
|
|
17
|
-
atFile: (file, id, defaults) => ruleAt(fileLevels(file), id, defaults),
|
|
18
|
-
atModule: (module, id, defaults) => ruleAt(levels(config, module), id, defaults),
|
|
19
|
-
decidedAt: (module, id) => decided(levels(config, module), id),
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
const decision = (level, id) => {
|
|
23
|
-
if (level === undefined)
|
|
24
|
-
return undefined;
|
|
25
|
-
if (level === 'off')
|
|
26
|
-
return false;
|
|
27
|
-
if (Object.hasOwn(level, id))
|
|
28
|
-
return level[id] !== false;
|
|
29
|
-
return level['*'];
|
|
30
|
-
};
|
|
31
|
-
const optionsAt = (level, id) => {
|
|
32
|
-
const setting = typeof level === 'object' ? level[id] : undefined;
|
|
33
|
-
return isRecord(setting) ? setting : undefined;
|
|
34
|
-
};
|
|
35
|
-
const decided = (levels, id) => levels.map((level) => decision(level, id)).find((said) => said !== undefined);
|
|
36
|
-
const ruleAt = (levels, id, defaults = {}) => ({
|
|
37
|
-
on: decided(levels, id) ?? true,
|
|
38
|
-
options: Object.assign({}, defaults, ...levels.map((level) => optionsAt(level, id)).reverse()),
|
|
39
|
-
});
|
|
40
|
-
export const rulesOf = (config, model, rules) => {
|
|
41
|
-
const settled = settings(config, model);
|
|
42
|
-
return {
|
|
43
|
-
defaults: Object.fromEntries(rules.map(({ id, defaults }) => [id, { ...defaults }])),
|
|
44
|
-
module: (module) => Object.fromEntries(rules.map(({ id, defaults }) => {
|
|
45
|
-
const { on, options } = settled.atModule(module, id, defaults);
|
|
46
|
-
return [id, on ? options : false];
|
|
47
|
-
})),
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
const turnsOn = (rules) => rules !== undefined && rules !== 'off' && Object.values(rules).some((setting) => setting !== false);
|
|
51
|
-
export const anyRuleOn = (config) => config.rules === undefined ||
|
|
52
|
-
(config.rules !== 'off' && config.rules['*'] !== false) ||
|
|
53
|
-
turnsOn(config.rules) ||
|
|
54
|
-
Object.values(config.archetypes).some((archetype) => turnsOn(archetype.rules) || archetype.modules.some((module) => turnsOn(module.rules)));
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|