mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 18:34:09 +00:00
ci: server and shared lint stop rewriting files, and Prettier is checked per file
shared's lint ran eslint --fix with prettier/prettier as an error, so in lint-prettier.yml the format:check after it only ever saw files it had just rewritten, and the server's format scripts pointed at a test/ directory that does not exist. Now lint is check-only in both (lint:fix applies fixes), the server scripts cover src/ and tests/, and a lint:format ratchet on the shared library holds every file outside scripts/format-baseline.json to Prettier in both workspaces: in the server job of test.yml and in lint-prettier.yml, which keeps providing the lint check. Formatting leaves ESLint in shared, and the unused eslint-plugin-prettier goes. Once the tree is reformatted in one commit, --update empties the baselines and the check is a full prettier --check.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env node
|
||||
/*
|
||||
* lint:format: new server code is formatted with Prettier.
|
||||
*
|
||||
* `npm run format:check` was never part of CI, and most files differ from what
|
||||
* .prettierrc asks for. Formatting all of them belongs in one mechanical
|
||||
* commit of its own; until it lands, the files that were unformatted when
|
||||
* this check came in are listed in scripts/format-baseline.json and the list
|
||||
* only shrinks: every file outside it, a new one in particular, must be
|
||||
* formatted, and a listed file leaves the list once it has been. After the
|
||||
* mass reformat, --update empties the list and the check is a plain
|
||||
* prettier --check over src/ and tests/.
|
||||
*
|
||||
* npm run lint:format check against the baseline (CI)
|
||||
* npm run lint:format -- --list print every unformatted file
|
||||
* npm run lint:format -- --update take formatted and deleted files off the list;
|
||||
* it never adds one
|
||||
*
|
||||
* To format a file: npx prettier --write <file>. The comparison lives in
|
||||
* scripts/lib/format.mjs at the repository root; Prettier and its config come
|
||||
* from this workspace.
|
||||
*/
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import * as prettier from 'prettier';
|
||||
import { check } from '../../scripts/lib/format.mjs';
|
||||
import { runCli } from '../../scripts/lib/ratchet.mjs';
|
||||
|
||||
const root = fileURLToPath(new URL('..', import.meta.url));
|
||||
await runCli('lint:format', (args) =>
|
||||
check({
|
||||
prettier,
|
||||
root,
|
||||
dirs: ['src', 'tests'],
|
||||
accepts: (key) => key.endsWith('.ts'),
|
||||
update: args.includes('--update'),
|
||||
list: args.includes('--list'),
|
||||
}),
|
||||
);
|
||||
@@ -114,12 +114,17 @@ function propertyKey(name: string): string {
|
||||
export function renderTable(table: TableInfo): string {
|
||||
const types = table.columns.map((c) => columnType(table, c));
|
||||
const has = (marker: string) => types.some((t) => t.startsWith(`${marker}<`));
|
||||
const imports =
|
||||
(has('GeneratedAlways') ? "import type { GeneratedAlways } from 'kysely';\n" : '') +
|
||||
(has('InsertOptional') ? "import type { InsertOptional } from './columns';\n" : '');
|
||||
const importBlock = imports === '' ? '' : `${imports}\n`;
|
||||
// Laid out the way the server's Prettier import sorting leaves them, so the
|
||||
// output passes lint:format as written: the relative import first, one blank
|
||||
// line between the groups, and the header comment on the first import with
|
||||
// no blank line after it. A file without imports keeps its blank line.
|
||||
const groups = [
|
||||
has('InsertOptional') ? "import type { InsertOptional } from './columns';\n" : '',
|
||||
has('GeneratedAlways') ? "import type { GeneratedAlways } from 'kysely';\n" : '',
|
||||
].filter((group) => group !== '');
|
||||
const importBlock = groups.length === 0 ? '\n' : `${groups.join('\n')}\n`;
|
||||
const body = table.columns.map((c, i) => ` ${propertyKey(c.name)}: ${types[i]};`).join('\n');
|
||||
return `${HEADER}\n${importBlock}export interface ${interfaceName(table.name)} {\n${body}\n}\n`;
|
||||
return `${HEADER}${importBlock}export interface ${interfaceName(table.name)} {\n${body}\n}\n`;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +137,7 @@ export function renderTable(table: TableInfo): string {
|
||||
*/
|
||||
export function renderColumns(): string {
|
||||
return (
|
||||
`${HEADER}\nimport type { ColumnType } from 'kysely';\n\n` +
|
||||
`${HEADER}import type { ColumnType } from 'kysely';\n\n` +
|
||||
'/** A column an insert may leave out: the database assigns it (rowid, DEFAULT) or stores NULL. */\n' +
|
||||
'export type InsertOptional<T> = ColumnType<T, T | void, T>;\n'
|
||||
);
|
||||
@@ -145,7 +150,7 @@ export function renderDb(tables: readonly TableInfo[]): string {
|
||||
.join('\n');
|
||||
const body = tables.map((t) => ` ${propertyKey(t.name)}: ${interfaceName(t.name)};`).join('\n');
|
||||
return (
|
||||
`${HEADER}\n${imports}\n\n` +
|
||||
`${HEADER}${imports}\n\n` +
|
||||
'/** Every table of the migrated schema. A repository narrows it: `this.kysely<Pick<DB, \'trips\'>>()`. */\n' +
|
||||
`export interface DB {\n${body}\n}\n`
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user