@kurvball/ashlar 0.0.0-stage → 1.3.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/CHANGELOG.md +238 -0
- package/LICENSE +21 -0
- package/README.md +145 -2
- package/dist/affected.d.ts +19 -0
- package/dist/affected.js +78 -0
- package/dist/areas.d.ts +2 -0
- package/dist/areas.js +20 -0
- package/dist/baseline.d.ts +27 -0
- package/dist/baseline.js +109 -0
- package/dist/beside.d.ts +1 -0
- package/dist/beside.js +4 -0
- package/dist/check.d.ts +39 -0
- package/dist/check.js +109 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +211 -0
- package/dist/config.d.ts +84 -0
- package/dist/config.js +98 -0
- package/dist/configCheck.d.ts +2 -0
- package/dist/configCheck.js +204 -0
- package/dist/css.d.ts +13 -0
- package/dist/css.js +66 -0
- package/dist/drive.d.ts +77 -0
- package/dist/drive.js +188 -0
- package/dist/features.d.ts +32 -0
- package/dist/features.js +156 -0
- package/dist/git.d.ts +18 -0
- package/dist/git.js +140 -0
- package/dist/glob.d.ts +5 -0
- package/dist/glob.js +49 -0
- package/dist/graph.d.ts +16 -0
- package/dist/graph.js +83 -0
- package/dist/identity.d.ts +1 -0
- package/dist/identity.js +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +18 -0
- package/dist/jsonc.d.ts +1 -0
- package/dist/jsonc.js +66 -0
- package/dist/knowledge/areas.d.ts +25 -0
- package/dist/knowledge/areas.js +86 -0
- package/dist/knowledge/decisions.d.ts +14 -0
- package/dist/knowledge/decisions.js +53 -0
- package/dist/knowledge/guards.d.ts +4 -0
- package/dist/knowledge/guards.js +60 -0
- package/dist/knowledge/rules.d.ts +12 -0
- package/dist/knowledge/rules.js +100 -0
- package/dist/knowledge/secrets.d.ts +6 -0
- package/dist/knowledge/secrets.js +58 -0
- package/dist/layout.d.ts +61 -0
- package/dist/layout.js +120 -0
- package/dist/ledger.d.ts +28 -0
- package/dist/ledger.js +44 -0
- package/dist/lint.d.ts +11 -0
- package/dist/lint.js +109 -0
- package/dist/map.d.ts +25 -0
- package/dist/map.js +37 -0
- package/dist/move.d.ts +18 -0
- package/dist/move.js +94 -0
- package/dist/onboard/applies.d.ts +11 -0
- package/dist/onboard/applies.js +28 -0
- package/dist/onboard/brief.d.ts +40 -0
- package/dist/onboard/brief.js +126 -0
- package/dist/onboard/guide.d.ts +7 -0
- package/dist/onboard/guide.js +150 -0
- package/dist/onboard/model.d.ts +15 -0
- package/dist/onboard/model.js +57 -0
- package/dist/onboard/onboard.d.ts +28 -0
- package/dist/onboard/onboard.js +86 -0
- package/dist/onboard/questions.d.ts +15 -0
- package/dist/onboard/questions.js +90 -0
- package/dist/onboard/snapshot.d.ts +28 -0
- package/dist/onboard/snapshot.js +58 -0
- package/dist/order.d.ts +1 -0
- package/dist/order.js +1 -0
- package/dist/origins.d.ts +6 -0
- package/dist/origins.js +51 -0
- package/dist/plugin/boundaries.d.ts +5 -0
- package/dist/plugin/boundaries.js +174 -0
- package/dist/plugin/exports.d.ts +2 -0
- package/dist/plugin/exports.js +41 -0
- package/dist/plugin/features.d.ts +4 -0
- package/dist/plugin/features.js +34 -0
- package/dist/plugin/here.d.ts +13 -0
- package/dist/plugin/here.js +69 -0
- package/dist/plugin/imports.d.ts +12 -0
- package/dist/plugin/imports.js +103 -0
- package/dist/plugin/index.d.ts +14 -0
- package/dist/plugin/index.js +19 -0
- package/dist/plugin/messages.d.ts +20 -0
- package/dist/plugin/messages.js +36 -0
- package/dist/plugin/names.d.ts +3 -0
- package/dist/plugin/names.js +68 -0
- package/dist/plugin/references.d.ts +5 -0
- package/dist/plugin/references.js +52 -0
- package/dist/plugin/text.d.ts +7 -0
- package/dist/plugin/text.js +87 -0
- package/dist/plugin/types.d.ts +87 -0
- package/dist/plugin/types.js +1 -0
- package/dist/reach.d.ts +82 -0
- package/dist/reach.js +163 -0
- package/dist/reachDrive.d.ts +31 -0
- package/dist/reachDrive.js +200 -0
- package/dist/reachReader.d.ts +1 -0
- package/dist/reachReader.js +31 -0
- package/dist/rehearse/dependents.d.ts +9 -0
- package/dist/rehearse/dependents.js +38 -0
- package/dist/rehearse/fill.d.ts +28 -0
- package/dist/rehearse/fill.js +44 -0
- package/dist/report.d.ts +6 -0
- package/dist/report.js +91 -0
- package/dist/resolve.d.ts +3 -0
- package/dist/resolve.js +114 -0
- package/dist/runner.d.ts +6 -0
- package/dist/runner.js +29 -0
- package/dist/skill.d.ts +23 -0
- package/dist/skill.js +235 -0
- package/dist/usage.d.ts +1 -0
- package/dist/usage.js +53 -0
- package/dist/workspace.d.ts +16 -0
- package/dist/workspace.js +125 -0
- package/ledger.json +201 -0
- package/package.json +73 -3
- package/schema/affected.v1.json +58 -0
- package/schema/brief.v1.json +205 -0
- package/schema/check.v1.json +151 -0
- package/schema/dependents.v1.json +30 -0
- package/schema/drive.v1.json +55 -0
- package/schema/ledger.v1.json +61 -0
- package/schema/map.v1.json +62 -0
- package/schema/move.v1.json +61 -0
- package/schema/onboard.v1.json +186 -0
- package/schema/rehearse.v1.json +91 -0
- package/schema/snapshot.v1.json +101 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { nameOf } from './imports.js';
|
|
2
|
+
function bound(node, out) {
|
|
3
|
+
if (!node)
|
|
4
|
+
return;
|
|
5
|
+
if (node.type === 'Identifier')
|
|
6
|
+
out.push(node.name);
|
|
7
|
+
else if (node.type === 'ObjectPattern')
|
|
8
|
+
for (const property of node.properties)
|
|
9
|
+
bound(property.type === 'RestElement' ? property.argument : property.value, out);
|
|
10
|
+
else if (node.type === 'ArrayPattern')
|
|
11
|
+
for (const element of node.elements)
|
|
12
|
+
bound(element, out);
|
|
13
|
+
else if (node.type === 'RestElement')
|
|
14
|
+
bound(node.argument, out);
|
|
15
|
+
else if (node.type === 'AssignmentPattern')
|
|
16
|
+
bound(node.left, out);
|
|
17
|
+
}
|
|
18
|
+
function declared(node, out) {
|
|
19
|
+
if (node.type === 'VariableDeclaration')
|
|
20
|
+
for (const declarator of node.declarations)
|
|
21
|
+
bound(declarator.id, out);
|
|
22
|
+
else if (node.id)
|
|
23
|
+
out.push(nameOf(node.id));
|
|
24
|
+
}
|
|
25
|
+
export function exportsVisitor(on) {
|
|
26
|
+
return {
|
|
27
|
+
ExportNamedDeclaration(node) {
|
|
28
|
+
if (node.source)
|
|
29
|
+
return;
|
|
30
|
+
const names = [];
|
|
31
|
+
if (node.declaration)
|
|
32
|
+
declared(node.declaration, names);
|
|
33
|
+
for (const specifier of node.specifiers)
|
|
34
|
+
names.push(nameOf(specifier.exported));
|
|
35
|
+
names.forEach(on);
|
|
36
|
+
},
|
|
37
|
+
ExportDefaultDeclaration() {
|
|
38
|
+
on('default');
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { found, hereOf } from './here.js';
|
|
2
|
+
import { MESSAGES } from './messages.js';
|
|
3
|
+
import { calleeName } from './references.js';
|
|
4
|
+
const EFFECTS = new Set(['useEffect', 'useLayoutEffect', 'useInsertionEffect']);
|
|
5
|
+
const TIMERS = new Set(['setTimeout', 'setInterval', 'requestAnimationFrame', 'requestIdleCallback']);
|
|
6
|
+
const QUERIES = new Set([
|
|
7
|
+
'querySelector',
|
|
8
|
+
'querySelectorAll',
|
|
9
|
+
'getElementById',
|
|
10
|
+
'getElementsByClassName',
|
|
11
|
+
'getElementsByTagName',
|
|
12
|
+
'getElementsByName',
|
|
13
|
+
'closest',
|
|
14
|
+
]);
|
|
15
|
+
function inFeatures(rule, calls, description) {
|
|
16
|
+
return {
|
|
17
|
+
meta: { type: 'problem', docs: { description } },
|
|
18
|
+
create(context) {
|
|
19
|
+
const here = hereOf(context);
|
|
20
|
+
if (!here || here.test || here.place.role !== 'features')
|
|
21
|
+
return {};
|
|
22
|
+
return {
|
|
23
|
+
CallExpression(node) {
|
|
24
|
+
const callee = calleeName(node);
|
|
25
|
+
if (callee && calls.has(callee))
|
|
26
|
+
found(context, here, rule, node.callee.loc, MESSAGES[rule]);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export const noEffect = inFeatures('no-effect', EFFECTS, 'Features use no effects.');
|
|
33
|
+
export const noTimer = inFeatures('no-timer', TIMERS, 'Features use no timers.');
|
|
34
|
+
export const noDomQuery = inFeatures('no-dom-query', QUERIES, 'Features reach elements by their refs.');
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Place } from '../layout.ts';
|
|
2
|
+
import type { Context, FileFindings, Loc, Settings } from './types.ts';
|
|
3
|
+
export interface Here {
|
|
4
|
+
settings: Settings;
|
|
5
|
+
path: string;
|
|
6
|
+
test: boolean;
|
|
7
|
+
place: Place;
|
|
8
|
+
findings: FileFindings;
|
|
9
|
+
resolve: (specifier: string) => string | null;
|
|
10
|
+
placeOf: (path: string) => Place;
|
|
11
|
+
}
|
|
12
|
+
export declare function hereOf(context: Context): Here | null;
|
|
13
|
+
export declare function found(context: Context, here: Here, rule: string, loc: Loc, message: string, size?: number): void;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
|
2
|
+
import { relative } from 'node:path';
|
|
3
|
+
import { placeOf, tidy } from '../layout.js';
|
|
4
|
+
import { makeResolver } from '../resolve.js';
|
|
5
|
+
const envs = new Map();
|
|
6
|
+
function write(env, target) {
|
|
7
|
+
const findings = { files: Object.fromEntries(env.files) };
|
|
8
|
+
writeFileSync(target, JSON.stringify(findings));
|
|
9
|
+
}
|
|
10
|
+
function envOf(settings) {
|
|
11
|
+
const key = `${settings.root}\0${settings.record ?? ''}`;
|
|
12
|
+
let env = envs.get(key);
|
|
13
|
+
if (!env) {
|
|
14
|
+
const made = {
|
|
15
|
+
settings,
|
|
16
|
+
resolve: makeResolver(settings.root, settings.workspace),
|
|
17
|
+
files: new Map(),
|
|
18
|
+
places: new Map(),
|
|
19
|
+
};
|
|
20
|
+
envs.set(key, made);
|
|
21
|
+
const target = settings.record;
|
|
22
|
+
if (target)
|
|
23
|
+
process.once('exit', () => write(made, target));
|
|
24
|
+
env = made;
|
|
25
|
+
}
|
|
26
|
+
return env;
|
|
27
|
+
}
|
|
28
|
+
export function hereOf(context) {
|
|
29
|
+
const settings = context.settings.ashlar;
|
|
30
|
+
if (!settings)
|
|
31
|
+
return null;
|
|
32
|
+
const env = envOf(settings);
|
|
33
|
+
const path = tidy(relative(settings.root, context.filename));
|
|
34
|
+
if (path.startsWith('..'))
|
|
35
|
+
return null;
|
|
36
|
+
let findings = env.files.get(path);
|
|
37
|
+
if (!findings) {
|
|
38
|
+
findings = { breaks: [], edges: [] };
|
|
39
|
+
env.files.set(path, findings);
|
|
40
|
+
}
|
|
41
|
+
const placeAt = (target) => {
|
|
42
|
+
let place = env.places.get(target);
|
|
43
|
+
if (!place) {
|
|
44
|
+
place = placeOf(target, env.settings.apps);
|
|
45
|
+
env.places.set(target, place);
|
|
46
|
+
}
|
|
47
|
+
return place;
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
settings,
|
|
51
|
+
path,
|
|
52
|
+
test: settings.tests.some((suffix) => path.endsWith(suffix)),
|
|
53
|
+
place: placeAt(path),
|
|
54
|
+
findings,
|
|
55
|
+
resolve: (specifier) => env.resolve(path, specifier),
|
|
56
|
+
placeOf: placeAt,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export function found(context, here, rule, loc, message, size = 1) {
|
|
60
|
+
const said = here.settings.messages?.[rule] ?? message;
|
|
61
|
+
context.report({ loc, message: said });
|
|
62
|
+
here.findings.breaks.push({
|
|
63
|
+
rule,
|
|
64
|
+
line: loc.start.line,
|
|
65
|
+
column: loc.start.column + 1,
|
|
66
|
+
size,
|
|
67
|
+
message: said,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Node, Visitor } from './types.ts';
|
|
2
|
+
export interface Import {
|
|
3
|
+
specifier: string;
|
|
4
|
+
node: Node;
|
|
5
|
+
type: boolean;
|
|
6
|
+
effect: boolean;
|
|
7
|
+
takes?: string[] | null;
|
|
8
|
+
passes?: [string, string][];
|
|
9
|
+
}
|
|
10
|
+
export declare const nameOf: (node: Node) => string;
|
|
11
|
+
export declare function importVisitor(on: (seen: Import) => void): Visitor;
|
|
12
|
+
export declare function merge(...visitors: Visitor[]): Visitor;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
const MOCKS = new Set(['mock', 'doMock', 'unmock', 'importActual', 'importMock']);
|
|
2
|
+
function literal(node) {
|
|
3
|
+
if (!node)
|
|
4
|
+
return null;
|
|
5
|
+
if (node.type === 'Literal' && typeof node.value === 'string')
|
|
6
|
+
return node.value;
|
|
7
|
+
if (node.type === 'TemplateLiteral' && node.expressions.length === 0)
|
|
8
|
+
return node.quasis[0]?.value.cooked ?? null;
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
function allTypes(specifiers, kind) {
|
|
12
|
+
return specifiers.length > 0 && specifiers.every((specifier) => specifier[kind] === 'type');
|
|
13
|
+
}
|
|
14
|
+
export const nameOf = (node) => (node.type === 'Identifier' ? node.name : String(node.value));
|
|
15
|
+
function taken(specifiers) {
|
|
16
|
+
const names = [];
|
|
17
|
+
for (const specifier of specifiers) {
|
|
18
|
+
if (specifier.type === 'ImportNamespaceSpecifier')
|
|
19
|
+
return null;
|
|
20
|
+
if (specifier.importKind === 'type')
|
|
21
|
+
continue;
|
|
22
|
+
names.push(specifier.type === 'ImportDefaultSpecifier' ? 'default' : nameOf(specifier.imported));
|
|
23
|
+
}
|
|
24
|
+
return names;
|
|
25
|
+
}
|
|
26
|
+
function isImportMetaUrl(node) {
|
|
27
|
+
return (node?.type === 'MemberExpression' &&
|
|
28
|
+
node.object.type === 'MetaProperty' &&
|
|
29
|
+
node.object.meta.name === 'import' &&
|
|
30
|
+
node.property.name === 'url');
|
|
31
|
+
}
|
|
32
|
+
function isMock(callee) {
|
|
33
|
+
return (callee.type === 'MemberExpression' &&
|
|
34
|
+
callee.object.type === 'Identifier' &&
|
|
35
|
+
callee.object.name === 'vi' &&
|
|
36
|
+
callee.property.type === 'Identifier' &&
|
|
37
|
+
MOCKS.has(callee.property.name));
|
|
38
|
+
}
|
|
39
|
+
export function importVisitor(on) {
|
|
40
|
+
const seen = (source, type, effect = false, uses = { takes: null }) => {
|
|
41
|
+
const specifier = literal(source);
|
|
42
|
+
if (specifier !== null && source)
|
|
43
|
+
on({ specifier, node: source, type, effect, ...uses });
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
ImportDeclaration(node) {
|
|
47
|
+
const type = node.importKind === 'type' || allTypes(node.specifiers, 'importKind');
|
|
48
|
+
const effect = node.specifiers.length === 0 && node.importKind !== 'type';
|
|
49
|
+
seen(node.source, type, effect, { takes: effect ? null : taken(node.specifiers) });
|
|
50
|
+
},
|
|
51
|
+
ExportAllDeclaration(node) {
|
|
52
|
+
const here = node.exported ? nameOf(node.exported) : '*';
|
|
53
|
+
seen(node.source, node.exportKind === 'type', false, { passes: [['*', here]] });
|
|
54
|
+
},
|
|
55
|
+
ExportNamedDeclaration(node) {
|
|
56
|
+
if (!node.source)
|
|
57
|
+
return;
|
|
58
|
+
const passes = node.specifiers
|
|
59
|
+
.filter((specifier) => specifier.exportKind !== 'type')
|
|
60
|
+
.map((specifier) => [nameOf(specifier.local), nameOf(specifier.exported)]);
|
|
61
|
+
seen(node.source, node.exportKind === 'type' || allTypes(node.specifiers, 'exportKind'), false, {
|
|
62
|
+
passes,
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
ImportExpression(node) {
|
|
66
|
+
seen(node.source, false);
|
|
67
|
+
},
|
|
68
|
+
TSImportType(node) {
|
|
69
|
+
seen(node.source ?? node.argument?.literal, true);
|
|
70
|
+
},
|
|
71
|
+
TSExternalModuleReference(node) {
|
|
72
|
+
seen(node.expression, false);
|
|
73
|
+
},
|
|
74
|
+
CallExpression(node) {
|
|
75
|
+
const callee = node.callee;
|
|
76
|
+
if ((callee.type === 'Identifier' && callee.name === 'require') || isMock(callee)) {
|
|
77
|
+
seen(node.arguments[0], false);
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
NewExpression(node) {
|
|
81
|
+
if (node.callee.type === 'Identifier' &&
|
|
82
|
+
node.callee.name === 'URL' &&
|
|
83
|
+
isImportMetaUrl(node.arguments[1])) {
|
|
84
|
+
seen(node.arguments[0], false);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export function merge(...visitors) {
|
|
90
|
+
const out = {};
|
|
91
|
+
for (const visitor of visitors) {
|
|
92
|
+
for (const [key, handler] of Object.entries(visitor)) {
|
|
93
|
+
const before = out[key];
|
|
94
|
+
out[key] = before
|
|
95
|
+
? (node) => {
|
|
96
|
+
before(node);
|
|
97
|
+
handler(node);
|
|
98
|
+
}
|
|
99
|
+
: handler;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { LintRule } from './messages.ts';
|
|
2
|
+
import type { Rule } from './types.ts';
|
|
3
|
+
export declare const rules: Record<LintRule, Rule> & {
|
|
4
|
+
graph: Rule;
|
|
5
|
+
};
|
|
6
|
+
declare const _default: {
|
|
7
|
+
meta: {
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
rules: Record<"client-only" | "max-lines" | "named-only-in" | "no-comment" | "no-cross-process-import" | "no-disable" | "no-dom-query" | "no-effect" | "no-timer" | "public-api-only" | "shared-is-pure", Rule> & {
|
|
11
|
+
graph: Rule;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { clientOnly, noCrossProcessImport, publicApiOnly, sharedIsPure } from './boundaries.js';
|
|
2
|
+
import { noDomQuery, noEffect, noTimer } from './features.js';
|
|
3
|
+
import { namedOnlyIn } from './names.js';
|
|
4
|
+
import { graph, maxLines, noComment, noDisable } from './text.js';
|
|
5
|
+
export const rules = {
|
|
6
|
+
'no-cross-process-import': noCrossProcessImport,
|
|
7
|
+
'shared-is-pure': sharedIsPure,
|
|
8
|
+
'public-api-only': publicApiOnly,
|
|
9
|
+
'no-effect': noEffect,
|
|
10
|
+
'no-timer': noTimer,
|
|
11
|
+
'no-dom-query': noDomQuery,
|
|
12
|
+
'client-only': clientOnly,
|
|
13
|
+
'no-comment': noComment,
|
|
14
|
+
'no-disable': noDisable,
|
|
15
|
+
'max-lines': maxLines,
|
|
16
|
+
'named-only-in': namedOnlyIn,
|
|
17
|
+
graph,
|
|
18
|
+
};
|
|
19
|
+
export default { meta: { name: 'ashlar' }, rules };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type AppLayout } from '../layout.ts';
|
|
2
|
+
export declare const LINT_RULES: readonly ['no-cross-process-import', 'shared-is-pure', 'public-api-only', 'no-effect', 'no-timer', 'no-dom-query', 'client-only', 'no-comment', 'no-disable', 'max-lines', 'named-only-in'];
|
|
3
|
+
export type LintRule = (typeof LINT_RULES)[number];
|
|
4
|
+
export declare const RULES: readonly ["no-cross-process-import", "shared-is-pure", "public-api-only", "no-effect", "no-timer", "no-dom-query", "client-only", "no-comment", "no-disable", "max-lines", "named-only-in", "feature-reach"];
|
|
5
|
+
export type RuleName = (typeof RULES)[number];
|
|
6
|
+
export declare const lintRulesOf: (config: {
|
|
7
|
+
rules: readonly RuleName[];
|
|
8
|
+
}) => LintRule[];
|
|
9
|
+
export declare const MESSAGES: {
|
|
10
|
+
readonly 'shared-is-pure': '`shared/` holds types and pure functions: no `node:`, React, DOM or the packages that reach the other side, and nothing that runs on import.';
|
|
11
|
+
readonly 'public-api-only': 'Import another feature or area through its `index.ts`. If you need something inside it, it belongs in its index or in `shared/`.';
|
|
12
|
+
readonly 'no-effect': '`useEffect` belongs to `client/` and `primitives/`. A feature that needs one needs a hook in `primitives/`, named for what it does, instead.';
|
|
13
|
+
readonly 'no-timer': "A timer patches over a render you don't control. Use a hook from `primitives/`, named for what it waits on.";
|
|
14
|
+
readonly 'no-dom-query': 'Reach an element by its ref, not by `querySelector`.';
|
|
15
|
+
readonly 'client-only': 'Only `client/` talks to the services.';
|
|
16
|
+
readonly 'no-comment': 'Comments go stale and nothing checks them. Rename it, or write a test. Git leads from any line to the item or task that wrote it.';
|
|
17
|
+
readonly 'no-disable': 'No comment turns a rule off. If a rule is wrong for a case, change the rule and record why in the ledger.';
|
|
18
|
+
};
|
|
19
|
+
export declare function crossProcess(app: AppLayout | null): string;
|
|
20
|
+
export declare function maxLines(limit: number): string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { names } from '../layout.js';
|
|
2
|
+
export const LINT_RULES = [
|
|
3
|
+
'no-cross-process-import',
|
|
4
|
+
'shared-is-pure',
|
|
5
|
+
'public-api-only',
|
|
6
|
+
'no-effect',
|
|
7
|
+
'no-timer',
|
|
8
|
+
'no-dom-query',
|
|
9
|
+
'client-only',
|
|
10
|
+
'no-comment',
|
|
11
|
+
'no-disable',
|
|
12
|
+
'max-lines',
|
|
13
|
+
'named-only-in',
|
|
14
|
+
];
|
|
15
|
+
export const RULES = [...LINT_RULES, 'feature-reach'];
|
|
16
|
+
export const lintRulesOf = (config) => LINT_RULES.filter((rule) => config.rules.includes(rule));
|
|
17
|
+
export const MESSAGES = {
|
|
18
|
+
'shared-is-pure': '`shared/` holds types and pure functions: no `node:`, React, DOM or the packages that reach the other side, and nothing that runs on import.',
|
|
19
|
+
'public-api-only': 'Import another feature or area through its `index.ts`. If you need something inside it, it belongs in its index or in `shared/`.',
|
|
20
|
+
'no-effect': '`useEffect` belongs to `client/` and `primitives/`. A feature that needs one needs a hook in `primitives/`, named for what it does, instead.',
|
|
21
|
+
'no-timer': "A timer patches over a render you don't control. Use a hook from `primitives/`, named for what it waits on.",
|
|
22
|
+
'no-dom-query': 'Reach an element by its ref, not by `querySelector`.',
|
|
23
|
+
'client-only': 'Only `client/` talks to the services.',
|
|
24
|
+
'no-comment': 'Comments go stale and nothing checks them. Rename it, or write a test. Git leads from any line to the item or task that wrote it.',
|
|
25
|
+
'no-disable': 'No comment turns a rule off. If a rule is wrong for a case, change the rule and record why in the ledger.',
|
|
26
|
+
};
|
|
27
|
+
export function crossProcess(app) {
|
|
28
|
+
if (!app) {
|
|
29
|
+
return 'The two processes never import each other, not even types. Put the contract in `shared/`.';
|
|
30
|
+
}
|
|
31
|
+
const folders = names(app);
|
|
32
|
+
return `\`${folders.renderer}/\` and \`${folders.main}/\` never import each other, not even types. Put the contract in \`${folders.shared}/\`.`;
|
|
33
|
+
}
|
|
34
|
+
export function maxLines(limit) {
|
|
35
|
+
return `A file over ${limit} lines costs every agent that reads it. Split it along what it does.`;
|
|
36
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { within } from '../layout.js';
|
|
2
|
+
import { found, hereOf } from './here.js';
|
|
3
|
+
const SOURCES = new Set([
|
|
4
|
+
'ImportDeclaration',
|
|
5
|
+
'ExportNamedDeclaration',
|
|
6
|
+
'ExportAllDeclaration',
|
|
7
|
+
'ImportExpression',
|
|
8
|
+
'TSExternalModuleReference',
|
|
9
|
+
'TSImportType',
|
|
10
|
+
]);
|
|
11
|
+
const escaped = (word) => word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
12
|
+
function isSource(node) {
|
|
13
|
+
const parent = node.parent;
|
|
14
|
+
if (!parent)
|
|
15
|
+
return false;
|
|
16
|
+
if (SOURCES.has(parent.type))
|
|
17
|
+
return true;
|
|
18
|
+
if (parent.type === 'TSLiteralType')
|
|
19
|
+
return isSource(parent);
|
|
20
|
+
return (parent.type === 'CallExpression' &&
|
|
21
|
+
parent.callee.type === 'Identifier' &&
|
|
22
|
+
parent.callee.name === 'require');
|
|
23
|
+
}
|
|
24
|
+
function inTestFolder(path) {
|
|
25
|
+
return path.split('/').includes('test');
|
|
26
|
+
}
|
|
27
|
+
function holds(path, places) {
|
|
28
|
+
return places.some((place) => within(path, place));
|
|
29
|
+
}
|
|
30
|
+
function textOf(node) {
|
|
31
|
+
if (node.type === 'Literal') {
|
|
32
|
+
if (typeof node.value === 'string')
|
|
33
|
+
return node.value;
|
|
34
|
+
return node.regex ? String(node.regex.pattern) : null;
|
|
35
|
+
}
|
|
36
|
+
if (node.type === 'TemplateElement')
|
|
37
|
+
return String(node.value.raw);
|
|
38
|
+
if (node.type === 'JSXText')
|
|
39
|
+
return String(node.value);
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
export function confinedHere(path, confined) {
|
|
43
|
+
return confined.filter((entry) => (entry.within.length === 0 || holds(path, entry.within)) && !holds(path, entry.only));
|
|
44
|
+
}
|
|
45
|
+
export const namedOnlyIn = {
|
|
46
|
+
meta: { type: 'problem', docs: { description: 'A confined name appears only where its config allows.' } },
|
|
47
|
+
create(context) {
|
|
48
|
+
const here = hereOf(context);
|
|
49
|
+
if (!here || here.test || inTestFolder(here.path))
|
|
50
|
+
return {};
|
|
51
|
+
const confined = confinedHere(here.path, here.settings.confined);
|
|
52
|
+
if (confined.length === 0)
|
|
53
|
+
return {};
|
|
54
|
+
const patterns = confined.map((entry) => ({
|
|
55
|
+
entry,
|
|
56
|
+
pattern: new RegExp(`\\b(?:${entry.words.map(escaped).join('|')})\\b`, 'i'),
|
|
57
|
+
}));
|
|
58
|
+
const look = (node) => {
|
|
59
|
+
const text = textOf(node);
|
|
60
|
+
if (text === null || isSource(node))
|
|
61
|
+
return;
|
|
62
|
+
const hit = patterns.find(({ pattern }) => pattern.test(text));
|
|
63
|
+
if (hit)
|
|
64
|
+
found(context, here, 'named-only-in', node.loc, hit.entry.message);
|
|
65
|
+
};
|
|
66
|
+
return { Literal: look, TemplateElement: look, JSXText: look };
|
|
67
|
+
},
|
|
68
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Context, Node } from './types.ts';
|
|
2
|
+
export declare function isValueReference(node: Node): boolean;
|
|
3
|
+
export declare function isGlobal(context: Context, node: Node): boolean;
|
|
4
|
+
export declare function isGlobalValue(context: Context, node: Node): boolean;
|
|
5
|
+
export declare function calleeName(node: Node): string | null;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const NOT_VALUES = new Set([
|
|
2
|
+
'ImportSpecifier',
|
|
3
|
+
'ImportDefaultSpecifier',
|
|
4
|
+
'ImportNamespaceSpecifier',
|
|
5
|
+
'ExportSpecifier',
|
|
6
|
+
'LabeledStatement',
|
|
7
|
+
'BreakStatement',
|
|
8
|
+
'ContinueStatement',
|
|
9
|
+
'TSTypeQuery',
|
|
10
|
+
'TSTypeReference',
|
|
11
|
+
'TSQualifiedName',
|
|
12
|
+
'TSPropertySignature',
|
|
13
|
+
'TSMethodSignature',
|
|
14
|
+
'TSInterfaceDeclaration',
|
|
15
|
+
'TSTypeAliasDeclaration',
|
|
16
|
+
'TSEnumMember',
|
|
17
|
+
'TSModuleDeclaration',
|
|
18
|
+
]);
|
|
19
|
+
export function isValueReference(node) {
|
|
20
|
+
const parent = node.parent;
|
|
21
|
+
if (!parent || NOT_VALUES.has(parent.type))
|
|
22
|
+
return false;
|
|
23
|
+
if (parent.type === 'MemberExpression')
|
|
24
|
+
return parent.object === node || parent.computed === true;
|
|
25
|
+
if (parent.type === 'Property')
|
|
26
|
+
return parent.value === node || parent.computed === true;
|
|
27
|
+
if (parent.type === 'MethodDefinition' || parent.type === 'PropertyDefinition') {
|
|
28
|
+
return parent.key !== node || parent.computed === true;
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
export function isGlobal(context, node) {
|
|
33
|
+
let scope = context.sourceCode.getScope(node);
|
|
34
|
+
while (scope) {
|
|
35
|
+
if (scope.type !== 'global' && scope.set.has(node.name))
|
|
36
|
+
return false;
|
|
37
|
+
scope = scope.upper;
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
export function isGlobalValue(context, node) {
|
|
42
|
+
return isValueReference(node) && isGlobal(context, node);
|
|
43
|
+
}
|
|
44
|
+
export function calleeName(node) {
|
|
45
|
+
const callee = node.callee;
|
|
46
|
+
if (callee.type === 'Identifier')
|
|
47
|
+
return callee.name;
|
|
48
|
+
if (callee.type === 'MemberExpression' && !callee.computed && callee.property.type === 'Identifier') {
|
|
49
|
+
return callee.property.name;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Comment, Rule } from './types.ts';
|
|
2
|
+
export declare function turnsARuleOff(comment: Comment): boolean;
|
|
3
|
+
export declare const noComment: Rule;
|
|
4
|
+
export declare const noDisable: Rule;
|
|
5
|
+
export declare function lineCount(lines: string[]): number;
|
|
6
|
+
export declare const maxLines: Rule;
|
|
7
|
+
export declare const graph: Rule;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { found, hereOf } from './here.js';
|
|
2
|
+
import { exportsVisitor } from './exports.js';
|
|
3
|
+
import { importVisitor, merge } from './imports.js';
|
|
4
|
+
import { maxLines as maxLinesMessage, MESSAGES } from './messages.js';
|
|
5
|
+
const DISABLE = /^[\s*]*(?:(?:eslint|oxlint)-disable(?:-next-line|-line)?|biome-ignore\S*)(?:\s|$)/;
|
|
6
|
+
const TS_DISABLE = /^[\s/*]*@ts-(?:ignore|nocheck|expect-error)\b/;
|
|
7
|
+
const TRIPLE_SLASH = /^\/\s*<(?:reference|amd-module|amd-dependency)\b/;
|
|
8
|
+
export function turnsARuleOff(comment) {
|
|
9
|
+
return DISABLE.test(comment.value) || TS_DISABLE.test(comment.value);
|
|
10
|
+
}
|
|
11
|
+
function isDirective(comment) {
|
|
12
|
+
return comment.type === 'Shebang' || (comment.type === 'Line' && TRIPLE_SLASH.test(comment.value));
|
|
13
|
+
}
|
|
14
|
+
export const noComment = {
|
|
15
|
+
meta: { type: 'problem', docs: { description: 'Code carries no comments.' } },
|
|
16
|
+
create(context) {
|
|
17
|
+
const here = hereOf(context);
|
|
18
|
+
if (!here)
|
|
19
|
+
return {};
|
|
20
|
+
return {
|
|
21
|
+
Program() {
|
|
22
|
+
for (const comment of context.sourceCode.getAllComments()) {
|
|
23
|
+
if (isDirective(comment) || turnsARuleOff(comment))
|
|
24
|
+
continue;
|
|
25
|
+
const lines = comment.loc.end.line - comment.loc.start.line + 1;
|
|
26
|
+
found(context, here, 'no-comment', comment.loc, MESSAGES['no-comment'], lines);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
export const noDisable = {
|
|
33
|
+
meta: { type: 'problem', docs: { description: 'No comment turns a rule off.' } },
|
|
34
|
+
create(context) {
|
|
35
|
+
const here = hereOf(context);
|
|
36
|
+
if (!here)
|
|
37
|
+
return {};
|
|
38
|
+
return {
|
|
39
|
+
Program() {
|
|
40
|
+
for (const comment of context.sourceCode.getAllComments()) {
|
|
41
|
+
if (turnsARuleOff(comment))
|
|
42
|
+
found(context, here, 'no-disable', comment.loc, MESSAGES['no-disable']);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
export function lineCount(lines) {
|
|
49
|
+
return lines.length > 0 && lines[lines.length - 1] === '' ? lines.length - 1 : lines.length;
|
|
50
|
+
}
|
|
51
|
+
export const maxLines = {
|
|
52
|
+
meta: { type: 'problem', docs: { description: 'Files stay short enough to read.' } },
|
|
53
|
+
create(context) {
|
|
54
|
+
const here = hereOf(context);
|
|
55
|
+
if (!here)
|
|
56
|
+
return {};
|
|
57
|
+
const limit = here.settings.maxLines;
|
|
58
|
+
return {
|
|
59
|
+
Program() {
|
|
60
|
+
const count = lineCount(context.sourceCode.lines);
|
|
61
|
+
if (count <= limit)
|
|
62
|
+
return;
|
|
63
|
+
const loc = { start: { line: limit + 1, column: 0 }, end: { line: count, column: 0 } };
|
|
64
|
+
found(context, here, 'max-lines', loc, maxLinesMessage(limit), count - limit);
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
export const graph = {
|
|
70
|
+
meta: { type: 'problem', docs: { description: 'Records the import graph.' } },
|
|
71
|
+
create(context) {
|
|
72
|
+
const here = hereOf(context);
|
|
73
|
+
if (!here)
|
|
74
|
+
return {};
|
|
75
|
+
const exports = (here.findings.exports ??= []);
|
|
76
|
+
return merge(importVisitor(({ specifier, type, takes, passes }) => {
|
|
77
|
+
const target = here.resolve(specifier);
|
|
78
|
+
if (target && target !== here.path)
|
|
79
|
+
here.findings.edges.push({
|
|
80
|
+
to: target,
|
|
81
|
+
type,
|
|
82
|
+
...(takes !== undefined && { takes }),
|
|
83
|
+
...(passes && { passes }),
|
|
84
|
+
});
|
|
85
|
+
}), exportsVisitor((name) => exports.push(name)));
|
|
86
|
+
},
|
|
87
|
+
};
|