@yearofthedan/warp 0.4.0 → 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/adapters/config/loadConfig.d.ts +8 -0
- package/dist/{config → adapters/config}/loadConfig.js +44 -21
- package/dist/{git → adapters/git}/cache.d.ts +1 -1
- package/dist/{git → adapters/git}/cache.js +5 -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 +2 -2
- 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} +9 -4
- 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 +64 -14
- 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 +51 -54
- package/dist/{model/archetype → domain/fixes}/fixes.d.ts +2 -2
- package/dist/{model/archetype → domain/fixes}/fixes.js +36 -29
- 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 +13 -2
- 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} +50 -17
- package/dist/{model/archetype → domain/model}/data.d.ts +10 -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 +9 -3
- package/dist/{model/archetype → domain/model}/settings.d.ts +1 -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 +11 -1
- 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 +2 -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/config/loadConfig.d.ts +0 -13
- package/dist/model/archetype/rulesets.d.ts +0 -5
- package/dist/model/archetype/rulesets.js +0 -138
- package/dist/model/archetype/settings.js +0 -49
- /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}/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
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const failures = (cache, toolDigest) => {
|
|
2
|
+
const key = `${toolDigest}-failure`;
|
|
3
|
+
return {
|
|
4
|
+
isNew(problem) {
|
|
5
|
+
if (cache?.get(key) === problem)
|
|
6
|
+
return false;
|
|
7
|
+
cache?.set(key, problem);
|
|
8
|
+
return true;
|
|
9
|
+
},
|
|
10
|
+
forget() {
|
|
11
|
+
if (cache?.get(key) !== undefined)
|
|
12
|
+
cache.prune((other) => other !== key);
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
};
|
package/dist/app/load.d.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type
|
|
1
|
+
import type { ConfigData } from '../domain/model/data.ts';
|
|
2
|
+
import { type Plugin, type Rule } from '../domain/rules/rule.ts';
|
|
3
|
+
import { type ConfigLines } from './configLines.ts';
|
|
4
|
+
import type { ConfigSource } from './ports.ts';
|
|
3
5
|
export interface LoadedConfigData {
|
|
4
6
|
config: ConfigData;
|
|
5
7
|
rules: Rule[];
|
|
6
8
|
}
|
|
7
9
|
export interface LoadOptions {
|
|
8
|
-
builtins?:
|
|
9
|
-
ruleset?: string;
|
|
10
|
+
builtins?: Plugin;
|
|
10
11
|
file?: string;
|
|
11
12
|
plugins?: Record<string, unknown>;
|
|
12
13
|
}
|
|
13
|
-
export declare const loadConfigData: (raw: unknown, { builtins,
|
|
14
|
+
export declare const loadConfigData: (raw: unknown, { builtins, file, plugins }?: LoadOptions) => LoadedConfigData;
|
|
15
|
+
export interface LoadedConfig extends LoadedConfigData {
|
|
16
|
+
lines: ConfigLines;
|
|
17
|
+
digest: string;
|
|
18
|
+
}
|
|
19
|
+
export declare const loadConfig: (source: ConfigSource, options?: Omit<LoadOptions, 'file' | 'plugins'>) => Promise<LoadedConfig>;
|
package/dist/app/load.js
CHANGED
|
@@ -1,64 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ConfigError } from '../model/configError.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const fail = (message) => {
|
|
14
|
-
if (!errors.includes(message))
|
|
15
|
-
errors.push(message);
|
|
16
|
-
};
|
|
17
|
-
const failed = () => {
|
|
18
|
-
if (errors.length > 0)
|
|
19
|
-
throw new ConfigError(errors.join('\n'));
|
|
20
|
-
};
|
|
21
|
-
if (!isRecord(raw))
|
|
22
|
-
throw new ConfigError(`${file}: expected a mapping, root: { modules: ... }`);
|
|
23
|
-
const unknownKeys = Object.keys(raw).filter((key) => !keys.includes(key));
|
|
24
|
-
if (unknownKeys.length > 0)
|
|
25
|
-
fail(`${file}: unknown key ${unknownKeys.join(', ')}; a config takes ${keys.join(', ')}`);
|
|
26
|
-
checkPlugins(raw.plugins, plugins, fail);
|
|
27
|
-
const rules = [...registry([...(builtins ?? []), ...pluginRules(plugins)]).values()];
|
|
28
|
-
const structure = parseStructure(raw.root, raw.archetypes, fail);
|
|
29
|
-
failed();
|
|
30
|
-
checkReferences(structure.archetypes, structure.pending, fail);
|
|
31
|
-
markTests(structure.archetypes, fail);
|
|
32
|
-
checkInputs(structure.archetypes, structure.pending, fail);
|
|
33
|
-
const check = {
|
|
34
|
-
fail,
|
|
35
|
-
ruleIds: builtins && new Set([...rules.map((rule) => rule.id), unclassified]),
|
|
1
|
+
import { compileConfig } from '../domain/language/compile.js';
|
|
2
|
+
import { ConfigError } from '../domain/model/configError.js';
|
|
3
|
+
import { pluginRules, pluginRulesets, registry } from '../domain/rules/registry.js';
|
|
4
|
+
import { noOptions } from '../domain/rules/rule.js';
|
|
5
|
+
import { placeProblems } from './configLines.js';
|
|
6
|
+
export const loadConfigData = (raw, { builtins, file, plugins = {} } = {}) => {
|
|
7
|
+
const rules = [...registry([...(builtins?.rules ?? []), ...pluginRules(plugins)]).values()];
|
|
8
|
+
const config = compileConfig(raw, {
|
|
9
|
+
...(file === undefined ? {} : { file }),
|
|
10
|
+
plugins: Object.keys(plugins),
|
|
11
|
+
rulesets: pluginRulesets(builtins ? { ...plugins, warp: builtins } : plugins),
|
|
12
|
+
ruleIds: builtins && new Set(rules.map((rule) => rule.id)),
|
|
36
13
|
options: Object.fromEntries(rules.map((rule) => [rule.id, rule.parseOptions ?? noOptions])),
|
|
37
|
-
};
|
|
38
|
-
const data = {
|
|
39
|
-
file,
|
|
40
|
-
root: structure.root,
|
|
41
|
-
archetypes: Object.fromEntries(Object.entries(structure.archetypes).map(([name, archetype]) => [name, archetypeData(archetype)])),
|
|
42
|
-
tsconfig: tsconfigs(raw.tsconfig, fail),
|
|
43
|
-
};
|
|
44
|
-
const config = withRuleset(data, raw.rulesets, ruleset, (value, at) => toRules(check, value, at), fail);
|
|
45
|
-
failed();
|
|
14
|
+
});
|
|
46
15
|
return { config, rules };
|
|
47
16
|
};
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
return;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
17
|
+
export const loadConfig = async (source, options = {}) => {
|
|
18
|
+
const { raw, plugins, lines, digest } = await source.read();
|
|
19
|
+
try {
|
|
20
|
+
return { ...loadConfigData(raw, { ...options, plugins, file: source.file }), lines, digest };
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (error instanceof ConfigError)
|
|
24
|
+
throw new ConfigError(placeProblems(lines, source.file, error.message));
|
|
25
|
+
throw error;
|
|
55
26
|
}
|
|
56
|
-
for (const namespace of Object.keys(declared).filter((namespace) => !Object.hasOwn(loaded, namespace)))
|
|
57
|
-
fail(`plugins.${namespace}: not loaded; warp loads each plugin from its path before reading the config`);
|
|
58
|
-
};
|
|
59
|
-
const tsconfigs = (value, fail) => {
|
|
60
|
-
const paths = [value ?? 'tsconfig.json'].flat();
|
|
61
|
-
if (paths.length === 0 || !paths.every(isName))
|
|
62
|
-
fail('tsconfig: expected a path or a list of paths');
|
|
63
|
-
return paths;
|
|
64
27
|
};
|
package/dist/app/ports.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Folders } from '../model/
|
|
2
|
-
import type { FileFacts, Project } from '../
|
|
3
|
-
import type { Finding } from '../rules/rule.ts';
|
|
1
|
+
import type { Folders } from '../domain/model/resolve.ts';
|
|
2
|
+
import type { FileFacts, Project } from '../domain/facts/facts.ts';
|
|
3
|
+
import type { Finding } from '../domain/rules/rule.ts';
|
|
4
4
|
export interface Analyzer {
|
|
5
5
|
analyze(root: string, tsconfig: readonly string[], facts?: FactsStore): Project;
|
|
6
6
|
}
|
|
@@ -39,3 +39,13 @@ export interface CachedFile {
|
|
|
39
39
|
specifiers?: string[];
|
|
40
40
|
facts?: FileFacts;
|
|
41
41
|
}
|
|
42
|
+
export interface ConfigSource {
|
|
43
|
+
file: string;
|
|
44
|
+
read(): Promise<ConfigText>;
|
|
45
|
+
}
|
|
46
|
+
export interface ConfigText {
|
|
47
|
+
raw: unknown;
|
|
48
|
+
plugins: Record<string, unknown>;
|
|
49
|
+
lines: ReadonlyMap<string, number>;
|
|
50
|
+
digest: string;
|
|
51
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { RefData } from '../model/
|
|
2
|
-
import type { Fix } from '../
|
|
3
|
-
import type { Verdicts } from '../model/
|
|
4
|
-
import type { Model } from '../model/
|
|
1
|
+
import type { RefData } from '../domain/model/data.ts';
|
|
2
|
+
import type { Fix } from '../domain/fixes/fixes.ts';
|
|
3
|
+
import type { Verdicts } from '../domain/model/reach.ts';
|
|
4
|
+
import type { Model } from '../domain/model/resolve.ts';
|
|
5
5
|
export declare const refText: (ref: RefData) => string;
|
|
6
6
|
export declare const sentence: (parts: readonly string[]) => string;
|
|
7
7
|
export declare const reachSize: (verdicts: Verdicts, file: string) => number;
|
package/dist/builtins/advice.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { show } from '../model/
|
|
1
|
+
import { show } from '../domain/model/text.js';
|
|
2
2
|
export const refText = (ref) => show(ref);
|
|
3
3
|
export const sentence = (parts) => parts.length < 2 ? (parts[0] ?? '') : `${parts.slice(0, -1).join(', ')} and ${parts.at(-1)}`;
|
|
4
4
|
export const reachSize = (verdicts, file) => new Set((verdicts.reach(file) ?? []).flatMap((grant) => (grant.ref === undefined ? [] : [grant.ref]))).size;
|
|
@@ -17,7 +17,7 @@ const step = (model, fix, refs) => {
|
|
|
17
17
|
case 'test-expose':
|
|
18
18
|
return `add ${sentence(refs.map(refText))} to ${fix.archetype}.test.exposes${instances(model, fix.archetype)}`;
|
|
19
19
|
case 'expose-file':
|
|
20
|
-
return `add '${fix.pattern}' to ${fix.archetype}.exposes
|
|
20
|
+
return `add '${fix.pattern}' to the files of ${fix.archetype}.exposes`;
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
export const fixSteps = (model, fixes) => {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Member, MemberGraph, MemberKind } from '../
|
|
1
|
+
import type { Member, MemberGraph, MemberKind } from '../domain/facts/facts.ts';
|
|
2
2
|
export declare const components: (graph: MemberGraph, counted: readonly MemberKind[]) => Member[][];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { exposesText } from '../../model/
|
|
1
|
+
import { exposesText } from '../../domain/model/text.js';
|
|
2
2
|
import { fixSteps, reachSize, sentence } from '../advice.js';
|
|
3
3
|
import { place } from '../place.js';
|
|
4
4
|
import { title } from '../shared.js';
|
|
5
|
-
import { fixesFor } from '../../
|
|
6
|
-
import { noOptions } from '../../rules/rule.js';
|
|
5
|
+
import { fixesFor } from '../../domain/fixes/fixes.js';
|
|
6
|
+
import { noOptions } from '../../domain/rules/rule.js';
|
|
7
7
|
const id = 'dependency-direction';
|
|
8
8
|
export const dependencyDirection = {
|
|
9
9
|
id,
|
|
@@ -49,12 +49,17 @@ const explain = ({ config, model, verdicts }, from, to, refusal) => {
|
|
|
49
49
|
if (refusal.reason === 'test')
|
|
50
50
|
return 'a test file. Production code never imports tests: move what both need out of the test file into the module it tests.';
|
|
51
51
|
const instead = refusal.reason === 'private' ? throughSurface({ config, model, verdicts }, from, to, refusal.hiddenBy) : '';
|
|
52
|
-
|
|
52
|
+
const opened = (instead && fixesFor(config, model, from, to)) || [];
|
|
53
|
+
const exposing = opened.filter((fix) => fix.kind === 'expose' || fix.kind === 'expose-file');
|
|
54
|
+
const open = exposing.length > 0 ? ` Or, if ${to} should be public, ${sentence(fixSteps(model, exposing))}.` : '';
|
|
55
|
+
return `${why(config, model, verdicts, from, to, refusal)}. ${instead ? `${instead}${open}` : advise(config, model, verdicts, from, to)}`;
|
|
53
56
|
};
|
|
54
57
|
const why = (config, model, verdicts, from, to, refusal) => {
|
|
55
58
|
const source = model.moduleOf(from);
|
|
56
59
|
if (refusal.reason === 'private') {
|
|
57
60
|
const { hiddenBy } = refusal;
|
|
61
|
+
if (model.isTest(to))
|
|
62
|
+
return `which ${hiddenBy.id} keeps for its own tests`;
|
|
58
63
|
return `which ${hiddenBy.id} keeps private (it exposes ${exposesText(verdicts.exposes(hiddenBy))})`;
|
|
59
64
|
}
|
|
60
65
|
if (refusal.reason === 'above')
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { components } from '../components.js';
|
|
2
|
-
import { wholeNumberOptions } from '../../rules/rule.js';
|
|
2
|
+
import { wholeNumberOptions } from '../../domain/rules/rule.js';
|
|
3
3
|
import { group } from '../shared.js';
|
|
4
4
|
const defaults = { maxLines: 200 };
|
|
5
5
|
export const fileCohesion = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { components } from '../components.js';
|
|
2
|
-
import { wholeNumberOptions } from '../../rules/rule.js';
|
|
2
|
+
import { wholeNumberOptions } from '../../domain/rules/rule.js';
|
|
3
3
|
import { group, withOrdinals } from '../shared.js';
|
|
4
4
|
const defaults = { maxLines: 40 };
|
|
5
5
|
export const functionCohesion = {
|
package/dist/builtins/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Rule } from '../rules/rule.ts';
|
|
1
|
+
import type { Plugin, Rule } from '../domain/rules/rule.ts';
|
|
2
2
|
export declare const builtinRules: readonly Rule[];
|
|
3
3
|
export declare const builtinRegistry: ReadonlyMap<string, Rule>;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const warp: Plugin;
|
package/dist/builtins/index.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { registry } from '../rules/registry.js';
|
|
2
|
-
import { cognitiveComplexity } from './cognitive-complexity/
|
|
3
|
-
import { dependencyDirection } from './dependency-direction/
|
|
4
|
-
import { fileCohesion } from './file-cohesion/
|
|
5
|
-
import { functionCohesion } from './function-cohesion/
|
|
6
|
-
import { moduleCycle } from './module-cycle/
|
|
7
|
-
import { moduleExternals } from './module-externals/
|
|
8
|
-
import { noCrossModuleReexport } from './no-cross-module-reexport/
|
|
9
|
-
import { noCycle } from './no-cycle/
|
|
10
|
-
import { noDoubleExport } from './no-double-export/
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
1
|
+
import { registry } from '../domain/rules/registry.js';
|
|
2
|
+
import { cognitiveComplexity } from './cognitive-complexity/rule.js';
|
|
3
|
+
import { dependencyDirection } from './dependency-direction/rule.js';
|
|
4
|
+
import { fileCohesion } from './file-cohesion/rule.js';
|
|
5
|
+
import { functionCohesion } from './function-cohesion/rule.js';
|
|
6
|
+
import { moduleCycle } from './module-cycle/rule.js';
|
|
7
|
+
import { moduleExternals } from './module-externals/rule.js';
|
|
8
|
+
import { noCrossModuleReexport } from './no-cross-module-reexport/rule.js';
|
|
9
|
+
import { noCycle } from './no-cycle/rule.js';
|
|
10
|
+
import { noDoubleExport } from './no-double-export/rule.js';
|
|
11
|
+
import { unclassified } from './unclassified/rule.js';
|
|
12
|
+
import { unresolvedImport } from './unresolved-import/rule.js';
|
|
13
|
+
import { unusedDeclaration } from './unused-declaration/rule.js';
|
|
13
14
|
export const builtinRules = [
|
|
15
|
+
unclassified,
|
|
14
16
|
unresolvedImport,
|
|
15
17
|
dependencyDirection,
|
|
16
18
|
moduleExternals,
|
|
@@ -29,4 +31,7 @@ const documented = (rule) => ({
|
|
|
29
31
|
docs: `${source}/src/builtins/${rule.id}/README.md`,
|
|
30
32
|
});
|
|
31
33
|
export const builtinRegistry = registry(builtinRules.map(documented));
|
|
32
|
-
export const
|
|
34
|
+
export const warp = {
|
|
35
|
+
rules: [...builtinRegistry.values()],
|
|
36
|
+
rulesets: { recommended: { rules: Object.fromEntries(builtinRules.map((rule) => [rule.id, 'on'])) } },
|
|
37
|
+
};
|
package/dist/builtins/loops.d.ts
CHANGED
package/dist/builtins/loops.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConfigError } from '../model/configError.js';
|
|
1
|
+
import { ConfigError } from '../domain/model/configError.js';
|
|
2
2
|
export const cycleDefaults = { types: 'count' };
|
|
3
3
|
export const cycleOptions = (raw, at) => {
|
|
4
4
|
const unknown = Object.keys(raw).filter((key) => key !== 'types');
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { listsPackage } from '../packages.js';
|
|
2
2
|
import { place } from '../place.js';
|
|
3
|
-
import { sitesOf } from '../../
|
|
4
|
-
import { packageText } from '../../model/
|
|
5
|
-
import { noOptions } from '../../rules/rule.js';
|
|
3
|
+
import { sitesOf } from '../../domain/fixes/fixes.js';
|
|
4
|
+
import { packageText } from '../../domain/model/text.js';
|
|
5
|
+
import { noOptions } from '../../domain/rules/rule.js';
|
|
6
6
|
const id = 'module-externals';
|
|
7
7
|
export const moduleExternals = {
|
|
8
8
|
id,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { place } from '../place.js';
|
|
2
|
-
import { noOptions } from '../../rules/rule.js';
|
|
2
|
+
import { noOptions } from '../../domain/rules/rule.js';
|
|
3
3
|
const id = 'no-double-export';
|
|
4
4
|
const exposingBoth = (verdicts, module, from, to) => {
|
|
5
5
|
for (let at = module; at; at = at.parent)
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { ExternalImport } from '../
|
|
1
|
+
import type { ExternalImport } from '../domain/facts/facts.ts';
|
|
2
2
|
export declare const listsPackage: (pattern: string, external: Pick<ExternalImport, 'package' | 'specifier'>) => boolean;
|
package/dist/builtins/place.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Model, ModuleView } from '../model/
|
|
1
|
+
import type { Model, ModuleView } from '../domain/model/resolve.ts';
|
|
2
2
|
export declare const place: (model: Model, file: string, module?: ModuleView) => string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const unclassified = {
|
|
2
|
+
id: 'unclassified',
|
|
3
|
+
scope: 'project',
|
|
4
|
+
check: ({ model, atModule }) => model.modules.flatMap((module) => atModule(module).on
|
|
5
|
+
? module.looseFiles.map((file) => ({
|
|
6
|
+
rule: 'unclassified',
|
|
7
|
+
key: `unclassified:${file}`,
|
|
8
|
+
file,
|
|
9
|
+
line: 1,
|
|
10
|
+
value: 1,
|
|
11
|
+
message: `${file} is in no module of ${module.parent ? `${module.id} (${module.archetype})` : 'the root'}, so nothing says what it may import. ` +
|
|
12
|
+
`Add a files module to ${module.archetype} that matches it, or move it into a module's folder.`,
|
|
13
|
+
}))
|
|
14
|
+
: []),
|
|
15
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ConfigData } from '../../model/
|
|
2
|
-
import type { ModuleView } from '../../model/
|
|
3
|
-
import type { Finding, ProjectContext } from '../../rules/rule.ts';
|
|
1
|
+
import type { ConfigData } from '../../domain/model/data.ts';
|
|
2
|
+
import type { ModuleView } from '../../domain/model/resolve.ts';
|
|
3
|
+
import type { Finding, ProjectContext } from '../../domain/rules/rule.ts';
|
|
4
4
|
export declare const id = "unused-declaration";
|
|
5
5
|
export type Layer = 'production' | 'test';
|
|
6
6
|
export type UnusedDeclaration = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isTestData } from '../../model/
|
|
1
|
+
import { isTestData } from '../../domain/model/data.js';
|
|
2
2
|
import { childrenNamed, instancesOf, named, unused } from './declarations.js';
|
|
3
3
|
export const emptyModules = (context) => Object.values(context.config.archetypes).flatMap((archetype) => {
|
|
4
4
|
const instances = instancesOf(context, archetype.name);
|
|
@@ -1,29 +1,74 @@
|
|
|
1
|
-
import { isTestData } from '../../model/
|
|
2
|
-
import { show } from '../../model/
|
|
1
|
+
import { isTestData, } from '../../domain/model/data.js';
|
|
2
|
+
import { show } from '../../domain/model/text.js';
|
|
3
3
|
import { listsPackage } from '../packages.js';
|
|
4
|
-
import { childrenNamed, instancesOf, named, unused } from './declarations.js';
|
|
4
|
+
import { childrenNamed, instancesOf, named, unused, within } from './declarations.js';
|
|
5
5
|
export const unusedGrants = (context) => {
|
|
6
6
|
const used = usedRefs(context);
|
|
7
|
-
return declared(context)
|
|
7
|
+
return declared(context, used)
|
|
8
8
|
.filter(({ ref, holders }) => !used.has(ref) && holders.some((holder) => context.atModule(holder).on))
|
|
9
|
-
.map(({ ref, declaredIn, layer, holders, kit }) => {
|
|
9
|
+
.map(({ ref, declaredIn, layer, holders, ending, kit, inner }) => {
|
|
10
10
|
const using = show(ref);
|
|
11
11
|
const modules = holders.map((holder) => holder.id);
|
|
12
12
|
const names = holders.map(named).join(', ');
|
|
13
13
|
const files = kit ? `the tests of ${names}` : names;
|
|
14
|
-
|
|
14
|
+
const users = inner ? innerUsers(context, holders, ref, layer) : [];
|
|
15
|
+
const owner = declaredIn.slice(0, -'.dependencies'.length);
|
|
16
|
+
const sites = users.map((name) => `${owner}.${name}.dependencies`);
|
|
17
|
+
const message = users.length === 0
|
|
18
|
+
? `${declaredIn} names ${using}, but nothing in ${files} imports through it. ${ending}`
|
|
19
|
+
: `${declaredIn} names ${using}, but only its modules ${users.join(', ')} import through it. ` +
|
|
20
|
+
`A module's dependencies are its own: name it in ${sites.join(' and ')}, and remove it here.`;
|
|
21
|
+
return unused(context.config, `${declaredIn}->${using}`, message, {
|
|
22
|
+
kind: 'grant',
|
|
23
|
+
declaredIn,
|
|
24
|
+
layer,
|
|
25
|
+
using,
|
|
26
|
+
modules,
|
|
27
|
+
});
|
|
15
28
|
});
|
|
16
29
|
};
|
|
17
|
-
const
|
|
30
|
+
const innerUsers = (context, holders, ref, layer) => {
|
|
31
|
+
const users = new Set();
|
|
32
|
+
for (const holder of holders) {
|
|
33
|
+
const grant = context.verdicts.grants(holder, layer).find((candidate) => candidate.declared === ref);
|
|
34
|
+
for (const file of context.project.files) {
|
|
35
|
+
const module = context.model.moduleOf(file.path);
|
|
36
|
+
if (grant && module && module !== holder && within(module, holder) && importsThrough(grant, file)) {
|
|
37
|
+
users.add(childOf(holder, module).name ?? module.id);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return [...users].sort();
|
|
42
|
+
};
|
|
43
|
+
const childOf = (holder, module) => {
|
|
44
|
+
let at = module;
|
|
45
|
+
while (at.parent !== holder)
|
|
46
|
+
at = at.parent;
|
|
47
|
+
return at;
|
|
48
|
+
};
|
|
49
|
+
const declared = (context, used) => Object.values(context.config.archetypes).flatMap((archetype) => {
|
|
18
50
|
const instances = instancesOf(context, archetype.name);
|
|
51
|
+
const unusedInputs = new Set(archetype.requires.filter((name) => !bindingsOf(context.config, archetype, name).some((ref) => used.has(ref))));
|
|
52
|
+
const requires = [...unusedInputs].map((name) => ({
|
|
53
|
+
ref: { kind: 'required', name },
|
|
54
|
+
declaredIn: `${archetype.name}.requires`,
|
|
55
|
+
layer: 'production',
|
|
56
|
+
holders: instances,
|
|
57
|
+
ending: 'Remove it, with its binding at each use.',
|
|
58
|
+
}));
|
|
19
59
|
const modules = archetype.modules.flatMap((module) => {
|
|
20
60
|
const holders = childrenNamed(context, instances, module.name);
|
|
21
61
|
const layer = isTestData(module) ? 'test' : 'production';
|
|
22
|
-
return module.using
|
|
62
|
+
return module.using
|
|
63
|
+
.filter((ref) => !fills(context.config, module, ref))
|
|
64
|
+
.filter((ref) => ref.kind !== 'required' || !unusedInputs.has(ref.name))
|
|
65
|
+
.map((ref) => ({
|
|
23
66
|
ref,
|
|
24
67
|
declaredIn: `${archetype.name}.${module.name}.dependencies`,
|
|
25
68
|
layer,
|
|
26
69
|
holders,
|
|
70
|
+
ending: 'Remove it.',
|
|
71
|
+
inner: true,
|
|
27
72
|
}));
|
|
28
73
|
});
|
|
29
74
|
const kit = (archetype.testUsing ?? []).map((ref) => ({
|
|
@@ -31,17 +76,22 @@ const declared = (context) => Object.values(context.config.archetypes).flatMap((
|
|
|
31
76
|
declaredIn: `${archetype.name}.test.provides`,
|
|
32
77
|
layer: 'test',
|
|
33
78
|
holders: instances,
|
|
79
|
+
ending: 'Remove it.',
|
|
34
80
|
kit: true,
|
|
35
81
|
}));
|
|
36
|
-
return [...modules, ...kit];
|
|
82
|
+
return [...requires, ...modules, ...kit];
|
|
37
83
|
});
|
|
84
|
+
const fills = (config, module, ref) => module.kind === 'dir' &&
|
|
85
|
+
Object.entries(module.inputs ?? {}).some(([name, bound]) => bound === ref && config.archetypes[module.archetype].requires.includes(name));
|
|
86
|
+
const bindingsOf = (config, archetype, name) => Object.values(config.archetypes).flatMap((holder) => holder.modules.flatMap((module) => module.kind === 'dir' && module.archetype === archetype.name && module.inputs?.[name]
|
|
87
|
+
? [module.inputs[name]]
|
|
88
|
+
: []));
|
|
38
89
|
const usedRefs = ({ project, verdicts }) => {
|
|
39
90
|
const used = new Set();
|
|
40
91
|
for (const file of project.files) {
|
|
41
92
|
const reach = verdicts.reach(file.path) ?? [];
|
|
42
|
-
const targets = file.imports.map((edge) => edge.via ?? edge.to);
|
|
43
93
|
for (const grant of reach) {
|
|
44
|
-
if (!grant.declared || !
|
|
94
|
+
if (!grant.declared || !importsThrough(grant, file))
|
|
45
95
|
continue;
|
|
46
96
|
used.add(grant.declared);
|
|
47
97
|
for (const bound of grant.via ?? [])
|
|
@@ -50,6 +100,6 @@ const usedRefs = ({ project, verdicts }) => {
|
|
|
50
100
|
}
|
|
51
101
|
return used;
|
|
52
102
|
};
|
|
53
|
-
const
|
|
54
|
-
?
|
|
55
|
-
: externals.some((external) => listsPackage(grant.package, external));
|
|
103
|
+
const importsThrough = (grant, file) => grant.package === undefined
|
|
104
|
+
? file.imports.some((edge) => grant.files.has(edge.via ?? edge.to))
|
|
105
|
+
: file.externals.some((external) => listsPackage(grant.package, external));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isTestData } from '../../model/
|
|
1
|
+
import { isTestData } from '../../domain/model/data.js';
|
|
2
2
|
import { childrenNamed, instancesOf, named, unused, within } from './declarations.js';
|
|
3
3
|
export const unusedSurfaces = (context) => {
|
|
4
4
|
const edges = context.project.files.flatMap((file) => file.imports.map((edge) => ({ from: file.path, to: edge.via ?? edge.to })));
|