@zgeoff/oxlint-config 0.10.0 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/build-seed-only.js +168 -0
- package/collect-sql-writes.js +19 -0
- package/collect-written-tables.js +14 -0
- package/file-named-for-export.js +177 -0
- package/function-verb.js +13 -2
- package/import-zones/index.js +2 -0
- package/is-in-test-utils.js +7 -0
- package/oxlintrc.json +4 -1
- package/package.json +17 -8
- package/plugin.js +9 -2
- package/read-folder-sources.js +12 -0
- package/resolve-repo-path.js +6 -0
- package/test-beside-seed.js +49 -0
- package/to-table-name.js +15 -0
- package/verb-contract.js +1 -0
- package/import-zones-entry.js +0 -2
- /package/{max-test-timeout.js → build-max-test-timeout.js} +0 -0
- /package/{test-beside-module.js → build-test-beside-module.js} +0 -0
- /package/{import-zones-entry.d.ts → import-zones/index.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -70,11 +70,14 @@ The plugin is addressable on its own at `@zgeoff/oxlint-config/plugin` for confi
|
|
|
70
70
|
- Comments: `zgeoff/no-jsdoc` and `zgeoff/max-consecutive-line-comments` keep comments to the reason
|
|
71
71
|
for a line. See
|
|
72
72
|
[the comment rules](../../docs/architecture/oxlint-config.md#zgeoffno-jsdoc-and-zgeoffmax-consecutive-line-comments).
|
|
73
|
-
- Code style: function verbs, verb contracts, module order, abbreviated names and
|
|
74
|
-
[code-style rules](../../docs/architecture/oxlint-config-code-style.md).
|
|
73
|
+
- Code style: function verbs, verb contracts, module order, file names, abbreviated names and
|
|
74
|
+
classes. See [code-style rules](../../docs/architecture/oxlint-config-code-style.md).
|
|
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).
|
|
@@ -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
|
+
}
|
|
@@ -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,177 @@
|
|
|
1
|
+
import { basename } from 'node:path';
|
|
2
|
+
|
|
3
|
+
const exemptBases = new Set(['index', 'types', 'constants']);
|
|
4
|
+
|
|
5
|
+
const fileNamedForExport = {
|
|
6
|
+
meta: {
|
|
7
|
+
type: 'suggestion',
|
|
8
|
+
messages: {
|
|
9
|
+
mismatch:
|
|
10
|
+
"No export of '{{file}}' is named for the file: name the main export '{{base}}' in camelCase, PascalCase or SCREAMING_SNAKE_CASE, or rename the file for its main export.",
|
|
11
|
+
},
|
|
12
|
+
schema: [],
|
|
13
|
+
},
|
|
14
|
+
create(context) {
|
|
15
|
+
return {
|
|
16
|
+
Program(program) {
|
|
17
|
+
const file = basename(context.physicalFilename);
|
|
18
|
+
const [base, ...suffixes] = file.split('.');
|
|
19
|
+
|
|
20
|
+
// a role suffix, such as `.config` or `.bench`, marks a file that a tool loads, and the
|
|
21
|
+
// tool sets its exports
|
|
22
|
+
if (suffixes.length !== 1 || exemptBases.has(base)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const exports = collectExports(program.body);
|
|
27
|
+
|
|
28
|
+
if (exports.statements.length === 0 || exports.names === null) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const wanted = toComparableName(base);
|
|
33
|
+
|
|
34
|
+
if (exports.names.some((name) => toComparableName(name) === wanted)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
context.report({
|
|
39
|
+
node: exports.statements[0],
|
|
40
|
+
messageId: 'mismatch',
|
|
41
|
+
data: { file, base },
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default fileNamedForExport;
|
|
49
|
+
|
|
50
|
+
const exportTypes = new Set([
|
|
51
|
+
'ExportNamedDeclaration',
|
|
52
|
+
'ExportDefaultDeclaration',
|
|
53
|
+
'ExportAllDeclaration',
|
|
54
|
+
'TSExportAssignment',
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
// an `export * from` or an `export { default } from` hides the name it exports, so names is null
|
|
58
|
+
// and the file passes
|
|
59
|
+
function collectExports(body) {
|
|
60
|
+
const statements = body.filter(
|
|
61
|
+
(statement) => exportTypes.has(statement.type) && !isEmptyExport(statement),
|
|
62
|
+
);
|
|
63
|
+
const names = [];
|
|
64
|
+
|
|
65
|
+
for (const statement of statements) {
|
|
66
|
+
const exported = collectExportNames(statement);
|
|
67
|
+
|
|
68
|
+
if (exported === null) {
|
|
69
|
+
return { statements, names: null };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
names.push(...exported);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return { statements, names };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// `export {}` only marks a script as a module
|
|
79
|
+
function isEmptyExport(statement) {
|
|
80
|
+
return (
|
|
81
|
+
statement.type === 'ExportNamedDeclaration' &&
|
|
82
|
+
statement.declaration === null &&
|
|
83
|
+
statement.specifiers.length === 0
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function collectExportNames(statement) {
|
|
88
|
+
if (statement.type === 'ExportAllDeclaration') {
|
|
89
|
+
return statement.exported === null ? null : [toExportName(statement.exported)];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (statement.type === 'TSExportAssignment') {
|
|
93
|
+
return collectValueNames(statement.expression);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (statement.type === 'ExportDefaultDeclaration') {
|
|
97
|
+
return collectValueNames(statement.declaration);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (statement.declaration !== null) {
|
|
101
|
+
return collectDeclarationNames(statement.declaration);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const names = statement.specifiers.map((specifier) => {
|
|
105
|
+
const exported = toExportName(specifier.exported);
|
|
106
|
+
|
|
107
|
+
return exported === 'default' ? toExportName(specifier.local) : exported;
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
return statement.source !== null && names.includes('default') ? null : names;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function toExportName(node) {
|
|
114
|
+
return node.type === 'Identifier' ? node.name : node.value;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const wrapperTypes = new Set(['TSAsExpression', 'TSSatisfiesExpression', 'TSNonNullExpression']);
|
|
118
|
+
|
|
119
|
+
function collectValueNames(value) {
|
|
120
|
+
if (wrapperTypes.has(value.type)) {
|
|
121
|
+
return collectValueNames(value.expression);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (value.type === 'Identifier') {
|
|
125
|
+
return [value.name];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return value.id?.type === 'Identifier' ? [value.id.name] : [];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function collectDeclarationNames(declaration) {
|
|
132
|
+
if (declaration.type === 'VariableDeclaration') {
|
|
133
|
+
return declaration.declarations.flatMap((declarator) => collectPatternNames(declarator.id));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return declaration.id === null || declaration.id === undefined
|
|
137
|
+
? []
|
|
138
|
+
: [toRootName(declaration.id)];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function collectPatternNames(pattern) {
|
|
142
|
+
if (pattern.type === 'Identifier') {
|
|
143
|
+
return [pattern.name];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (pattern.type === 'ObjectPattern') {
|
|
147
|
+
return pattern.properties.flatMap((property) => {
|
|
148
|
+
const target = property.type === 'RestElement' ? property.argument : property.value;
|
|
149
|
+
|
|
150
|
+
return collectPatternNames(target);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (pattern.type === 'ArrayPattern') {
|
|
155
|
+
return pattern.elements.flatMap((element) =>
|
|
156
|
+
element === null ? [] : collectPatternNames(element),
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (pattern.type === 'AssignmentPattern') {
|
|
161
|
+
return collectPatternNames(pattern.left);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return pattern.type === 'RestElement' ? collectPatternNames(pattern.argument) : [];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function toRootName(name) {
|
|
168
|
+
if (name.type === 'TSQualifiedName') {
|
|
169
|
+
return toRootName(name.left);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return toExportName(name);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function toComparableName(name) {
|
|
176
|
+
return name.replaceAll(/[-_]/gu, '').toLowerCase();
|
|
177
|
+
}
|
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
|
@@ -43,6 +43,9 @@
|
|
|
43
43
|
"zgeoff/no-require": "error",
|
|
44
44
|
"zgeoff/test-shape": "error",
|
|
45
45
|
"zgeoff/feature-folders": "error",
|
|
46
|
+
"zgeoff/seed-only": "error",
|
|
47
|
+
"zgeoff/test-beside-seed": "error",
|
|
48
|
+
"zgeoff/file-named-for-export": "error",
|
|
46
49
|
|
|
47
50
|
// name a value for what it holds, in full words: one letter only for a
|
|
48
51
|
// coordinate, zod's `z`, Bun's shell `$` or an unread `_` placeholder, and
|
|
@@ -154,7 +157,7 @@
|
|
|
154
157
|
"unicorn/no-useless-undefined": ["error", { "checkArguments": false }],
|
|
155
158
|
"unicorn/no-null": "off",
|
|
156
159
|
"unicorn/number-literal-case": "off",
|
|
157
|
-
"unicorn/filename-case": "
|
|
160
|
+
"unicorn/filename-case": ["error", { "case": "kebabCase" }],
|
|
158
161
|
|
|
159
162
|
// one declaration per variable; a declaration list has no order to sort
|
|
160
163
|
"one-var": ["error", "never"],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zgeoff/oxlint-config",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"description": "Shareable oxlint config: strict categories, house-style rules, and a custom JS plugin",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"no-jsdoc.js",
|
|
29
29
|
"no-comment-rule-override.js",
|
|
30
30
|
"no-hidden-cast.js",
|
|
31
|
-
"test-beside-module.js",
|
|
31
|
+
"build-test-beside-module.js",
|
|
32
32
|
"no-file-snapshot.js",
|
|
33
33
|
"setup-test-only.js",
|
|
34
|
-
"max-test-timeout.js",
|
|
34
|
+
"build-max-test-timeout.js",
|
|
35
35
|
"test-timeout-exception-ticket.js",
|
|
36
36
|
"build-lane-limits.js",
|
|
37
37
|
"read-rig-lanes.js",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"find-static-key.js",
|
|
48
48
|
"import-zones.js",
|
|
49
49
|
"import-zones-schema.js",
|
|
50
|
-
"import-zones
|
|
51
|
-
"import-zones
|
|
50
|
+
"import-zones/index.js",
|
|
51
|
+
"import-zones/index.d.ts",
|
|
52
52
|
"collect-refusing-edges.js",
|
|
53
53
|
"is-edge-refusing.js",
|
|
54
54
|
"is-entry-applying.js",
|
|
@@ -70,6 +70,15 @@
|
|
|
70
70
|
"read-stale-pending.js",
|
|
71
71
|
"read-package-manifest.js",
|
|
72
72
|
"read-module-paths.js",
|
|
73
|
+
"build-seed-only.js",
|
|
74
|
+
"test-beside-seed.js",
|
|
75
|
+
"file-named-for-export.js",
|
|
76
|
+
"read-folder-sources.js",
|
|
77
|
+
"collect-written-tables.js",
|
|
78
|
+
"collect-sql-writes.js",
|
|
79
|
+
"to-table-name.js",
|
|
80
|
+
"resolve-repo-path.js",
|
|
81
|
+
"is-in-test-utils.js",
|
|
73
82
|
"index.js"
|
|
74
83
|
],
|
|
75
84
|
"type": "module",
|
|
@@ -79,8 +88,8 @@
|
|
|
79
88
|
"./react.json": "./react.json",
|
|
80
89
|
"./plugin": "./plugin.js",
|
|
81
90
|
"./import-zones": {
|
|
82
|
-
"types": "./import-zones
|
|
83
|
-
"default": "./import-zones
|
|
91
|
+
"types": "./import-zones/index.d.ts",
|
|
92
|
+
"default": "./import-zones/index.js"
|
|
84
93
|
}
|
|
85
94
|
},
|
|
86
95
|
"publishConfig": {
|
|
@@ -94,7 +103,7 @@
|
|
|
94
103
|
},
|
|
95
104
|
"devDependencies": {
|
|
96
105
|
"@types/bun": "1.4.4",
|
|
97
|
-
"@zgeoff/rig": "0.2.
|
|
106
|
+
"@zgeoff/rig": "0.2.2",
|
|
98
107
|
"@zgeoff/std": "0.4.3",
|
|
99
108
|
"@zgeoff/testing": "0.3.0",
|
|
100
109
|
"tsrs": "0.18.0-ts7.1.0-dev.20260929",
|
package/plugin.js
CHANGED
|
@@ -2,11 +2,14 @@ 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 buildMaxTestTimeout from './build-max-test-timeout.js';
|
|
6
|
+
import buildSeedOnly from './build-seed-only.js';
|
|
7
|
+
import buildTestBesideModule from './build-test-beside-module.js';
|
|
5
8
|
import featureFolders from './feature-folders.js';
|
|
9
|
+
import fileNamedForExport from './file-named-for-export.js';
|
|
6
10
|
import functionVerb from './function-verb.js';
|
|
7
11
|
import importZones from './import-zones.js';
|
|
8
12
|
import maxConsecutiveLineComments from './max-consecutive-line-comments.js';
|
|
9
|
-
import buildMaxTestTimeout from './max-test-timeout.js';
|
|
10
13
|
import moduleOrder from './module-order.js';
|
|
11
14
|
import noAbbreviatedNames from './no-abbreviated-names.js';
|
|
12
15
|
import noClass from './no-class.js';
|
|
@@ -17,10 +20,11 @@ import noJSDoc from './no-jsdoc.js';
|
|
|
17
20
|
import noRequire from './no-require.js';
|
|
18
21
|
import noRestrictedWords from './no-restricted-words.js';
|
|
19
22
|
import noTestSleep from './no-test-sleep.js';
|
|
23
|
+
import readFolderSources from './read-folder-sources.js';
|
|
20
24
|
import readRigLanes from './read-rig-lanes.js';
|
|
21
25
|
import resolveRepoRoot from './resolve-repo-root.js';
|
|
22
26
|
import setupTestOnly from './setup-test-only.js';
|
|
23
|
-
import
|
|
27
|
+
import testBesideSeed from './test-beside-seed.js';
|
|
24
28
|
import testShape from './test-shape.js';
|
|
25
29
|
import testTimeoutExceptionTicket from './test-timeout-exception-ticket.js';
|
|
26
30
|
import verbContract from './verb-contract.js';
|
|
@@ -133,6 +137,9 @@ const plugin = {
|
|
|
133
137
|
'test-shape': testShape,
|
|
134
138
|
'import-zones': importZones,
|
|
135
139
|
'feature-folders': featureFolders,
|
|
140
|
+
'seed-only': buildSeedOnly(readFolderSources),
|
|
141
|
+
'test-beside-seed': testBesideSeed,
|
|
142
|
+
'file-named-for-export': fileNamedForExport,
|
|
136
143
|
},
|
|
137
144
|
};
|
|
138
145
|
|
|
@@ -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,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
|
+
}
|
package/verb-contract.js
CHANGED
package/import-zones-entry.js
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|