@staff0rd/assist 0.76.0 → 0.77.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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +59 -17
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -70,7 +70,7 @@ After installation, the `assist` command will be available globally.
70
70
  - `assist config list` - List all config values
71
71
  - `assist verify` - Run all verify:* commands in parallel (from run configs in assist.yml and scripts in package.json)
72
72
  - `assist verify init` - Add verify scripts to a project
73
- - `assist verify hardcoded-colors` - Check for hardcoded hex colors in src/
73
+ - `assist verify hardcoded-colors` - Check for hardcoded hex colors in src/ (supports `hardcodedColors.ignore` globs in config)
74
74
  - `assist lint` - Run lint checks for conventions not enforced by biomejs
75
75
  - `assist lint init` - Initialize Biome with standard linter config
76
76
  - `assist refactor check [pattern]` - Check for files that exceed the maximum line count
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import { Command } from "commander";
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "@staff0rd/assist",
9
- version: "0.76.0",
9
+ version: "0.77.0",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -116,6 +116,9 @@ var assistConfigSchema = z.strictObject({
116
116
  complexity: z.strictObject({
117
117
  ignore: z.array(z.string()).default(["**/*test.ts*"])
118
118
  }).default({ ignore: ["**/*test.ts*"] }),
119
+ hardcodedColors: z.strictObject({
120
+ ignore: z.array(z.string()).default([])
121
+ }).optional(),
119
122
  restructure: z.strictObject({
120
123
  ignore: z.array(z.string()).default([])
121
124
  }).optional(),
@@ -258,24 +261,52 @@ function getNestedValue(obj, path31) {
258
261
  for (const key of path31.split(".")) current = stepInto(current, key);
259
262
  return current;
260
263
  }
264
+
265
+ // src/commands/config/setNestedValue.ts
261
266
  function isPlainObject(val) {
262
267
  return val !== null && typeof val === "object" && !Array.isArray(val);
263
268
  }
264
- function ensureNestedObject(current, key) {
265
- current[key] = isPlainObject(current[key]) ? { ...current[key] } : {};
266
- return current[key];
269
+ function isNumericKey(key) {
270
+ return /^\d+$/.test(key);
267
271
  }
268
- function buildNestedPath(root, keys) {
269
- let current = root;
270
- for (let i = 0; i < keys.length - 1; i++) {
271
- current = ensureNestedObject(current, keys[i]);
272
+ function resolveKey(key) {
273
+ return isNumericKey(key) ? Number.parseInt(key, 10) : key;
274
+ }
275
+ function getItem(container, key) {
276
+ if (Array.isArray(container)) return container[key];
277
+ return container[key];
278
+ }
279
+ function setItem(container, key, value) {
280
+ if (Array.isArray(container)) container[key] = value;
281
+ else container[key] = value;
282
+ }
283
+ function ensureArray(container, key) {
284
+ const existing = getItem(container, key);
285
+ const arr = Array.isArray(existing) ? [...existing] : [];
286
+ setItem(container, key, arr);
287
+ return arr;
288
+ }
289
+ function ensureObject(container, key) {
290
+ const existing = getItem(container, key);
291
+ const obj = isPlainObject(existing) ? { ...existing } : {};
292
+ setItem(container, key, obj);
293
+ return obj;
294
+ }
295
+ function stepIntoNested(container, key, nextKey) {
296
+ const resolved = resolveKey(key);
297
+ if (nextKey !== void 0 && isNumericKey(nextKey)) {
298
+ return ensureArray(container, resolved);
272
299
  }
273
- return current;
300
+ return ensureObject(container, resolved);
274
301
  }
275
302
  function setNestedValue(obj, path31, value) {
276
303
  const keys = path31.split(".");
277
304
  const result = { ...obj };
278
- buildNestedPath(result, keys)[keys[keys.length - 1]] = value;
305
+ let current = result;
306
+ for (let i = 0; i < keys.length - 1; i++) {
307
+ current = stepIntoNested(current, keys[i], keys[i + 1]);
308
+ }
309
+ setItem(current, resolveKey(keys[keys.length - 1]), value);
279
310
  return result;
280
311
  }
281
312
 
@@ -1309,13 +1340,24 @@ import { basename as basename2, resolve } from "path";
1309
1340
 
1310
1341
  // src/commands/verify/hardcodedColors.ts
1311
1342
  import { execSync as execSync5 } from "child_process";
1343
+ import { minimatch } from "minimatch";
1312
1344
  var pattern = "0x[0-9a-fA-F]{6}|#[0-9a-fA-F]{3,6}";
1313
1345
  function hardcodedColors() {
1346
+ const ignoreGlobs = loadConfig().hardcodedColors?.ignore ?? [];
1314
1347
  try {
1315
1348
  const output = execSync5(`grep -rEnH '${pattern}' src/`, {
1316
1349
  encoding: "utf-8"
1317
1350
  });
1318
- const lines = output.trim().split("\n");
1351
+ const lines = output.trim().split("\n").filter((line) => {
1352
+ const match = line.match(/^(.+?):\d+:/);
1353
+ if (!match) return true;
1354
+ const file = match[1];
1355
+ return !ignoreGlobs.some((glob) => minimatch(file, glob));
1356
+ });
1357
+ if (lines.length === 0) {
1358
+ console.log("No hardcoded colors found.");
1359
+ process.exit(0);
1360
+ }
1319
1361
  console.log("Hardcoded colors found:\n");
1320
1362
  for (const line of lines) {
1321
1363
  const match = line.match(/^(.+):(\d+):(.+)$/);
@@ -2312,11 +2354,11 @@ import ts5 from "typescript";
2312
2354
  // src/commands/complexity/findSourceFiles.ts
2313
2355
  import fs10 from "fs";
2314
2356
  import path15 from "path";
2315
- import { minimatch } from "minimatch";
2357
+ import { minimatch as minimatch2 } from "minimatch";
2316
2358
  function applyIgnoreGlobs(files) {
2317
2359
  const { complexity } = loadConfig();
2318
2360
  return files.filter(
2319
- (f) => !complexity.ignore.some((glob) => minimatch(f, glob))
2361
+ (f) => !complexity.ignore.some((glob) => minimatch2(f, glob))
2320
2362
  );
2321
2363
  }
2322
2364
  function walk(dir, results) {
@@ -2340,7 +2382,7 @@ function findSourceFiles2(pattern2, baseDir = ".") {
2340
2382
  const results = [];
2341
2383
  if (pattern2.includes("*")) {
2342
2384
  walk(baseDir, results);
2343
- return applyIgnoreGlobs(results.filter((f) => minimatch(f, pattern2)));
2385
+ return applyIgnoreGlobs(results.filter((f) => minimatch2(f, pattern2)));
2344
2386
  }
2345
2387
  if (fs10.existsSync(pattern2) && fs10.statSync(pattern2).isFile()) {
2346
2388
  return [pattern2];
@@ -2350,7 +2392,7 @@ function findSourceFiles2(pattern2, baseDir = ".") {
2350
2392
  return applyIgnoreGlobs(results);
2351
2393
  }
2352
2394
  walk(baseDir, results);
2353
- return applyIgnoreGlobs(results.filter((f) => minimatch(f, pattern2)));
2395
+ return applyIgnoreGlobs(results.filter((f) => minimatch2(f, pattern2)));
2354
2396
  }
2355
2397
 
2356
2398
  // src/commands/complexity/shared/getNodeName.ts
@@ -3768,7 +3810,7 @@ Refactor check failed:
3768
3810
  // src/commands/refactor/check/getViolations/index.ts
3769
3811
  import { execSync as execSync22 } from "child_process";
3770
3812
  import fs15 from "fs";
3771
- import { minimatch as minimatch2 } from "minimatch";
3813
+ import { minimatch as minimatch3 } from "minimatch";
3772
3814
 
3773
3815
  // src/commands/refactor/check/getViolations/getIgnoredFiles.ts
3774
3816
  import fs14 from "fs";
@@ -3836,7 +3878,7 @@ function getViolations(pattern2, options2 = {}, maxLines = DEFAULT_MAX_LINES) {
3836
3878
  const ignoredFiles = getIgnoredFiles();
3837
3879
  const gitFiles = getGitFiles(options2);
3838
3880
  if (pattern2) {
3839
- sourceFiles = sourceFiles.filter((f) => minimatch2(f, pattern2));
3881
+ sourceFiles = sourceFiles.filter((f) => minimatch3(f, pattern2));
3840
3882
  }
3841
3883
  if (gitFiles) {
3842
3884
  sourceFiles = sourceFiles.filter((f) => gitFiles.has(f));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staff0rd/assist",
3
- "version": "0.76.0",
3
+ "version": "0.77.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {