@multiplatform.one/config 9.8.1 → 9.10.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/README.md +24 -20
- package/design-lint.mjs +57 -39
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -210,28 +210,32 @@ Every violation is tagged with its rule: `field-action`, `field-focus`, `hex`,
|
|
|
210
210
|
#### Ratchet
|
|
211
211
|
|
|
212
212
|
```sh
|
|
213
|
-
pnpm exec mpo-design-lint --baseline design-baseline.json --init
|
|
214
|
-
pnpm exec mpo-design-lint --baseline design-baseline.json
|
|
215
|
-
pnpm exec mpo-design-lint --baseline design-baseline.json --frozen
|
|
213
|
+
pnpm exec mpo-design-lint --baseline design-baseline.json --init # once, commit the file
|
|
214
|
+
pnpm exec mpo-design-lint --baseline design-baseline.json # lint step
|
|
215
|
+
pnpm exec mpo-design-lint --baseline design-baseline.json --frozen # CI
|
|
216
|
+
pnpm exec mpo-design-lint --baseline design-baseline.json --tighten # drop cleared offenders
|
|
216
217
|
```
|
|
217
218
|
|
|
218
|
-
The baseline records the scanned paths (relative to the baseline file) and
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
`
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
219
|
+
The baseline records the scanned paths (relative to the baseline file) and every
|
|
220
|
+
offender by rule, file and message, with how often it occurs. It stores no total
|
|
221
|
+
and no per-rule count; the lint derives both from the offenders
|
|
222
|
+
(`countBaseline(baseline)`). A run fails when it finds an offender the baseline
|
|
223
|
+
doesn't list, or more of one than it lists, so fixing one never pays for a new
|
|
224
|
+
one, and line moves don't count. Clearing offenders passes without touching the
|
|
225
|
+
file, so two changes that each clear a different offender never conflict on the
|
|
226
|
+
baseline. `--tighten` is the explicit step that rewrites the baseline down to
|
|
227
|
+
what the scan finds; nothing else writes it except `--init`, and `--frozen`
|
|
228
|
+
refuses both. The file is written in the shape `oxfmt` gives it. A baseline that
|
|
229
|
+
still stores `total` and `rules` ratchets those counts until `--tighten`
|
|
230
|
+
rewrites it. `--list` prints the violations on a passing run. `--baseline` may
|
|
231
|
+
repeat; MPO's `pnpm lint:design` ratchets `apps/one`, `apps/storybook-expo`,
|
|
232
|
+
`features`, `packages`, `public/backoffice`, `public/frappe-ui` and `public`
|
|
233
|
+
(the harvested rules over every MPO package) this way.
|
|
234
|
+
|
|
235
|
+
`--only <rule>` (repeatable) cuts a baseline that ratchets just those rules;
|
|
236
|
+
`--only harvest` takes all the harvested rules. `--init` on an existing baseline
|
|
237
|
+
adopts the rules it doesn't record yet, such as `mpo-role` in a baseline cut
|
|
238
|
+
before it shipped, and leaves the recorded offenders alone.
|
|
235
239
|
|
|
236
240
|
`mpo-design-lint --verify-ci [dir]` is LC-192's fitness check: it fails when
|
|
237
241
|
the repo's `.gitlab-ci.yml` or GitHub workflows never run the lint, run it
|
package/design-lint.mjs
CHANGED
|
@@ -203,9 +203,6 @@ export const designRules = [
|
|
|
203
203
|
"token-file",
|
|
204
204
|
...harvestRules,
|
|
205
205
|
];
|
|
206
|
-
// Rules whose baseline records each offender, so a new offender fails even
|
|
207
|
-
// when another one was fixed in the same change.
|
|
208
|
-
export const identityRules = new Set(["icon-button", "mpo-role", ...harvestRules]);
|
|
209
206
|
// LC-203 USER-WORDS: implementation words a user never reads. A baseline's
|
|
210
207
|
// bannedWords replaces this list for its app; --init seeds it.
|
|
211
208
|
export const houseBannedWords = [
|
|
@@ -2059,6 +2056,7 @@ function parseArgs(args) {
|
|
|
2059
2056
|
init: false,
|
|
2060
2057
|
list: false,
|
|
2061
2058
|
only: [],
|
|
2059
|
+
tighten: false,
|
|
2062
2060
|
verifyCi: false,
|
|
2063
2061
|
};
|
|
2064
2062
|
for (let index = 0; index < args.length; index++) {
|
|
@@ -2078,12 +2076,15 @@ function parseArgs(args) {
|
|
|
2078
2076
|
} else if (arg === "--frozen") options.frozen = true;
|
|
2079
2077
|
else if (arg === "--verify-ci") options.verifyCi = true;
|
|
2080
2078
|
else if (arg === "--init") options.init = true;
|
|
2079
|
+
else if (arg === "--tighten") options.tighten = true;
|
|
2081
2080
|
else if (arg === "--list") options.list = true;
|
|
2082
2081
|
else if (arg.startsWith("--")) throw new Error(`Unknown option ${arg}.`);
|
|
2083
2082
|
else options.paths.push(arg);
|
|
2084
2083
|
}
|
|
2085
2084
|
if (options.paths.length && options.baselines.length > 1)
|
|
2086
2085
|
throw new Error("Pass paths with at most one --baseline.");
|
|
2086
|
+
if (options.frozen && (options.init || options.tighten))
|
|
2087
|
+
throw new Error("--frozen never writes a baseline; drop --init and --tighten.");
|
|
2087
2088
|
return options;
|
|
2088
2089
|
}
|
|
2089
2090
|
|
|
@@ -2113,7 +2114,7 @@ export function offenderKey(error, base) {
|
|
|
2113
2114
|
|
|
2114
2115
|
function offendersOf(scan, base) {
|
|
2115
2116
|
const offenders = {};
|
|
2116
|
-
for (const rule of
|
|
2117
|
+
for (const rule of Object.keys(scan.rules).sort()) {
|
|
2117
2118
|
const keys = {};
|
|
2118
2119
|
for (const error of scan.errors.filter((item) => ruleOf(item) === rule)) {
|
|
2119
2120
|
const key = offenderKey(error, base);
|
|
@@ -2124,6 +2125,18 @@ function offendersOf(scan, base) {
|
|
|
2124
2125
|
return offenders;
|
|
2125
2126
|
}
|
|
2126
2127
|
|
|
2128
|
+
const sum = (counts) => counts.reduce((total, count) => total + count, 0);
|
|
2129
|
+
|
|
2130
|
+
export function countBaseline(baseline) {
|
|
2131
|
+
const rules = Object.fromEntries(
|
|
2132
|
+
Object.entries(baseline.offenders ?? {}).map(([rule, keys]) => [
|
|
2133
|
+
rule,
|
|
2134
|
+
sum(Object.values(keys)),
|
|
2135
|
+
]),
|
|
2136
|
+
);
|
|
2137
|
+
return { total: sum(Object.values(rules)), rules };
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2127
2140
|
// FZ-10697: a regenerated baseline has to be a file oxfmt leaves alone, or
|
|
2128
2141
|
// every lane that lowers the ratchet fails `scripts/format-changed.sh` and has
|
|
2129
2142
|
// to hand-run the formatter. JSON.stringify's indent puts every array element
|
|
@@ -2164,7 +2177,8 @@ function ratchet(file, options) {
|
|
|
2164
2177
|
const present = existsSync(file);
|
|
2165
2178
|
if (!present && !options.init)
|
|
2166
2179
|
throw new Error(`${file} does not exist; create it with --init and commit it.`);
|
|
2167
|
-
const
|
|
2180
|
+
const text = present ? readFileSync(file, "utf8") : undefined;
|
|
2181
|
+
const previous = present ? JSON.parse(text) : undefined;
|
|
2168
2182
|
const paths = options.paths.length
|
|
2169
2183
|
? options.paths.map(relative)
|
|
2170
2184
|
: (previous?.paths ?? scopeFrom(process.cwd()).map(relative));
|
|
@@ -2203,8 +2217,6 @@ function ratchet(file, options) {
|
|
|
2203
2217
|
paths,
|
|
2204
2218
|
...(only ? { only } : {}),
|
|
2205
2219
|
...(!only || only.includes("user-words") ? words : {}),
|
|
2206
|
-
total: scan.total,
|
|
2207
|
-
rules: Object.fromEntries(Object.entries(scan.rules).sort()),
|
|
2208
2220
|
offenders: offendersOf(scan, base),
|
|
2209
2221
|
};
|
|
2210
2222
|
const write = () => writeFileSync(file, formatBaseline(next));
|
|
@@ -2213,29 +2225,31 @@ function ratchet(file, options) {
|
|
|
2213
2225
|
process.stdout.write(`MPO design guard: ${file} created at ${summary(scan)}.\n`);
|
|
2214
2226
|
return 0;
|
|
2215
2227
|
}
|
|
2228
|
+
const counts = previous.rules ?? {};
|
|
2229
|
+
const recorded = new Set([...Object.keys(previous.offenders ?? {}), ...Object.keys(counts)]);
|
|
2216
2230
|
// --init on an existing baseline adopts only the rules it does not record
|
|
2217
2231
|
// yet (a rule added to MPO after the baseline was cut); recorded rules keep
|
|
2218
2232
|
// their ceilings.
|
|
2219
2233
|
const adopted = options.init
|
|
2220
|
-
? (
|
|
2234
|
+
? Object.keys(next.offenders).filter((rule) => !recorded.has(rule))
|
|
2221
2235
|
: [];
|
|
2222
|
-
const
|
|
2223
|
-
|
|
2224
|
-
const
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2236
|
+
const found = countBaseline(next).rules;
|
|
2237
|
+
const rose = [];
|
|
2238
|
+
const added = [];
|
|
2239
|
+
for (const [rule, keys] of Object.entries(next.offenders)) {
|
|
2240
|
+
if (adopted.includes(rule)) continue;
|
|
2241
|
+
const listed = previous.offenders?.[rule];
|
|
2242
|
+
if (!listed && rule in counts) {
|
|
2243
|
+
if (found[rule] > counts[rule]) rose.push(`${rule} ${counts[rule]} -> ${found[rule]}`);
|
|
2244
|
+
continue;
|
|
2245
|
+
}
|
|
2246
|
+
for (const [key, count] of Object.entries(keys))
|
|
2247
|
+
if (count > (listed?.[key] ?? 0)) added.push(`[${rule}] ${key}`);
|
|
2248
|
+
}
|
|
2233
2249
|
if (rose.length || added.length) {
|
|
2234
2250
|
process.stderr.write(
|
|
2235
2251
|
`${scan.errors.join("\n")}\nMPO design guard: ${file} regressed${
|
|
2236
|
-
rose.length
|
|
2237
|
-
? `, ${rose.map((rule) => `${rule} ${ceiling(rule)} -> ${next.rules[rule]}`).join(", ")}`
|
|
2238
|
-
: ""
|
|
2252
|
+
rose.length ? `, ${rose.join(", ")}` : ""
|
|
2239
2253
|
}${
|
|
2240
2254
|
added.length
|
|
2241
2255
|
? `; new offenders:\n ${added.join("\n ")}\nFix each the way its LC rule says (LC-175: render the MPO component). A rename of a listed offender renames its key in ${file}.\n`
|
|
@@ -2245,30 +2259,34 @@ function ratchet(file, options) {
|
|
|
2245
2259
|
return 1;
|
|
2246
2260
|
}
|
|
2247
2261
|
if (options.list && scan.errors.length) process.stderr.write(`${scan.errors.join("\n")}\n`);
|
|
2248
|
-
const
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2262
|
+
const cleared =
|
|
2263
|
+
sum(
|
|
2264
|
+
Object.entries(previous.offenders ?? {}).flatMap(([rule, keys]) =>
|
|
2265
|
+
Object.entries(keys).map(([key, count]) =>
|
|
2266
|
+
Math.max(0, count - (next.offenders[rule]?.[key] ?? 0)),
|
|
2267
|
+
),
|
|
2268
|
+
),
|
|
2269
|
+
) +
|
|
2270
|
+
sum(
|
|
2271
|
+
Object.entries(counts)
|
|
2272
|
+
.filter(([rule]) => !previous.offenders?.[rule])
|
|
2273
|
+
.map(([rule, count]) => Math.max(0, count - (found[rule] ?? 0))),
|
|
2274
|
+
);
|
|
2275
|
+
const stale = "total" in previous || "rules" in previous;
|
|
2276
|
+
if ((options.tighten || options.init) && text !== formatBaseline(next)) {
|
|
2263
2277
|
write();
|
|
2264
2278
|
process.stdout.write(
|
|
2265
2279
|
adopted.length
|
|
2266
2280
|
? `MPO design guard: ${file} adopted ${adopted.join(", ")}. ${summary(scan)}.\n`
|
|
2267
|
-
: `MPO design guard: ${file}
|
|
2281
|
+
: `MPO design guard: ${file} tightened, ${cleared} offenders cleared. ${summary(scan)}.\n`,
|
|
2268
2282
|
);
|
|
2269
2283
|
return 0;
|
|
2270
2284
|
}
|
|
2271
|
-
process.stdout.write(
|
|
2285
|
+
process.stdout.write(
|
|
2286
|
+
`MPO design guard: ${file} holds at ${summary(scan)}${
|
|
2287
|
+
cleared ? `; ${cleared} cleared offenders stay listed until --tighten` : ""
|
|
2288
|
+
}${stale ? "; it still stores total and rules, which --tighten drops" : ""}.\n`,
|
|
2289
|
+
);
|
|
2272
2290
|
return 0;
|
|
2273
2291
|
}
|
|
2274
2292
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@multiplatform.one/config",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.10.0",
|
|
4
4
|
"description": "Shared build and test configuration presets for multiplatform.one",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"config",
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
"@babel/parser": "^7.29.9",
|
|
123
123
|
"@babel/plugin-transform-block-scoping": "^7.29.7",
|
|
124
124
|
"@babel/traverse": "^7.29.10",
|
|
125
|
-
"@multiplatform.one/utils": "^9.
|
|
125
|
+
"@multiplatform.one/utils": "^9.10.0",
|
|
126
126
|
"@tamagui/vite-plugin": "2.7.6",
|
|
127
127
|
"@vitejs/plugin-react": "^6.1.2",
|
|
128
128
|
"dotenv": "^17.4.2",
|