@yearofthedan/warp 0.4.1 → 0.5.1
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 +6 -10
- package/dist/adapters/analysis/chains.d.ts +4 -0
- package/dist/adapters/analysis/chains.js +97 -0
- package/dist/adapters/analysis/classes.d.ts +3 -0
- package/dist/adapters/analysis/classes.js +109 -0
- 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 +60 -23
- package/dist/{analysis → adapters/analysis}/members.d.ts +1 -1
- package/dist/{analysis → adapters/analysis}/members.js +1 -1
- package/dist/{analysis → adapters/analysis}/source.d.ts +2 -2
- package/dist/{analysis → adapters/analysis}/source.js +2 -2
- 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 +14 -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 +7 -8
- 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 +23 -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/boundaries.d.ts +17 -0
- package/dist/builtins/boundaries.js +35 -0
- package/dist/builtins/class-cohesion/rule.d.ts +6 -0
- package/dist/builtins/class-cohesion/rule.js +34 -0
- 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/export-consumers/rule.d.ts +6 -0
- package/dist/builtins/export-consumers/rule.js +65 -0
- package/dist/builtins/export-spread/rule.d.ts +3 -0
- package/dist/builtins/export-spread/rule.js +65 -0
- package/dist/builtins/export-surface/rule.d.ts +6 -0
- package/dist/builtins/export-surface/rule.js +60 -0
- 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 +33 -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-dependencies/rule.d.ts +3 -0
- package/dist/builtins/module-dependencies/rule.js +67 -0
- package/dist/builtins/module-externals/rule.d.ts +2 -0
- package/dist/builtins/module-externals/{moduleExternals.js → rule.js} +3 -3
- package/dist/builtins/module-size/rule.d.ts +6 -0
- package/dist/builtins/module-size/rule.js +36 -0
- 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 → domain/facts}/facts.d.ts +20 -0
- 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 +12 -0
- package/dist/domain/language/compile.js +58 -0
- package/dist/{model/archetype → domain/language}/references.d.ts +6 -7
- package/dist/{model/archetype → domain/language}/references.js +41 -26
- 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 +11 -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} +33 -12
- package/dist/{model/archetype → domain/model}/data.d.ts +9 -6
- package/dist/{model/archetype → domain/model}/reach.d.ts +2 -0
- package/dist/{model/archetype → domain/model}/reach.js +10 -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 +3 -3
- package/dist/domain/model/settings.js +83 -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 +11 -4
- package/dist/{rules → domain/rules}/rule.js +1 -1
- 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/{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/errors}/configError.d.ts +0 -0
- /package/dist/{model → domain/errors}/configError.js +0 -0
- /package/dist/{model → domain/facts}/facts.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
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ignored, limitOptions, listed, valueUses, within } from '../boundaries.js';
|
|
2
|
+
const id = 'export-spread';
|
|
3
|
+
const defaults = { max: 2, ignore: [] };
|
|
4
|
+
export const exportSpread = {
|
|
5
|
+
id,
|
|
6
|
+
scope: 'project',
|
|
7
|
+
defaults,
|
|
8
|
+
moduleOptions: ['ignore'],
|
|
9
|
+
parseOptions: limitOptions(defaults),
|
|
10
|
+
check: ({ model, project, atModule }) => {
|
|
11
|
+
const uses = valueUses(model, project.files);
|
|
12
|
+
return model.modules.flatMap((module) => {
|
|
13
|
+
const { on, options } = atModule(module);
|
|
14
|
+
if (!on)
|
|
15
|
+
return [];
|
|
16
|
+
const skip = ignored(model, options.ignore);
|
|
17
|
+
return [...spreads(model, module, uses, skip).values()]
|
|
18
|
+
.filter((spread) => spread.children.size > options.max)
|
|
19
|
+
.map((spread) => finding(spread, module, model.moduleOf(spread.file), options.max));
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
const outside = (target, module, skip) => !within(target, module) && !skip.some((holder) => within(target, holder));
|
|
24
|
+
const spreads = (model, module, uses, skip) => {
|
|
25
|
+
const found = new Map();
|
|
26
|
+
for (const { file, edge, name } of uses) {
|
|
27
|
+
if (!outside(model.moduleOf(edge.to), module, skip))
|
|
28
|
+
continue;
|
|
29
|
+
const child = module.children.find((candidate) => !candidate.test && within(model.moduleOf(file), candidate));
|
|
30
|
+
if (!child)
|
|
31
|
+
continue;
|
|
32
|
+
const key = `${edge.to}#${name}`;
|
|
33
|
+
const spread = found.get(key) ?? { file: edge.to, name, children: new Map() };
|
|
34
|
+
found.set(key, spread);
|
|
35
|
+
spread.children.set(child, [...(spread.children.get(child) ?? []), { file, line: edge.line }]);
|
|
36
|
+
}
|
|
37
|
+
return found;
|
|
38
|
+
};
|
|
39
|
+
const finding = ({ file, name, children }, module, exporter, max) => {
|
|
40
|
+
const named = [...children.keys()].map((child) => child.id).sort();
|
|
41
|
+
const sites = [...children.values()].map(([first]) => first).toSorted((a, b) => a.file.localeCompare(b.file));
|
|
42
|
+
return {
|
|
43
|
+
rule: id,
|
|
44
|
+
key: `${id}:${module.id}:${file}#${name}`,
|
|
45
|
+
file: sites[0].file,
|
|
46
|
+
line: sites[0].line,
|
|
47
|
+
value: children.size,
|
|
48
|
+
limit: max,
|
|
49
|
+
message: `${children.size} of ${module.id}'s modules use ${name} from ${exporter.id}: ${listed(named)}. ` +
|
|
50
|
+
`Its limit here is ${max}. Give the use to the one module that should own it and let the others go through ` +
|
|
51
|
+
`that module, or name it in ${id}'s ignore on ${module.id} if it is meant to be shared.`,
|
|
52
|
+
sites,
|
|
53
|
+
parts: named,
|
|
54
|
+
details: {
|
|
55
|
+
module: module.id,
|
|
56
|
+
exporter: exporter.id,
|
|
57
|
+
file,
|
|
58
|
+
name,
|
|
59
|
+
children: [...children].map(([child, uses]) => ({
|
|
60
|
+
module: child.id,
|
|
61
|
+
files: [...new Set(uses.map((use) => use.file))],
|
|
62
|
+
})),
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { wholeNumberOptions } from '../../domain/rules/rule.js';
|
|
2
|
+
import { within } from '../boundaries.js';
|
|
3
|
+
const id = 'export-surface';
|
|
4
|
+
const defaults = { max: 20 };
|
|
5
|
+
export const exportSurface = {
|
|
6
|
+
id,
|
|
7
|
+
scope: 'project',
|
|
8
|
+
defaults,
|
|
9
|
+
parseOptions: wholeNumberOptions(defaults),
|
|
10
|
+
check: ({ model, project, atModule }) => {
|
|
11
|
+
const production = new Set(project.files.map((file) => file.path).filter((path) => !model.isTest(path)));
|
|
12
|
+
const uses = project.files.flatMap(({ path, imports }) => production.has(path)
|
|
13
|
+
? imports
|
|
14
|
+
.filter((edge) => !edge.reExport && production.has(edge.to))
|
|
15
|
+
.flatMap((edge) => edge.names
|
|
16
|
+
.filter((name) => name !== '*')
|
|
17
|
+
.map((name) => ({ from: path, file: edge.to, name, value: !edge.typeOnly })))
|
|
18
|
+
: []);
|
|
19
|
+
return model.modules.flatMap((module) => {
|
|
20
|
+
const { on, options } = atModule(module);
|
|
21
|
+
if (!on)
|
|
22
|
+
return [];
|
|
23
|
+
const names = surface(module, uses, (file) => model.moduleOf(file));
|
|
24
|
+
return names.length > options.max ? [finding(module, names, options.max)] : [];
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
const surface = (module, uses, moduleOf) => {
|
|
29
|
+
const names = new Map();
|
|
30
|
+
for (const { from, file, name, value } of uses) {
|
|
31
|
+
if (!within(moduleOf(file), module) || within(moduleOf(from), module))
|
|
32
|
+
continue;
|
|
33
|
+
const key = `${file}#${name}`;
|
|
34
|
+
const known = names.get(key);
|
|
35
|
+
names.set(key, { file, name, value: value || (known?.value ?? false) });
|
|
36
|
+
}
|
|
37
|
+
return [...names.values()].toSorted((a, b) => a.file.localeCompare(b.file) || a.name.localeCompare(b.name));
|
|
38
|
+
};
|
|
39
|
+
const finding = (module, names, max) => {
|
|
40
|
+
const values = names.filter((name) => name.value).length;
|
|
41
|
+
const byFile = Map.groupBy(names, (name) => name.file);
|
|
42
|
+
const [widest] = [...byFile].toSorted(([, a], [, b]) => b.length - a.length);
|
|
43
|
+
return {
|
|
44
|
+
rule: id,
|
|
45
|
+
key: `${id}:${module.id}`,
|
|
46
|
+
file: widest[0],
|
|
47
|
+
line: 1,
|
|
48
|
+
value: names.length,
|
|
49
|
+
limit: max,
|
|
50
|
+
message: `${module.id} offers ${names.length} names that other modules use (${counted(values, 'value')}, ${counted(names.length - values, 'type')}). ` +
|
|
51
|
+
`Its limit here is ${max}. Split it, or give it a smaller front.`,
|
|
52
|
+
details: {
|
|
53
|
+
module: module.id,
|
|
54
|
+
values,
|
|
55
|
+
types: names.length - values,
|
|
56
|
+
files: [...byFile].map(([file, found]) => ({ file, names: found.map((name) => name.name) })),
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
const counted = (count, noun) => `${count} ${noun}${count === 1 ? '' : 's'}`;
|
|
@@ -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,24 @@
|
|
|
1
|
-
import { registry } from '../rules/registry.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
1
|
+
import { registry } from '../domain/rules/registry.js';
|
|
2
|
+
import { classCohesion } from './class-cohesion/rule.js';
|
|
3
|
+
import { cognitiveComplexity } from './cognitive-complexity/rule.js';
|
|
4
|
+
import { exportConsumers } from './export-consumers/rule.js';
|
|
5
|
+
import { exportSpread } from './export-spread/rule.js';
|
|
6
|
+
import { exportSurface } from './export-surface/rule.js';
|
|
7
|
+
import { dependencyDirection } from './dependency-direction/rule.js';
|
|
8
|
+
import { fileCohesion } from './file-cohesion/rule.js';
|
|
9
|
+
import { functionCohesion } from './function-cohesion/rule.js';
|
|
10
|
+
import { moduleDependencies } from './module-dependencies/rule.js';
|
|
11
|
+
import { moduleSize } from './module-size/rule.js';
|
|
12
|
+
import { moduleCycle } from './module-cycle/rule.js';
|
|
13
|
+
import { moduleExternals } from './module-externals/rule.js';
|
|
14
|
+
import { noCrossModuleReexport } from './no-cross-module-reexport/rule.js';
|
|
15
|
+
import { noCycle } from './no-cycle/rule.js';
|
|
16
|
+
import { noDoubleExport } from './no-double-export/rule.js';
|
|
17
|
+
import { unclassified } from './unclassified/rule.js';
|
|
18
|
+
import { unresolvedImport } from './unresolved-import/rule.js';
|
|
19
|
+
import { unusedDeclaration } from './unused-declaration/rule.js';
|
|
13
20
|
export const builtinRules = [
|
|
21
|
+
unclassified,
|
|
14
22
|
unresolvedImport,
|
|
15
23
|
dependencyDirection,
|
|
16
24
|
moduleExternals,
|
|
@@ -19,9 +27,15 @@ export const builtinRules = [
|
|
|
19
27
|
noCycle,
|
|
20
28
|
moduleCycle,
|
|
21
29
|
fileCohesion,
|
|
30
|
+
classCohesion,
|
|
22
31
|
functionCohesion,
|
|
23
32
|
cognitiveComplexity,
|
|
24
33
|
unusedDeclaration,
|
|
34
|
+
exportConsumers,
|
|
35
|
+
exportSpread,
|
|
36
|
+
exportSurface,
|
|
37
|
+
moduleDependencies,
|
|
38
|
+
moduleSize,
|
|
25
39
|
];
|
|
26
40
|
const source = 'https://github.com/yearofthedan/warp/blob/main';
|
|
27
41
|
const documented = (rule) => ({
|
|
@@ -29,4 +43,10 @@ const documented = (rule) => ({
|
|
|
29
43
|
docs: `${source}/src/builtins/${rule.id}/README.md`,
|
|
30
44
|
});
|
|
31
45
|
export const builtinRegistry = registry(builtinRules.map(documented));
|
|
32
|
-
export const
|
|
46
|
+
export const warp = {
|
|
47
|
+
rules: [...builtinRegistry.values()],
|
|
48
|
+
rulesets: {
|
|
49
|
+
recommended: { rules: Object.fromEntries(builtinRules.map((rule) => [rule.id, 'on'])) },
|
|
50
|
+
utility: { rules: { 'export-consumers': 'off', 'export-surface': 'off' } },
|
|
51
|
+
},
|
|
52
|
+
};
|
package/dist/builtins/loops.d.ts
CHANGED
package/dist/builtins/loops.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConfigError } from '../
|
|
1
|
+
import { ConfigError } from '../domain/errors/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');
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { crossed, ignored, limitOptions, listed, within } from '../boundaries.js';
|
|
2
|
+
const id = 'module-dependencies';
|
|
3
|
+
const defaults = { max: 4, ignore: [] };
|
|
4
|
+
export const moduleDependencies = {
|
|
5
|
+
id,
|
|
6
|
+
scope: 'project',
|
|
7
|
+
defaults,
|
|
8
|
+
moduleOptions: ['ignore'],
|
|
9
|
+
parseOptions: limitOptions(defaults),
|
|
10
|
+
check: ({ model, project, atModule }) => {
|
|
11
|
+
const imports = productionImports(model, project.files);
|
|
12
|
+
return model.modules.flatMap((module) => {
|
|
13
|
+
const { on, options } = atModule(module);
|
|
14
|
+
if (!on)
|
|
15
|
+
return [];
|
|
16
|
+
const boundaries = crossings(model, module, imports, ignored(model, options.ignore));
|
|
17
|
+
return boundaries.size > options.max ? [finding(module, boundaries, options.max)] : [];
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
const crossings = (model, module, imports, skip) => {
|
|
22
|
+
const boundaries = new Map();
|
|
23
|
+
for (const { file, to, line } of imports) {
|
|
24
|
+
const target = model.moduleOf(to);
|
|
25
|
+
if (!within(model.moduleOf(file), module) || within(target, module))
|
|
26
|
+
continue;
|
|
27
|
+
if (skip.some((holder) => within(target, holder)))
|
|
28
|
+
continue;
|
|
29
|
+
const boundary = crossed(module, target);
|
|
30
|
+
boundaries.set(boundary, [...(boundaries.get(boundary) ?? []), { file, line }]);
|
|
31
|
+
}
|
|
32
|
+
return boundaries;
|
|
33
|
+
};
|
|
34
|
+
const productionImports = (model, files) => {
|
|
35
|
+
const production = new Set(files.map((file) => file.path).filter((path) => !model.isTest(path)));
|
|
36
|
+
return files
|
|
37
|
+
.filter(({ path }) => production.has(path))
|
|
38
|
+
.flatMap(({ path, imports }) => imports
|
|
39
|
+
.map((edge) => ({ file: path, to: edge.via ?? edge.to, line: edge.line }))
|
|
40
|
+
.filter(({ to }) => production.has(to)));
|
|
41
|
+
};
|
|
42
|
+
const finding = (module, boundaries, max) => {
|
|
43
|
+
const named = [...boundaries.keys()].map((boundary) => boundary.id).sort();
|
|
44
|
+
const sites = [...boundaries.values()]
|
|
45
|
+
.map(([first]) => first)
|
|
46
|
+
.toSorted((a, b) => a.file.localeCompare(b.file) || a.line - b.line);
|
|
47
|
+
return {
|
|
48
|
+
rule: id,
|
|
49
|
+
key: `${id}:${module.id}`,
|
|
50
|
+
file: sites[0].file,
|
|
51
|
+
line: sites[0].line,
|
|
52
|
+
value: boundaries.size,
|
|
53
|
+
limit: max,
|
|
54
|
+
message: `${module.id} imports across ${boundaries.size} boundaries: ${listed(named)}. Its limit here is ${max}. ` +
|
|
55
|
+
'Split it along what each part depends on, or reach some of them through one module. A module meant to wire ' +
|
|
56
|
+
`everything together, such as a composition root, turns ${id} off or raises its max.`,
|
|
57
|
+
sites,
|
|
58
|
+
parts: named,
|
|
59
|
+
details: {
|
|
60
|
+
module: module.id,
|
|
61
|
+
boundaries: [...boundaries].map(([boundary, uses]) => ({
|
|
62
|
+
module: boundary.id,
|
|
63
|
+
files: [...new Set(uses.map((use) => use.file))],
|
|
64
|
+
})),
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
};
|
|
@@ -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,
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { wholeNumberOptions } from '../../domain/rules/rule.js';
|
|
2
|
+
const id = 'module-size';
|
|
3
|
+
const defaults = { max: 1000 };
|
|
4
|
+
export const moduleSize = {
|
|
5
|
+
id,
|
|
6
|
+
scope: 'project',
|
|
7
|
+
defaults,
|
|
8
|
+
parseOptions: wholeNumberOptions(defaults),
|
|
9
|
+
check: ({ model, project, atModule }) => {
|
|
10
|
+
return model.modules.flatMap((module) => {
|
|
11
|
+
if (module.test)
|
|
12
|
+
return [];
|
|
13
|
+
const { on, options } = atModule(module);
|
|
14
|
+
if (!on)
|
|
15
|
+
return [];
|
|
16
|
+
const files = project.files
|
|
17
|
+
.filter(({ path }) => model.moduleOf(path) === module)
|
|
18
|
+
.map(({ path, lines }) => ({ file: path, lines }))
|
|
19
|
+
.toSorted((a, b) => b.lines - a.lines || a.file.localeCompare(b.file));
|
|
20
|
+
const total = files.reduce((sum, file) => sum + file.lines, 0);
|
|
21
|
+
return total > options.max ? [finding(module, files, total, options.max)] : [];
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const finding = (module, files, total, max) => ({
|
|
26
|
+
rule: id,
|
|
27
|
+
key: `${id}:${module.id}`,
|
|
28
|
+
file: files[0].file,
|
|
29
|
+
line: 1,
|
|
30
|
+
value: total,
|
|
31
|
+
limit: max,
|
|
32
|
+
message: `${module.id} holds ${total} lines in its own files (limit ${max}): ` +
|
|
33
|
+
`${files.map(({ file, lines }) => `${file} ${lines}`).join(', ')}. ` +
|
|
34
|
+
'Split it into modules that each hold one responsibility.',
|
|
35
|
+
details: { module: module.id, files },
|
|
36
|
+
});
|
|
@@ -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,19 +1,51 @@
|
|
|
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
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, ending, 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
|
};
|
|
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
|
+
};
|
|
17
49
|
const declared = (context, used) => Object.values(context.config.archetypes).flatMap((archetype) => {
|
|
18
50
|
const instances = instancesOf(context, archetype.name);
|
|
19
51
|
const unusedInputs = new Set(archetype.requires.filter((name) => !bindingsOf(context.config, archetype, name).some((ref) => used.has(ref))));
|
|
@@ -36,6 +68,7 @@ const declared = (context, used) => Object.values(context.config.archetypes).fla
|
|
|
36
68
|
layer,
|
|
37
69
|
holders,
|
|
38
70
|
ending: 'Remove it.',
|
|
71
|
+
inner: true,
|
|
39
72
|
}));
|
|
40
73
|
});
|
|
41
74
|
const kit = (archetype.testUsing ?? []).map((ref) => ({
|
|
@@ -57,9 +90,8 @@ const usedRefs = ({ project, verdicts }) => {
|
|
|
57
90
|
const used = new Set();
|
|
58
91
|
for (const file of project.files) {
|
|
59
92
|
const reach = verdicts.reach(file.path) ?? [];
|
|
60
|
-
const targets = file.imports.map((edge) => edge.via ?? edge.to);
|
|
61
93
|
for (const grant of reach) {
|
|
62
|
-
if (!grant.declared || !
|
|
94
|
+
if (!grant.declared || !importsThrough(grant, file))
|
|
63
95
|
continue;
|
|
64
96
|
used.add(grant.declared);
|
|
65
97
|
for (const bound of grant.via ?? [])
|
|
@@ -68,6 +100,6 @@ const usedRefs = ({ project, verdicts }) => {
|
|
|
68
100
|
}
|
|
69
101
|
return used;
|
|
70
102
|
};
|
|
71
|
-
const
|
|
72
|
-
?
|
|
73
|
-
: 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 })));
|