@zgeoff/oxlint-config 0.9.0 → 0.10.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 -0
- package/build-import-settings.js +5 -0
- package/collect-entry-targets.js +41 -0
- package/collect-sql-writes.js +19 -0
- package/collect-written-tables.js +14 -0
- package/feature-folders.js +173 -0
- package/find-feature-folder.js +18 -0
- package/function-verb.js +13 -2
- package/is-in-test-utils.js +7 -0
- package/oxlintrc.json +3 -0
- package/package.json +23 -3
- package/pick-folder-kind.js +13 -0
- package/pick-loose-module-message.js +7 -0
- package/plugin.js +7 -0
- package/read-folder-sources.js +12 -0
- package/read-loose-modules.js +22 -0
- package/read-module-paths.js +12 -0
- package/read-package-manifest.js +14 -0
- package/read-stale-pending.js +72 -0
- package/resolve-import-target.js +6 -5
- package/resolve-repo-path.js +6 -0
- package/resolve-source-package.js +25 -0
- package/seed-only.js +168 -0
- package/test-beside-module.js +1 -1
- package/test-beside-seed.js +49 -0
- package/to-table-name.js +15 -0
- package/verb-contract.js +1 -0
package/README.md
CHANGED
|
@@ -75,11 +75,17 @@ The plugin is addressable on its own at `@zgeoff/oxlint-config/plugin` for confi
|
|
|
75
75
|
- Test files: a test sits beside its module, holds only `setupTest()` and its tests, uses inline
|
|
76
76
|
snapshots, keeps each timeout within its lane's limit, and waits on a condition, never a sleep.
|
|
77
77
|
See [test-file rules](../../docs/architecture/oxlint-config-tests.md).
|
|
78
|
+
- Seeding: test code writes database rows only where the testing skill's seeding rules allow, and
|
|
79
|
+
each seed has a test beside it. See
|
|
80
|
+
[seeding rules](../../docs/architecture/oxlint-config-seeding.md).
|
|
78
81
|
- Require functions: `zgeoff/no-require` bans the `require` global and `createRequire`, and
|
|
79
82
|
`import/no-commonjs` bans CommonJS exports. See
|
|
80
83
|
[require functions](../../docs/architecture/oxlint-config.md#require-functions).
|
|
81
84
|
- Import boundaries: `zgeoff/import-zones` fails an import that crosses a declared zone boundary.
|
|
82
85
|
See [import zones](../../docs/architecture/oxlint-config-import-zones.md).
|
|
86
|
+
- Feature folders: `zgeoff/feature-folders` caps the loose modules at the root of a package's
|
|
87
|
+
`src/`, and keeps shared code in `src/utils/`. See
|
|
88
|
+
[feature folders](../../docs/architecture/oxlint-config-feature-folders.md).
|
|
83
89
|
|
|
84
90
|
## Configuration
|
|
85
91
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
|
|
3
|
+
export default function collectEntryTargets(directory, manifest) {
|
|
4
|
+
const targets = [
|
|
5
|
+
manifest.main,
|
|
6
|
+
manifest.module,
|
|
7
|
+
...collectStringLeaves(manifest.bin),
|
|
8
|
+
...collectStringLeaves(manifest.exports),
|
|
9
|
+
...Object.values(manifest.scripts ?? {}).flatMap((script) => collectScriptPaths(script)),
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
return new Set(
|
|
13
|
+
targets
|
|
14
|
+
.filter((target) => typeof target === 'string' && !target.includes('*'))
|
|
15
|
+
.map((target) => resolve(directory, target)),
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function collectStringLeaves(value) {
|
|
20
|
+
if (typeof value === 'string') {
|
|
21
|
+
return [value];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (typeof value !== 'object' || value === null) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return Object.values(value).flatMap((leaf) => collectStringLeaves(leaf));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function collectScriptPaths(script) {
|
|
32
|
+
if (typeof script !== 'string') {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return script
|
|
37
|
+
.split(/\s+/u)
|
|
38
|
+
.map((word) => word.replaceAll(/["']/gu, ''))
|
|
39
|
+
.map((word) => word.slice(word.lastIndexOf('=') + 1))
|
|
40
|
+
.filter((word) => word !== '');
|
|
41
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import toTableName from './to-table-name.js';
|
|
2
|
+
|
|
3
|
+
const tablePattern = String.raw`(?<table>[^\s(),;'\x60]+)`;
|
|
4
|
+
|
|
5
|
+
const sqlWritePatterns = [
|
|
6
|
+
new RegExp(String.raw`\binsert\s+(?:or\s+[a-z]+\s+)?into\s+${tablePattern}`, 'giu'),
|
|
7
|
+
new RegExp(String.raw`(?<!\bor\s+)\breplace\s+into\s+${tablePattern}`, 'giu'),
|
|
8
|
+
new RegExp(
|
|
9
|
+
String.raw`\bupdate\s+(?:or\s+[a-z]+\s+)?${tablePattern}(?:\s+(?:as\s+)?\w+)?\s+set\b`,
|
|
10
|
+
'giu',
|
|
11
|
+
),
|
|
12
|
+
new RegExp(String.raw`\bdelete\s+from\s+${tablePattern}`, 'giu'),
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
export default function collectSQLWrites(text) {
|
|
16
|
+
return sqlWritePatterns.flatMap((pattern) =>
|
|
17
|
+
[...text.matchAll(pattern)].map((match) => toTableName(match.groups.table)),
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import collectSQLWrites from './collect-sql-writes.js';
|
|
2
|
+
import toTableName from './to-table-name.js';
|
|
3
|
+
|
|
4
|
+
const kyselyWritePattern =
|
|
5
|
+
/\.\s*(?:insertInto|updateTable|deleteFrom)\(\s*(?<quote>['"`])(?<table>[^'"`]+)\k<quote>/gu;
|
|
6
|
+
|
|
7
|
+
// reads a module as plain text, so a write in a comment counts too
|
|
8
|
+
export default function collectWrittenTables(text) {
|
|
9
|
+
const kyselyTables = [...text.matchAll(kyselyWritePattern)].map((match) =>
|
|
10
|
+
toTableName(match.groups.table),
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
return [...kyselyTables, ...collectSQLWrites(text)].filter((table) => table !== null);
|
|
14
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { basename, join, posix, relative, sep } from 'node:path';
|
|
2
|
+
import buildImportSettings from './build-import-settings.js';
|
|
3
|
+
import findFeatureFolder from './find-feature-folder.js';
|
|
4
|
+
import pickFolderKind from './pick-folder-kind.js';
|
|
5
|
+
import pickLooseModuleMessage from './pick-loose-module-message.js';
|
|
6
|
+
import readLooseModules from './read-loose-modules.js';
|
|
7
|
+
import readStalePending from './read-stale-pending.js';
|
|
8
|
+
import resolveImportTarget from './resolve-import-target.js';
|
|
9
|
+
import resolveRepoRoot from './resolve-repo-root.js';
|
|
10
|
+
import resolveSourcePackage from './resolve-source-package.js';
|
|
11
|
+
|
|
12
|
+
const looseModuleLimit = 8;
|
|
13
|
+
|
|
14
|
+
const capLine = `{{source}} holds {{count}} loose modules, and the limit is ${looseModuleLimit}. Group them into one folder per thing the package does:`;
|
|
15
|
+
|
|
16
|
+
const exampleTree = `
|
|
17
|
+
|
|
18
|
+
src/
|
|
19
|
+
index.ts cli.ts index.ts, types.ts, constants.ts and the files package.json names stay
|
|
20
|
+
invoices/ create-invoice.ts format-invoice-total.ts
|
|
21
|
+
payments/ charge-card.ts refund-payment.ts
|
|
22
|
+
utils/ to-cents.ts code that several folders share`;
|
|
23
|
+
|
|
24
|
+
// a report on one file per repo shows once per run, and an editor's
|
|
25
|
+
// language server keeps it on that file across edits
|
|
26
|
+
const anchorFiles = new Map();
|
|
27
|
+
|
|
28
|
+
const featureFolders = {
|
|
29
|
+
meta: {
|
|
30
|
+
type: 'suggestion',
|
|
31
|
+
messages: {
|
|
32
|
+
capExample: `${capLine}${exampleTree}`,
|
|
33
|
+
cap: capLine,
|
|
34
|
+
synonym: '{{folder}} is a shared folder under another name; rename it to src/utils/.',
|
|
35
|
+
utilsImport:
|
|
36
|
+
'{{from}} imports {{to}}, and utils/ sits below every feature folder. Move {{target}} into utils/, or move {{module}} into {{feature}}/.',
|
|
37
|
+
pendingPasses:
|
|
38
|
+
'`{{entry}}` in the `pending` option of zgeoff/feature-folders now passes the rule; remove it from `pending`.',
|
|
39
|
+
pendingMissing:
|
|
40
|
+
'`{{entry}}` in the `pending` option of zgeoff/feature-folders names no package; remove it from `pending`.',
|
|
41
|
+
},
|
|
42
|
+
schema: [
|
|
43
|
+
{
|
|
44
|
+
type: 'object',
|
|
45
|
+
properties: { pending: { type: 'array', items: { type: 'string' } } },
|
|
46
|
+
additionalProperties: false,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
create(context) {
|
|
51
|
+
const filename = context.physicalFilename;
|
|
52
|
+
const root = resolveRepoRoot(filename) ?? context.cwd;
|
|
53
|
+
const pending = (context.options[0]?.pending ?? []).map((entry) => toPendingPath(entry));
|
|
54
|
+
const sourcePackage = resolveSourcePackage(filename);
|
|
55
|
+
const isChecked =
|
|
56
|
+
sourcePackage !== null && !pending.includes(toRootPath(root, sourcePackage.directory));
|
|
57
|
+
|
|
58
|
+
if (!anchorFiles.has(root)) {
|
|
59
|
+
anchorFiles.set(root, filename);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const file = { context, filename, root, sourcePackage };
|
|
63
|
+
const visitors =
|
|
64
|
+
isChecked && pickFolderKind(sourcePackage.path.split('/')[0]) === 'utils'
|
|
65
|
+
? buildUtilsVisitors(file)
|
|
66
|
+
: {};
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
...visitors,
|
|
70
|
+
Program(program) {
|
|
71
|
+
const start = program.body[0]?.loc.start ?? { line: 1, column: 0 };
|
|
72
|
+
const at = { loc: { start, end: start } };
|
|
73
|
+
|
|
74
|
+
if (anchorFiles.get(root) === filename) {
|
|
75
|
+
for (const stale of readStalePending(root, pending, looseModuleLimit)) {
|
|
76
|
+
context.report({ ...at, messageId: stale.messageId, data: { entry: stale.entry } });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (isChecked) {
|
|
81
|
+
checkLooseModule(file, at);
|
|
82
|
+
checkSynonymFolder(file, at);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export default featureFolders;
|
|
90
|
+
|
|
91
|
+
function toPendingPath(entry) {
|
|
92
|
+
return posix.normalize(entry).replace(/(?<=.)\/+$/u, '');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function toRootPath(root, path) {
|
|
96
|
+
return relative(root, path).split(sep).join('/') || '.';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function buildUtilsVisitors(file) {
|
|
100
|
+
const settings = buildImportSettings(file.root);
|
|
101
|
+
const check = (node) => {
|
|
102
|
+
if (node.source?.type === 'Literal' && typeof node.source.value === 'string') {
|
|
103
|
+
checkUtilsImport(file, { node, specifier: node.source.value, settings });
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
ImportDeclaration: check,
|
|
109
|
+
ExportNamedDeclaration: check,
|
|
110
|
+
ExportAllDeclaration: check,
|
|
111
|
+
ImportExpression: check,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function checkUtilsImport(file, imported) {
|
|
116
|
+
const target = resolveImportTarget(file.filename, imported.specifier, imported.settings);
|
|
117
|
+
const source = join(file.sourcePackage.directory, 'src');
|
|
118
|
+
|
|
119
|
+
if (target.kind !== 'file') {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const feature = findFeatureFolder(source, target.path);
|
|
124
|
+
|
|
125
|
+
if (feature === null) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
file.context.report({
|
|
130
|
+
node: imported.node,
|
|
131
|
+
messageId: 'utilsImport',
|
|
132
|
+
data: {
|
|
133
|
+
from: toRootPath(file.root, file.filename),
|
|
134
|
+
to: `src/${toRootPath(source, target.path)}`,
|
|
135
|
+
target: basename(target.path),
|
|
136
|
+
module: basename(file.filename),
|
|
137
|
+
feature,
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function checkLooseModule(file, at) {
|
|
143
|
+
if (file.sourcePackage.path.includes('/')) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const modules = readLooseModules(file.sourcePackage);
|
|
148
|
+
const messageID = pickLooseModuleMessage(modules, basename(file.filename), looseModuleLimit);
|
|
149
|
+
|
|
150
|
+
if (messageID === null) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const source = `${toRootPath(file.root, join(file.sourcePackage.directory, 'src'))}/`;
|
|
155
|
+
|
|
156
|
+
file.context.report({
|
|
157
|
+
...at,
|
|
158
|
+
messageId: messageID,
|
|
159
|
+
data: { source, count: String(modules.length) },
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function checkSynonymFolder(file, at) {
|
|
164
|
+
const [folder] = file.sourcePackage.path.split('/');
|
|
165
|
+
|
|
166
|
+
if (!file.sourcePackage.path.includes('/') || pickFolderKind(folder) !== 'synonym') {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const path = toRootPath(file.root, join(file.sourcePackage.directory, 'src', folder));
|
|
171
|
+
|
|
172
|
+
file.context.report({ ...at, messageId: 'synonym', data: { folder: `${path}/` } });
|
|
173
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isAbsolute, relative, sep } from 'node:path';
|
|
2
|
+
import pickFolderKind from './pick-folder-kind.js';
|
|
3
|
+
|
|
4
|
+
export default function findFeatureFolder(source, target) {
|
|
5
|
+
const path = relative(source, target);
|
|
6
|
+
const segments = path.split(sep);
|
|
7
|
+
|
|
8
|
+
if (
|
|
9
|
+
isAbsolute(path) ||
|
|
10
|
+
segments.length < 2 ||
|
|
11
|
+
segments[0] === '..' ||
|
|
12
|
+
pickFolderKind(segments[0]) !== 'feature'
|
|
13
|
+
) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return segments[0];
|
|
18
|
+
}
|
package/function-verb.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import findFunctionName from './find-function-name.js';
|
|
2
|
+
import isInTestUtils from './is-in-test-utils.js';
|
|
2
3
|
import isVerbMatch from './is-verb-match.js';
|
|
4
|
+
import resolveRepoPath from './resolve-repo-path.js';
|
|
3
5
|
|
|
4
6
|
const functionVerb = {
|
|
5
7
|
meta: {
|
|
@@ -8,6 +10,8 @@ const functionVerb = {
|
|
|
8
10
|
bannedVerb: "'{{name}}' starts with the banned verb '{{verb}}' — use `{{replacement}}`.",
|
|
9
11
|
vagueVerb: "'{{name}}' starts with the banned verb '{{verb}}' — name what the function does.",
|
|
10
12
|
bareTemplate: "'{{name}}' is a bare prefix — add what it applies to, as in `{{name}}Thing`.",
|
|
13
|
+
seedOutsideTestUtils:
|
|
14
|
+
"'{{name}}' starts with 'seed', which only test code in a `test-utils` folder may use — move the seed to the package's `src/test-utils/`, or name what the function does.",
|
|
11
15
|
},
|
|
12
16
|
schema: [
|
|
13
17
|
{
|
|
@@ -22,9 +26,12 @@ const functionVerb = {
|
|
|
22
26
|
create(context) {
|
|
23
27
|
const exemptNames = new Set(context.options[0]?.exemptNames);
|
|
24
28
|
|
|
29
|
+
const probeSeedAllowed = () =>
|
|
30
|
+
isInTestUtils(resolveRepoPath(context.physicalFilename, context.cwd));
|
|
31
|
+
|
|
25
32
|
const checkFunction = (node) => {
|
|
26
33
|
const id = findFunctionName(node);
|
|
27
|
-
const report = id === null ? null : planReport(id.name, exemptNames);
|
|
34
|
+
const report = id === null ? null : planReport(id.name, exemptNames, probeSeedAllowed);
|
|
28
35
|
|
|
29
36
|
if (report !== null) {
|
|
30
37
|
context.report({ node: id, messageId: report.messageId, data: report.data });
|
|
@@ -43,11 +50,15 @@ export default functionVerb;
|
|
|
43
50
|
|
|
44
51
|
const suffixRequiredVerbs = new Set(['to', 'with', 'make', 'use', 'on']);
|
|
45
52
|
|
|
46
|
-
function planReport(name, exemptNames) {
|
|
53
|
+
function planReport(name, exemptNames, probeSeedAllowed) {
|
|
47
54
|
if (exemptNames.has(name) || !/^[a-z]/u.test(name)) {
|
|
48
55
|
return null;
|
|
49
56
|
}
|
|
50
57
|
|
|
58
|
+
if (isVerbMatch(name, 'seed') && !probeSeedAllowed()) {
|
|
59
|
+
return { messageId: 'seedOutsideTestUtils', data: { name } };
|
|
60
|
+
}
|
|
61
|
+
|
|
51
62
|
if (suffixRequiredVerbs.has(name)) {
|
|
52
63
|
return { messageId: 'bareTemplate', data: { name } };
|
|
53
64
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { sep } from 'node:path';
|
|
2
|
+
|
|
3
|
+
// takes the path below the repo root, so a checkout inside a folder named `test-utils` does not
|
|
4
|
+
// count every file as test code
|
|
5
|
+
export default function isInTestUtils(repoPath) {
|
|
6
|
+
return repoPath.split(sep).includes('test-utils');
|
|
7
|
+
}
|
package/oxlintrc.json
CHANGED
|
@@ -42,6 +42,9 @@
|
|
|
42
42
|
"zgeoff/no-test-sleep": "error",
|
|
43
43
|
"zgeoff/no-require": "error",
|
|
44
44
|
"zgeoff/test-shape": "error",
|
|
45
|
+
"zgeoff/feature-folders": "error",
|
|
46
|
+
"zgeoff/seed-only": "error",
|
|
47
|
+
"zgeoff/test-beside-seed": "error",
|
|
45
48
|
|
|
46
49
|
// name a value for what it holds, in full words: one letter only for a
|
|
47
50
|
// coordinate, zod's `z`, Bun's shell `$` or an unread `_` placeholder, and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zgeoff/oxlint-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Shareable oxlint config: strict categories, house-style rules, and a custom JS plugin",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -59,6 +59,25 @@
|
|
|
59
59
|
"get-zone-options.js",
|
|
60
60
|
"make-glob-matcher.js",
|
|
61
61
|
"resolve-import-target.js",
|
|
62
|
+
"feature-folders.js",
|
|
63
|
+
"pick-folder-kind.js",
|
|
64
|
+
"pick-loose-module-message.js",
|
|
65
|
+
"collect-entry-targets.js",
|
|
66
|
+
"read-loose-modules.js",
|
|
67
|
+
"resolve-source-package.js",
|
|
68
|
+
"find-feature-folder.js",
|
|
69
|
+
"build-import-settings.js",
|
|
70
|
+
"read-stale-pending.js",
|
|
71
|
+
"read-package-manifest.js",
|
|
72
|
+
"read-module-paths.js",
|
|
73
|
+
"seed-only.js",
|
|
74
|
+
"test-beside-seed.js",
|
|
75
|
+
"read-folder-sources.js",
|
|
76
|
+
"collect-written-tables.js",
|
|
77
|
+
"collect-sql-writes.js",
|
|
78
|
+
"to-table-name.js",
|
|
79
|
+
"resolve-repo-path.js",
|
|
80
|
+
"is-in-test-utils.js",
|
|
62
81
|
"index.js"
|
|
63
82
|
],
|
|
64
83
|
"type": "module",
|
|
@@ -83,8 +102,9 @@
|
|
|
83
102
|
},
|
|
84
103
|
"devDependencies": {
|
|
85
104
|
"@types/bun": "1.4.4",
|
|
86
|
-
"@zgeoff/rig": "0.2.
|
|
87
|
-
"@zgeoff/
|
|
105
|
+
"@zgeoff/rig": "0.2.1",
|
|
106
|
+
"@zgeoff/std": "0.4.3",
|
|
107
|
+
"@zgeoff/testing": "0.3.0",
|
|
88
108
|
"tsrs": "0.18.0-ts7.1.0-dev.20260929",
|
|
89
109
|
"typescript": "7.0.2"
|
|
90
110
|
},
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const folderKinds = new Map([
|
|
2
|
+
['utils', 'utils'],
|
|
3
|
+
['test-utils', 'exempt'],
|
|
4
|
+
['generated', 'exempt'],
|
|
5
|
+
['lib', 'synonym'],
|
|
6
|
+
['shared', 'synonym'],
|
|
7
|
+
['helpers', 'synonym'],
|
|
8
|
+
['common', 'synonym'],
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
export default function pickFolderKind(name) {
|
|
12
|
+
return folderKinds.get(name) ?? 'feature';
|
|
13
|
+
}
|
package/plugin.js
CHANGED
|
@@ -2,6 +2,7 @@ import { existsSync } from 'node:fs';
|
|
|
2
2
|
// oxlint-disable-next-line zgeoff/no-require -- only resolves rig's path from the repo root; an import loads it
|
|
3
3
|
import { createRequire } from 'node:module';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
+
import featureFolders from './feature-folders.js';
|
|
5
6
|
import functionVerb from './function-verb.js';
|
|
6
7
|
import importZones from './import-zones.js';
|
|
7
8
|
import maxConsecutiveLineComments from './max-consecutive-line-comments.js';
|
|
@@ -16,10 +17,13 @@ import noJSDoc from './no-jsdoc.js';
|
|
|
16
17
|
import noRequire from './no-require.js';
|
|
17
18
|
import noRestrictedWords from './no-restricted-words.js';
|
|
18
19
|
import noTestSleep from './no-test-sleep.js';
|
|
20
|
+
import readFolderSources from './read-folder-sources.js';
|
|
19
21
|
import readRigLanes from './read-rig-lanes.js';
|
|
20
22
|
import resolveRepoRoot from './resolve-repo-root.js';
|
|
23
|
+
import buildSeedOnly from './seed-only.js';
|
|
21
24
|
import setupTestOnly from './setup-test-only.js';
|
|
22
25
|
import buildTestBesideModule from './test-beside-module.js';
|
|
26
|
+
import testBesideSeed from './test-beside-seed.js';
|
|
23
27
|
import testShape from './test-shape.js';
|
|
24
28
|
import testTimeoutExceptionTicket from './test-timeout-exception-ticket.js';
|
|
25
29
|
import verbContract from './verb-contract.js';
|
|
@@ -131,6 +135,9 @@ const plugin = {
|
|
|
131
135
|
'no-require': noRequire,
|
|
132
136
|
'test-shape': testShape,
|
|
133
137
|
'import-zones': importZones,
|
|
138
|
+
'feature-folders': featureFolders,
|
|
139
|
+
'seed-only': buildSeedOnly(readFolderSources),
|
|
140
|
+
'test-beside-seed': testBesideSeed,
|
|
134
141
|
},
|
|
135
142
|
};
|
|
136
143
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { readFileSync, readdirSync, statSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
const sourcePattern = /\.[cm]?[jt]sx?$/u;
|
|
5
|
+
const skippedPattern = /\.test\.[cm]?[jt]sx?$|\.d\.[cm]?ts$/u;
|
|
6
|
+
|
|
7
|
+
export default function readFolderSources(directory) {
|
|
8
|
+
return readdirSync(directory)
|
|
9
|
+
.filter((name) => sourcePattern.test(name) && !skippedPattern.test(name))
|
|
10
|
+
.filter((name) => statSync(join(directory, name), { throwIfNoEntry: false })?.isFile() ?? false)
|
|
11
|
+
.map((name) => ({ name, text: readFileSync(join(directory, name), 'utf8') }));
|
|
12
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { readdirSync } from 'node:fs';
|
|
2
|
+
import { basename, join } from 'node:path';
|
|
3
|
+
import collectEntryTargets from './collect-entry-targets.js';
|
|
4
|
+
import readModulePaths from './read-module-paths.js';
|
|
5
|
+
|
|
6
|
+
export default function readLooseModules(sourcePackage) {
|
|
7
|
+
const targets = collectEntryTargets(sourcePackage.directory, sourcePackage.manifest);
|
|
8
|
+
const entries = readdirSync(join(sourcePackage.directory, 'src'), { withFileTypes: true });
|
|
9
|
+
|
|
10
|
+
return readModulePaths(entries)
|
|
11
|
+
.filter((path) => !targets.has(path) && isCountedModule(basename(path)))
|
|
12
|
+
.map((path) => basename(path))
|
|
13
|
+
.toSorted();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const declarationPattern = /\.d\.[cm]?ts$/u;
|
|
17
|
+
const testPattern = /\.(?:test|bench|spec)\.[cm]?[jt]sx?$/u;
|
|
18
|
+
const exemptPattern = /^(?:index|types|constants)\.[cm]?[jt]sx?$/u;
|
|
19
|
+
|
|
20
|
+
function isCountedModule(name) {
|
|
21
|
+
return !declarationPattern.test(name) && !testPattern.test(name) && !exemptPattern.test(name);
|
|
22
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { statSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
const modulePattern = /\.[cm]?[jt]sx?$/u;
|
|
5
|
+
|
|
6
|
+
// takes readdir entries and follows a symlink, so a linked module counts as the file it points at
|
|
7
|
+
export default function readModulePaths(entries) {
|
|
8
|
+
return entries
|
|
9
|
+
.filter((entry) => modulePattern.test(entry.name))
|
|
10
|
+
.map((entry) => join(entry.parentPath, entry.name))
|
|
11
|
+
.filter((path) => statSync(path, { throwIfNoEntry: false })?.isFile() ?? false);
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
// a manifest that does not parse to an object names no entry files, and lint goes on; the package
|
|
5
|
+
// manager reports the broken file itself
|
|
6
|
+
export default function readPackageManifest(directory) {
|
|
7
|
+
try {
|
|
8
|
+
const manifest = JSON.parse(readFileSync(join(directory, 'package.json'), 'utf8'));
|
|
9
|
+
|
|
10
|
+
return typeof manifest === 'object' && manifest !== null ? manifest : {};
|
|
11
|
+
} catch {
|
|
12
|
+
return {};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import buildImportSettings from './build-import-settings.js';
|
|
4
|
+
import findFeatureFolder from './find-feature-folder.js';
|
|
5
|
+
import pickFolderKind from './pick-folder-kind.js';
|
|
6
|
+
import readLooseModules from './read-loose-modules.js';
|
|
7
|
+
import readModulePaths from './read-module-paths.js';
|
|
8
|
+
import readPackageManifest from './read-package-manifest.js';
|
|
9
|
+
import resolveImportTarget from './resolve-import-target.js';
|
|
10
|
+
|
|
11
|
+
export default function readStalePending(root, pending, limit) {
|
|
12
|
+
return pending.flatMap((entry) => {
|
|
13
|
+
const directory = join(root, entry);
|
|
14
|
+
|
|
15
|
+
if (!existsSync(join(directory, 'package.json'))) {
|
|
16
|
+
return [{ entry, messageId: 'pendingMissing' }];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return probePackagePassing(root, directory, limit)
|
|
20
|
+
? [{ entry, messageId: 'pendingPasses' }]
|
|
21
|
+
: [];
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function probePackagePassing(root, directory, limit) {
|
|
26
|
+
const source = join(directory, 'src');
|
|
27
|
+
|
|
28
|
+
if (!existsSync(source)) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const manifest = readPackageManifest(directory);
|
|
33
|
+
const synonyms = readdirSync(source, { withFileTypes: true }).filter(
|
|
34
|
+
(entry) => entry.isDirectory() && pickFolderKind(entry.name) === 'synonym',
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
readLooseModules({ directory, manifest }).length <= limit &&
|
|
39
|
+
!synonyms.some((folder) => readFolderModules(join(source, folder.name)).length > 0) &&
|
|
40
|
+
!probeUtilsFeatureImport(root, source)
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function readFolderModules(folder) {
|
|
45
|
+
return existsSync(folder)
|
|
46
|
+
? readModulePaths(readdirSync(folder, { recursive: true, withFileTypes: true }))
|
|
47
|
+
: [];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// a text scan stands in for the parse that only the linted file gets: comments go first, so a
|
|
51
|
+
// specifier that only a string holds is the one case that keeps the entry
|
|
52
|
+
const commentPattern =
|
|
53
|
+
/(?<text>"(?:\\.|[^"\\\n])*"|'(?:\\.|[^'\\\n])*')|\/\/[^\n]*|\/\*[\s\S]*?\*\//gu;
|
|
54
|
+
const specifierPattern =
|
|
55
|
+
/(?:\bfrom|\bimport)\s*\(?\s*(?<quote>["'])(?<specifier>[^"'\n]+)\k<quote>/gu;
|
|
56
|
+
|
|
57
|
+
function probeUtilsFeatureImport(root, source) {
|
|
58
|
+
const settings = buildImportSettings(root);
|
|
59
|
+
|
|
60
|
+
return readFolderModules(join(source, 'utils')).some((filename) => {
|
|
61
|
+
const text = readFileSync(filename, 'utf8').replaceAll(
|
|
62
|
+
commentPattern,
|
|
63
|
+
(...match) => match.at(-1).text ?? '',
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
return [...text.matchAll(specifierPattern)].some((match) => {
|
|
67
|
+
const target = resolveImportTarget(filename, match.groups.specifier, settings);
|
|
68
|
+
|
|
69
|
+
return target.kind === 'file' && findFeatureFolder(source, target.path) !== null;
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
package/resolve-import-target.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { existsSync,
|
|
1
|
+
import { existsSync, statSync } from 'node:fs';
|
|
2
2
|
import { isBuiltin } from 'node:module';
|
|
3
3
|
import { dirname, join, resolve } from 'node:path';
|
|
4
|
+
import readPackageManifest from './read-package-manifest.js';
|
|
4
5
|
|
|
5
6
|
export default function resolveImportTarget(filename, specifier, settings) {
|
|
6
7
|
if (isPathSpecifier(specifier)) {
|
|
7
8
|
return toTarget(resolveImportedFile(filename, toFileSpecifier(specifier), settings.extensions));
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
const manifest =
|
|
11
|
+
const manifest = resolveNearestManifest(dirname(filename), settings.root);
|
|
11
12
|
|
|
12
13
|
return resolveManifestTarget(manifest, specifier, settings);
|
|
13
14
|
}
|
|
@@ -54,7 +55,7 @@ function toFileSpecifier(specifier) {
|
|
|
54
55
|
|
|
55
56
|
const manifests = new Map();
|
|
56
57
|
|
|
57
|
-
function
|
|
58
|
+
function resolveNearestManifest(directory, root) {
|
|
58
59
|
if (manifests.has(directory)) {
|
|
59
60
|
return manifests.get(directory);
|
|
60
61
|
}
|
|
@@ -64,9 +65,9 @@ function readPackageManifest(directory, root) {
|
|
|
64
65
|
let manifest = null;
|
|
65
66
|
|
|
66
67
|
if (existsSync(path)) {
|
|
67
|
-
manifest = { directory, ...
|
|
68
|
+
manifest = { directory, ...readPackageManifest(directory) };
|
|
68
69
|
} else if (directory !== root && parent !== directory) {
|
|
69
|
-
manifest =
|
|
70
|
+
manifest = resolveNearestManifest(parent, root);
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
manifests.set(directory, manifest);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { dirname, join, relative, sep } from 'node:path';
|
|
3
|
+
import readPackageManifest from './read-package-manifest.js';
|
|
4
|
+
|
|
5
|
+
// the package is the nearest folder above the file whose `src/` holds it, so a `package.json` inside
|
|
6
|
+
// `src/`, such as one that sets `type`, does not stand in for the package
|
|
7
|
+
export default function resolveSourcePackage(filename) {
|
|
8
|
+
let directory = dirname(filename);
|
|
9
|
+
|
|
10
|
+
while (true) {
|
|
11
|
+
const path = relative(join(directory, 'src'), filename).split(sep).join('/');
|
|
12
|
+
|
|
13
|
+
if (!path.startsWith('../') && existsSync(join(directory, 'package.json'))) {
|
|
14
|
+
return { directory, manifest: readPackageManifest(directory), path };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const parent = dirname(directory);
|
|
18
|
+
|
|
19
|
+
if (parent === directory) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
directory = parent;
|
|
24
|
+
}
|
|
25
|
+
}
|
package/seed-only.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { basename, dirname } from 'node:path';
|
|
2
|
+
import collectSQLWrites from './collect-sql-writes.js';
|
|
3
|
+
import collectWrittenTables from './collect-written-tables.js';
|
|
4
|
+
import findBunTestName from './find-bun-test-name.js';
|
|
5
|
+
import findChainRoot from './find-chain-root.js';
|
|
6
|
+
import findFunctionName from './find-function-name.js';
|
|
7
|
+
import isInTestUtils from './is-in-test-utils.js';
|
|
8
|
+
import isVerbMatch from './is-verb-match.js';
|
|
9
|
+
import resolveRepoPath from './resolve-repo-path.js';
|
|
10
|
+
import toTableName from './to-table-name.js';
|
|
11
|
+
|
|
12
|
+
export default function buildSeedOnly(readFolderSources) {
|
|
13
|
+
const folderTables = new Map();
|
|
14
|
+
|
|
15
|
+
const readFolderTables = (directory) => {
|
|
16
|
+
const cached = folderTables.get(directory);
|
|
17
|
+
|
|
18
|
+
if (cached !== undefined) {
|
|
19
|
+
return cached;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const tables = new Set(
|
|
23
|
+
readFolderSources(directory)
|
|
24
|
+
.filter((source) => !source.name.startsWith('seed-'))
|
|
25
|
+
.flatMap((source) => collectWrittenTables(source.text)),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
folderTables.set(directory, tables);
|
|
29
|
+
|
|
30
|
+
return tables;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
meta: {
|
|
35
|
+
type: 'problem',
|
|
36
|
+
messages: {
|
|
37
|
+
write:
|
|
38
|
+
"Seed '{{table}}' through the module that writes it, with a `seed…` function from its `test-utils`. A direct write passes only inside a `seed…` function in `test-utils`, in a test beside a module that writes '{{table}}', in a migration test and in a seed's own test.",
|
|
39
|
+
nonLiteral:
|
|
40
|
+
"Name the table in a string literal: the rule finds a table's owner by the table's name.",
|
|
41
|
+
},
|
|
42
|
+
schema: [],
|
|
43
|
+
},
|
|
44
|
+
create(context) {
|
|
45
|
+
const filename = context.physicalFilename;
|
|
46
|
+
const kind = pickFileKind(resolveRepoPath(filename, context.cwd), basename(filename));
|
|
47
|
+
|
|
48
|
+
if (kind === null) {
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const checkWrite = (node, table) => {
|
|
53
|
+
if (kind.inTestUtils && isInSeedFunction(node)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (table === null) {
|
|
58
|
+
context.report({ node, messageId: 'nonLiteral' });
|
|
59
|
+
} else if (!kind.isTest || !readFolderTables(dirname(filename)).has(table)) {
|
|
60
|
+
context.report({ node, messageId: 'write', data: { table } });
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const checkText = (node, text) => {
|
|
65
|
+
if (!isTestTitle(context, node)) {
|
|
66
|
+
for (const table of collectSQLWrites(text)) {
|
|
67
|
+
checkWrite(node, table);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
CallExpression(node) {
|
|
74
|
+
if (isKyselyWrite(node)) {
|
|
75
|
+
checkWrite(node, findLiteralTable(node.arguments[0]));
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
Literal(node) {
|
|
79
|
+
if (typeof node.value === 'string') {
|
|
80
|
+
checkText(node, node.value);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
TemplateLiteral(node) {
|
|
84
|
+
const text = node.quasis
|
|
85
|
+
.map((quasi) => quasi.value.cooked ?? quasi.value.raw)
|
|
86
|
+
// oxlint-disable-next-line no-template-curly-in-string -- marks each interpolation as a module's text shows it
|
|
87
|
+
.join('${}');
|
|
88
|
+
|
|
89
|
+
checkText(node, text);
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const testFilePattern = /\.test\.tsx?$/u;
|
|
97
|
+
const seedTestPattern = /^seed-.+\.test\.tsx?$/u;
|
|
98
|
+
const migrationWords = new Set(['migrate', 'migration', 'migrations']);
|
|
99
|
+
|
|
100
|
+
function pickFileKind(repoPath, name) {
|
|
101
|
+
const inTestUtils = isInTestUtils(repoPath);
|
|
102
|
+
const isTest = testFilePattern.test(name);
|
|
103
|
+
const isMigrationTest = repoPath.split(/[-./\\_]/u).some((word) => migrationWords.has(word));
|
|
104
|
+
|
|
105
|
+
if (isTest && (isMigrationTest || (inTestUtils && seedTestPattern.test(name)))) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return isTest || inTestUtils ? { inTestUtils, isTest } : null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const functionTypes = new Set([
|
|
113
|
+
'FunctionDeclaration',
|
|
114
|
+
'FunctionExpression',
|
|
115
|
+
'ArrowFunctionExpression',
|
|
116
|
+
]);
|
|
117
|
+
|
|
118
|
+
// a seed's callbacks write for the seed, while a seed-named helper inside another function does not
|
|
119
|
+
function isInSeedFunction(node) {
|
|
120
|
+
let outermost = null;
|
|
121
|
+
|
|
122
|
+
for (
|
|
123
|
+
let current = node.parent;
|
|
124
|
+
current !== null && current !== undefined;
|
|
125
|
+
current = current.parent
|
|
126
|
+
) {
|
|
127
|
+
if (functionTypes.has(current.type)) {
|
|
128
|
+
outermost = current;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const name = outermost === null ? null : findFunctionName(outermost);
|
|
133
|
+
|
|
134
|
+
return name !== null && isVerbMatch(name.name, 'seed');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const testRunnerNames = new Set(['test', 'it', 'describe']);
|
|
138
|
+
|
|
139
|
+
function isTestTitle(context, node) {
|
|
140
|
+
const call = node.parent;
|
|
141
|
+
|
|
142
|
+
if (call?.type !== 'CallExpression' || call.arguments[0] !== node) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const root = findChainRoot(call.callee, true);
|
|
147
|
+
|
|
148
|
+
return root !== null && testRunnerNames.has(findBunTestName(context, root));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const kyselyWriteMethods = new Set(['insertInto', 'updateTable', 'deleteFrom']);
|
|
152
|
+
|
|
153
|
+
function isKyselyWrite(node) {
|
|
154
|
+
const callee = node.callee;
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
callee.type === 'MemberExpression' &&
|
|
158
|
+
!callee.computed &&
|
|
159
|
+
callee.property.type === 'Identifier' &&
|
|
160
|
+
kyselyWriteMethods.has(callee.property.name)
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function findLiteralTable(argument) {
|
|
165
|
+
return argument?.type === 'Literal' && typeof argument.value === 'string'
|
|
166
|
+
? toTableName(argument.value)
|
|
167
|
+
: null;
|
|
168
|
+
}
|
package/test-beside-module.js
CHANGED
|
@@ -12,7 +12,7 @@ export default function buildTestBesideModule(rigLanes) {
|
|
|
12
12
|
type: 'problem',
|
|
13
13
|
messages: {
|
|
14
14
|
missing:
|
|
15
|
-
'Move this test beside the module it tests: no `{{name}}.<ext>` sits in this directory. A
|
|
15
|
+
'Move this test beside the module it tests: no `{{name}}.<ext>` sits in this directory. A test that runs the built program belongs in `e2e/` of the package that builds it, and an evaluation in `evals/` of the package whose code it scores.',
|
|
16
16
|
rigLanes:
|
|
17
17
|
'Declare lanes in rig.config.ts only: this repo has one, and the `lanes` option here would give the lanes a second source.',
|
|
18
18
|
},
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { readdirSync } from 'node:fs';
|
|
2
|
+
import { basename, dirname } from 'node:path';
|
|
3
|
+
|
|
4
|
+
const seedFilePattern = /^(?<base>seed-.+)\.tsx?$/u;
|
|
5
|
+
const skippedPattern = /\.test\.tsx?$|\.d\.ts$/u;
|
|
6
|
+
|
|
7
|
+
const testBesideSeed = {
|
|
8
|
+
meta: {
|
|
9
|
+
type: 'problem',
|
|
10
|
+
messages: {
|
|
11
|
+
missing:
|
|
12
|
+
'Write `{{base}}.test.ts` beside this seed: it asserts the rows and files the seed writes, and that input overrides apply.',
|
|
13
|
+
},
|
|
14
|
+
schema: [],
|
|
15
|
+
},
|
|
16
|
+
create(context) {
|
|
17
|
+
return {
|
|
18
|
+
Program() {
|
|
19
|
+
const filename = context.physicalFilename;
|
|
20
|
+
const name = basename(filename);
|
|
21
|
+
const match = seedFilePattern.exec(name);
|
|
22
|
+
|
|
23
|
+
if (match === null || skippedPattern.test(name)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const base = match.groups.base;
|
|
28
|
+
|
|
29
|
+
if (probeSeedTest(dirname(filename), base)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// a disable comment at the top of the file sits above the first statement, so it covers the
|
|
34
|
+
// report there
|
|
35
|
+
const start = context.sourceCode.ast.body[0]?.loc.start ?? { line: 1, column: 0 };
|
|
36
|
+
|
|
37
|
+
context.report({ loc: { start, end: start }, messageId: 'missing', data: { base } });
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export default testBesideSeed;
|
|
44
|
+
|
|
45
|
+
function probeSeedTest(directory, base) {
|
|
46
|
+
return readdirSync(directory).some(
|
|
47
|
+
(entry) => entry.startsWith(`${base}.`) && /\.test\.tsx?$/u.test(entry),
|
|
48
|
+
);
|
|
49
|
+
}
|
package/to-table-name.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// a table named through an interpolation holds `${`, both in a file's text and in a template
|
|
2
|
+
// literal whose parts the rule joins with `${}`
|
|
3
|
+
export default function toTableName(raw) {
|
|
4
|
+
if (raw.includes('${')) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const name = raw
|
|
9
|
+
.split(/\s+as\s+/iu)[0]
|
|
10
|
+
.split('.')
|
|
11
|
+
.at(-1)
|
|
12
|
+
.replaceAll(/["[\]]/gu, '');
|
|
13
|
+
|
|
14
|
+
return name === '' ? null : name.toLowerCase();
|
|
15
|
+
}
|