@ingram-tech/nk-dev 0.7.0 → 0.8.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/guide.md
CHANGED
|
@@ -77,6 +77,12 @@ the UI/page tree, and never expose internal plumbing under `/api/`.
|
|
|
77
77
|
`@ingram-tech/nk-db`'s drift-aware runner (`@ingram-tech/nk-db/migrate`), which
|
|
78
78
|
surfaces the real Postgres error and pre-flights journal drift. Generate **and
|
|
79
79
|
apply** in the same step; don't leave "run the migration" as a handoff.
|
|
80
|
+
- **A migration that moves data asserts how much it moved.** Any backfill /
|
|
81
|
+
seed / copy counts the rows it expects, compares that to the `row_count` it
|
|
82
|
+
got (`get diagnostics`), and `raise exception`s on a mismatch — inside the
|
|
83
|
+
transaction, before commit. A blind move that touches nothing (an RLS mask, a
|
|
84
|
+
wrong `where`) otherwise reports success, and the drop of the source columns
|
|
85
|
+
in the same migration makes it unrecoverable.
|
|
80
86
|
- **`drizzle-kit` is GENERATE-ONLY — it must never apply schema.** Use it for
|
|
81
87
|
`drizzle-kit generate` (and `generate --custom` for a package-owned/raw SQL
|
|
82
88
|
migration). Applying is always **`nk-pg-migrate`** (the bin from
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Shared helper for the `t-*` oxlint rules: extract the ICU MessageFormat
|
|
2
|
+
// argument list from a message.
|
|
3
|
+
//
|
|
4
|
+
// Only depth-0 braces are argument positions. Braces nested inside a
|
|
5
|
+
// plural/select sub-message are ordinary text and must not be read as
|
|
6
|
+
// arguments -- `{count, plural, one {# item} other {# items}}` has exactly one
|
|
7
|
+
// argument, `count`, not three. A brace-depth scan gets this exactly right,
|
|
8
|
+
// which is why this lives in the linter rather than in the package's types:
|
|
9
|
+
// TypeScript template-literal types cannot match brace pairs, so the same check
|
|
10
|
+
// expressed as a type would report `# item` as an argument.
|
|
11
|
+
//
|
|
12
|
+
// A depth-0 brace whose contents do not open with an identifier or a number is
|
|
13
|
+
// not an argument at all -- it is literal text the author wrote. `{"a": 1}`,
|
|
14
|
+
// `{}`, and `body { color: red }` all fall out here and are skipped silently.
|
|
15
|
+
// That bias matters: in this i18n scheme the English source string *is* the
|
|
16
|
+
// catalog key, so an author cannot ICU-escape a stray brace without changing
|
|
17
|
+
// the key and every translation of it. Staying quiet on ambiguous braces is the
|
|
18
|
+
// only behaviour that leaves those messages usable.
|
|
19
|
+
|
|
20
|
+
// ICU argNameOrNumber, anchored at a brace: an identifier or a number, followed
|
|
21
|
+
// by the argument's `,` separator or its closing `}`.
|
|
22
|
+
const ARGUMENT_HEAD = /^\{\s*([A-Za-z_$][\w$]*|\d+)\s*[,}]/;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The ICU arguments of `message`, in source order.
|
|
26
|
+
*
|
|
27
|
+
* Under-reports rather than over-reports. A message using ICU's apostrophe
|
|
28
|
+
* escaping for a literal brace (`Use '{' here`) leaves the scan's depth
|
|
29
|
+
* unbalanced, so later arguments go unseen -- a missed lint, never a false one.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} message
|
|
32
|
+
* @returns {{ name: string, positional: boolean }[]}
|
|
33
|
+
*/
|
|
34
|
+
export function icuArguments(message) {
|
|
35
|
+
const args = [];
|
|
36
|
+
let depth = 0;
|
|
37
|
+
for (let index = 0; index < message.length; index++) {
|
|
38
|
+
const char = message[index];
|
|
39
|
+
if (char === "}") {
|
|
40
|
+
if (depth > 0) depth--;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (char !== "{") continue;
|
|
44
|
+
if (depth === 0) {
|
|
45
|
+
const match = ARGUMENT_HEAD.exec(message.slice(index));
|
|
46
|
+
if (match) {
|
|
47
|
+
args.push({ name: match[1], positional: /^\d+$/.test(match[1]) });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
depth++;
|
|
51
|
+
}
|
|
52
|
+
return args;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Whether `node` is a call to a translator: `t(...)`, by convention throughout
|
|
57
|
+
* the fleet (`const t = createT(locale, scope)` / `const t = useT({ fr, nl })`).
|
|
58
|
+
* Gating on the callee name keeps the rules inert everywhere else without
|
|
59
|
+
* needing to resolve the binding back to `createT`/`useT`.
|
|
60
|
+
*
|
|
61
|
+
* @param {{ callee: { type: string, name?: string } }} node
|
|
62
|
+
*/
|
|
63
|
+
export function isTranslatorCall(node) {
|
|
64
|
+
return node.callee.type === "Identifier" && node.callee.name === "t";
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The message literal of a translator call, or `null` when the first argument
|
|
69
|
+
* is not a plain string literal (a runtime key -- nothing to check statically).
|
|
70
|
+
*
|
|
71
|
+
* @param {{ arguments: { type: string, value?: unknown }[] }} node
|
|
72
|
+
*/
|
|
73
|
+
export function messageLiteral(node) {
|
|
74
|
+
const first = node.arguments[0];
|
|
75
|
+
if (!first || first.type !== "Literal" || typeof first.value !== "string") {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return first;
|
|
79
|
+
}
|
|
@@ -7,6 +7,8 @@ import deferredCurrentTarget from "./deferred-current-target.js";
|
|
|
7
7
|
import lucideIconSuffix from "./lucide-icon-suffix.js";
|
|
8
8
|
import noRedirectOnlyPage from "./no-redirect-only-page.js";
|
|
9
9
|
import redundantUseStateType from "./redundant-usestate-type.js";
|
|
10
|
+
import tNoPositionalArgs from "./t-no-positional-args.js";
|
|
11
|
+
import tRequiresValues from "./t-requires-values.js";
|
|
10
12
|
|
|
11
13
|
export default {
|
|
12
14
|
meta: { name: "nextkit" },
|
|
@@ -16,5 +18,7 @@ export default {
|
|
|
16
18
|
...lucideIconSuffix.rules,
|
|
17
19
|
...noRedirectOnlyPage.rules,
|
|
18
20
|
...redundantUseStateType.rules,
|
|
21
|
+
...tNoPositionalArgs.rules,
|
|
22
|
+
...tRequiresValues.rules,
|
|
19
23
|
},
|
|
20
24
|
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// nextkit oxlint JS plugin rule: forbid positional ICU arguments (`{0}`, `{1}`)
|
|
2
|
+
// in `t()` messages.
|
|
3
|
+
//
|
|
4
|
+
// ICU MessageFormat permits numbered arguments, but they are wrong for this
|
|
5
|
+
// i18n scheme in two ways. The English source string is the catalog key and is
|
|
6
|
+
// what a translator reads, so `{0}` gives them no clue what the value is, and
|
|
7
|
+
// reordering it for another language's word order becomes guesswork. Named
|
|
8
|
+
// arguments carry that context in the key itself.
|
|
9
|
+
//
|
|
10
|
+
// Banning them also lets the runtime stay conservative about what counts as a
|
|
11
|
+
// placeholder: `@ingram-tech/nk-i18n` only treats identifier-headed braces as
|
|
12
|
+
// arguments, so prose and embedded JSON (`t('This is JSON: {"a": 1}')`) are
|
|
13
|
+
// passed through untouched. That heuristic would have to admit digits -- and
|
|
14
|
+
// with them `{2: "x"}` -- if positional arguments were allowed anywhere.
|
|
15
|
+
|
|
16
|
+
import { icuArguments, isTranslatorCall, messageLiteral } from "./icu-arguments.js";
|
|
17
|
+
|
|
18
|
+
const tNoPositionalArgs = {
|
|
19
|
+
meta: {
|
|
20
|
+
type: "problem",
|
|
21
|
+
docs: {
|
|
22
|
+
description: "Forbid positional ICU arguments in t() messages",
|
|
23
|
+
},
|
|
24
|
+
messages: {
|
|
25
|
+
positionalArgument:
|
|
26
|
+
"`t()` message uses the positional placeholder `{{{name}}}`. Name it instead -- the English source is the catalog key, so translators read the placeholder and may need to reorder it.",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
create(context) {
|
|
30
|
+
return {
|
|
31
|
+
CallExpression(node) {
|
|
32
|
+
if (!isTranslatorCall(node)) return;
|
|
33
|
+
const message = messageLiteral(node);
|
|
34
|
+
if (!message) return;
|
|
35
|
+
|
|
36
|
+
for (const arg of icuArguments(message.value)) {
|
|
37
|
+
if (!arg.positional) continue;
|
|
38
|
+
context.report({
|
|
39
|
+
node: message,
|
|
40
|
+
messageId: "positionalArgument",
|
|
41
|
+
data: { name: arg.name },
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default {
|
|
50
|
+
meta: { name: "nextkit" },
|
|
51
|
+
rules: { "t-no-positional-args": tNoPositionalArgs },
|
|
52
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// nextkit oxlint JS plugin rule: a `t()` message with ICU placeholders must be
|
|
2
|
+
// passed the values those placeholders need.
|
|
3
|
+
//
|
|
4
|
+
// `@ingram-tech/nk-i18n`'s translator returns the message unformatted when no
|
|
5
|
+
// values argument is given -- it never reaches IntlMessageFormat, so nothing
|
|
6
|
+
// throws and nothing warns. `t("Results for {query}")` therefore ships the
|
|
7
|
+
// literal text `Results for {query}` to users with no runtime signal at all.
|
|
8
|
+
// Every other failure in that package degrades loudly; this one is silent,
|
|
9
|
+
// which makes it the one worth catching at author time.
|
|
10
|
+
//
|
|
11
|
+
// Two reports:
|
|
12
|
+
// - the values argument is missing entirely, while the message has arguments;
|
|
13
|
+
// - the values argument is an object literal that omits a required key, which
|
|
14
|
+
// is what a misspelling looks like (`t("… {query}", { qeury })`).
|
|
15
|
+
//
|
|
16
|
+
// When the values argument is anything other than a plain object literal (a
|
|
17
|
+
// variable, a call, a spread), only the first check applies -- the keys are not
|
|
18
|
+
// statically known and guessing would produce false reports.
|
|
19
|
+
|
|
20
|
+
import { icuArguments, isTranslatorCall, messageLiteral } from "./icu-arguments.js";
|
|
21
|
+
|
|
22
|
+
const tRequiresValues = {
|
|
23
|
+
meta: {
|
|
24
|
+
type: "problem",
|
|
25
|
+
docs: {
|
|
26
|
+
description: "Require values for the ICU placeholders in a t() message",
|
|
27
|
+
},
|
|
28
|
+
messages: {
|
|
29
|
+
missingValues:
|
|
30
|
+
"`t()` message uses the placeholder{{plural}} {{names}} but no values argument was passed. The placeholder text is rendered to users verbatim.",
|
|
31
|
+
missingValue:
|
|
32
|
+
"`t()` values object is missing `{{name}}`, required by the message's `{{{name}}}` placeholder.",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
create(context) {
|
|
36
|
+
return {
|
|
37
|
+
CallExpression(node) {
|
|
38
|
+
if (!isTranslatorCall(node)) return;
|
|
39
|
+
const message = messageLiteral(node);
|
|
40
|
+
if (!message) return;
|
|
41
|
+
|
|
42
|
+
const args = icuArguments(message.value);
|
|
43
|
+
if (args.length === 0) return;
|
|
44
|
+
|
|
45
|
+
const names = args.map((arg) => arg.name);
|
|
46
|
+
const values = node.arguments[1];
|
|
47
|
+
if (!values) {
|
|
48
|
+
context.report({
|
|
49
|
+
node,
|
|
50
|
+
messageId: "missingValues",
|
|
51
|
+
data: {
|
|
52
|
+
plural: names.length === 1 ? "" : "s",
|
|
53
|
+
names: names.map((name) => `\`${name}\``).join(", "),
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (values.type !== "ObjectExpression") return;
|
|
60
|
+
// A spread can supply anything; the key set is no longer known.
|
|
61
|
+
if (
|
|
62
|
+
values.properties.some((property) => property.type !== "Property")
|
|
63
|
+
) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const provided = new Set();
|
|
67
|
+
for (const property of values.properties) {
|
|
68
|
+
if (property.computed) return;
|
|
69
|
+
if (property.key.type === "Identifier")
|
|
70
|
+
provided.add(property.key.name);
|
|
71
|
+
else if (property.key.type === "Literal") {
|
|
72
|
+
provided.add(String(property.key.value));
|
|
73
|
+
} else return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
for (const name of names) {
|
|
77
|
+
if (provided.has(name)) continue;
|
|
78
|
+
context.report({
|
|
79
|
+
node: values,
|
|
80
|
+
messageId: "missingValue",
|
|
81
|
+
data: { name },
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export default {
|
|
90
|
+
meta: { name: "nextkit" },
|
|
91
|
+
rules: { "t-requires-values": tRequiresValues },
|
|
92
|
+
};
|
package/oxlintrc.json
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
"nextkit/no-redundant-usestate-type": "warn",
|
|
11
11
|
"nextkit/lucide-icon-suffix": "warn",
|
|
12
12
|
"nextkit/no-redirect-only-page": "warn",
|
|
13
|
+
"nextkit/t-requires-values": "error",
|
|
14
|
+
"nextkit/t-no-positional-args": "error",
|
|
13
15
|
"no-unused-vars": "warn",
|
|
14
16
|
"typescript/no-non-null-assertion": "error",
|
|
15
17
|
"typescript/no-explicit-any": "error",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ingram-tech/nk-dev",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "The nextkit dev toolchain in one package: the `nk` CLI plus shared oxlint/oxfmt, TypeScript, and Vitest config, the format-on-commit hook, and the AI agent guide. `nk init` scaffolds a site to use it.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|