@ariestools/toolchain 8.7.12 → 8.7.14

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/dist/bin/xy.mjs CHANGED
@@ -26231,6 +26231,270 @@ function collectExternalUsage(folderRoots, targetPackageNames) {
26231
26231
  return usage;
26232
26232
  }
26233
26233
  //#endregion
26234
+ //#region src/actions/lintlintGitignore.ts
26235
+ const GITIGNORE_NAME = "XY repository .gitignore";
26236
+ const GITIGNORE_ENVIRONMENT_VARIABLE = "XY_LINT_GITIGNORE";
26237
+ function parseConfig(source) {
26238
+ return ts.createSourceFile("eslint.config.ts", source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
26239
+ }
26240
+ function importDeclarations(sourceFile) {
26241
+ return sourceFile.statements.filter(ts.isImportDeclaration);
26242
+ }
26243
+ function moduleName(declaration) {
26244
+ return ts.isStringLiteral(declaration.moduleSpecifier) ? declaration.moduleSpecifier.text : void 0;
26245
+ }
26246
+ function importedReference(sourceFile, moduleSpecifier, importedName) {
26247
+ for (const declaration of importDeclarations(sourceFile)) {
26248
+ if (moduleName(declaration) !== moduleSpecifier) continue;
26249
+ const bindings = declaration.importClause?.namedBindings;
26250
+ if (bindings === void 0) continue;
26251
+ if (ts.isNamespaceImport(bindings)) return `${bindings.name.text}.${importedName}`;
26252
+ for (const specifier of bindings.elements) if ((specifier.propertyName?.text ?? specifier.name.text) === importedName) return specifier.name.text;
26253
+ }
26254
+ }
26255
+ function addBindingNames(name, names) {
26256
+ if (ts.isIdentifier(name)) {
26257
+ names.add(name.text);
26258
+ return;
26259
+ }
26260
+ for (const element of name.elements) if (!ts.isOmittedExpression(element)) addBindingNames(element.name, names);
26261
+ }
26262
+ function topLevelBindingNames(sourceFile) {
26263
+ const names = /* @__PURE__ */ new Set();
26264
+ for (const statement of sourceFile.statements) {
26265
+ if (ts.isImportDeclaration(statement)) {
26266
+ const clause = statement.importClause;
26267
+ if (clause?.name !== void 0) names.add(clause.name.text);
26268
+ const bindings = clause?.namedBindings;
26269
+ if (bindings !== void 0 && ts.isNamespaceImport(bindings)) names.add(bindings.name.text);
26270
+ if (bindings !== void 0 && ts.isNamedImports(bindings)) for (const element of bindings.elements) names.add(element.name.text);
26271
+ continue;
26272
+ }
26273
+ if (ts.isVariableStatement(statement)) {
26274
+ for (const declaration of statement.declarationList.declarations) addBindingNames(declaration.name, names);
26275
+ continue;
26276
+ }
26277
+ if ((ts.isClassDeclaration(statement) || ts.isEnumDeclaration(statement) || ts.isFunctionDeclaration(statement)) && statement.name !== void 0) names.add(statement.name.text);
26278
+ }
26279
+ return names;
26280
+ }
26281
+ function uniqueImportReference(sourceFile, importedName) {
26282
+ const names = topLevelBindingNames(sourceFile);
26283
+ if (!names.has(importedName)) return importedName;
26284
+ const base = `xy${importedName[0]?.toUpperCase() ?? ""}${importedName.slice(1)}`;
26285
+ let candidate = base;
26286
+ let suffix = 2;
26287
+ while (names.has(candidate)) {
26288
+ candidate = `${base}${suffix}`;
26289
+ suffix++;
26290
+ }
26291
+ return candidate;
26292
+ }
26293
+ function variableInitializers(sourceFile) {
26294
+ const initializers = /* @__PURE__ */ new Map();
26295
+ for (const statement of sourceFile.statements) {
26296
+ if (!ts.isVariableStatement(statement)) continue;
26297
+ for (const declaration of statement.declarationList.declarations) if (ts.isIdentifier(declaration.name) && declaration.initializer !== void 0) initializers.set(declaration.name.text, declaration.initializer);
26298
+ }
26299
+ return initializers;
26300
+ }
26301
+ function unwrapConfigArray(expression, initializers) {
26302
+ const visited = /* @__PURE__ */ new Set();
26303
+ let current = expression;
26304
+ while (!ts.isArrayLiteralExpression(current)) {
26305
+ if (ts.isParenthesizedExpression(current) || ts.isAsExpression(current) || ts.isSatisfiesExpression(current) || ts.isTypeAssertionExpression(current)) {
26306
+ current = current.expression;
26307
+ continue;
26308
+ }
26309
+ if (ts.isCallExpression(current)) {
26310
+ const [firstArgument] = current.arguments;
26311
+ if (firstArgument === void 0) return void 0;
26312
+ current = firstArgument;
26313
+ continue;
26314
+ }
26315
+ if (!ts.isIdentifier(current) || visited.has(current.text)) return void 0;
26316
+ visited.add(current.text);
26317
+ const initializer = initializers.get(current.text);
26318
+ if (initializer === void 0) return void 0;
26319
+ current = initializer;
26320
+ }
26321
+ return current;
26322
+ }
26323
+ function findConfigArray(sourceFile) {
26324
+ const initializers = variableInitializers(sourceFile);
26325
+ for (const statement of sourceFile.statements) {
26326
+ if (!ts.isExportAssignment(statement) || statement.isExportEquals) continue;
26327
+ return unwrapConfigArray(statement.expression, initializers);
26328
+ }
26329
+ }
26330
+ function expressionReferencesGitignore(expression, sourceFile, initializers, visited = /* @__PURE__ */ new Set()) {
26331
+ if (expression.getText(sourceFile).includes(".gitignore")) return true;
26332
+ if (!ts.isIdentifier(expression) || visited.has(expression.text)) return false;
26333
+ visited.add(expression.text);
26334
+ const initializer = initializers.get(expression.text);
26335
+ return initializer !== void 0 && expressionReferencesGitignore(initializer, sourceFile, initializers, visited);
26336
+ }
26337
+ function enablesGitignoreResolution(expression) {
26338
+ if (expression === void 0 || !ts.isObjectLiteralExpression(expression)) return false;
26339
+ return expression.properties.some((property) => {
26340
+ if (!ts.isPropertyAssignment(property)) return false;
26341
+ return property.name.getText().replaceAll(/["']/g, "") === "gitignoreResolution" && property.initializer.kind === ts.SyntaxKind.TrueKeyword;
26342
+ });
26343
+ }
26344
+ function isRequiredGitignoreCall(node, includeReference, sourceFile, initializers) {
26345
+ if (!ts.isCallExpression(node) || node.expression.getText(sourceFile) !== includeReference) return false;
26346
+ const [ignorePath, options] = node.arguments;
26347
+ return ignorePath !== void 0 && expressionReferencesGitignore(ignorePath, sourceFile, initializers) && enablesGitignoreResolution(options);
26348
+ }
26349
+ function findRequiredGitignoreCall(configArray, includeReference, sourceFile, initializers) {
26350
+ let found;
26351
+ function visit(node) {
26352
+ if (found !== void 0) return;
26353
+ if (isRequiredGitignoreCall(node, includeReference, sourceFile, initializers)) {
26354
+ found = node;
26355
+ return;
26356
+ }
26357
+ ts.forEachChild(node, visit);
26358
+ }
26359
+ visit(configArray);
26360
+ return found;
26361
+ }
26362
+ function isGitignoreControlCondition(expression, sourceFile) {
26363
+ const compact = expression.getText(sourceFile).replaceAll(/\s/g, "");
26364
+ return [
26365
+ `globalThis.process.env.${GITIGNORE_ENVIRONMENT_VARIABLE}==='false'`,
26366
+ `'false'===globalThis.process.env.${GITIGNORE_ENVIRONMENT_VARIABLE}`,
26367
+ `process.env.${GITIGNORE_ENVIRONMENT_VARIABLE}==='false'`,
26368
+ `'false'===process.env.${GITIGNORE_ENVIRONMENT_VARIABLE}`
26369
+ ].includes(compact);
26370
+ }
26371
+ function isControlledGitignoreCall(call, configArray, sourceFile) {
26372
+ let current = call;
26373
+ while (current !== configArray && current.parent !== void 0) {
26374
+ current = current.parent;
26375
+ if (ts.isConditionalExpression(current) && isGitignoreControlCondition(current.condition, sourceFile)) return true;
26376
+ }
26377
+ return false;
26378
+ }
26379
+ function hasGitignoreConfig(source) {
26380
+ const sourceFile = parseConfig(source);
26381
+ const includeReference = importedReference(sourceFile, "eslint/config", "includeIgnoreFile");
26382
+ const configArray = findConfigArray(sourceFile);
26383
+ if (includeReference === void 0 || configArray === void 0) return false;
26384
+ const call = findRequiredGitignoreCall(configArray, includeReference, sourceFile, variableInitializers(sourceFile));
26385
+ return call !== void 0 && isControlledGitignoreCall(call, configArray, sourceFile);
26386
+ }
26387
+ function updateNamedImport(declaration, importedName, referenceName, sourceFile) {
26388
+ const clause = declaration.importClause;
26389
+ const bindings = clause?.namedBindings;
26390
+ const elements = bindings !== void 0 && ts.isNamedImports(bindings) ? [...bindings.elements] : [];
26391
+ const namedImports = ts.factory.createNamedImports([...elements, ts.factory.createImportSpecifier(false, importedName === referenceName ? void 0 : ts.factory.createIdentifier(importedName), ts.factory.createIdentifier(referenceName))]);
26392
+ const updatedClause = ts.factory.updateImportClause(clause ?? ts.factory.createImportClause(false, void 0, namedImports), false, clause?.name, namedImports);
26393
+ const updated = ts.factory.updateImportDeclaration(declaration, declaration.modifiers, updatedClause, declaration.moduleSpecifier, declaration.attributes);
26394
+ const printer = ts.createPrinter({
26395
+ newLine: ts.NewLineKind.LineFeed,
26396
+ omitTrailingSemicolon: true
26397
+ });
26398
+ return {
26399
+ end: declaration.getEnd(),
26400
+ start: declaration.getStart(sourceFile),
26401
+ text: printer.printNode(ts.EmitHint.Unspecified, updated, sourceFile)
26402
+ };
26403
+ }
26404
+ function resolveImportReference(sourceFile, moduleSpecifier, importedName, newImports) {
26405
+ const existingReference = importedReference(sourceFile, moduleSpecifier, importedName);
26406
+ if (existingReference !== void 0) return { reference: existingReference };
26407
+ const referenceName = uniqueImportReference(sourceFile, importedName);
26408
+ for (const declaration of importDeclarations(sourceFile)) {
26409
+ if (moduleName(declaration) !== moduleSpecifier || declaration.importClause?.isTypeOnly === true) continue;
26410
+ const bindings = declaration.importClause?.namedBindings;
26411
+ if (bindings !== void 0 && ts.isNamespaceImport(bindings)) return { reference: `${bindings.name.text}.${importedName}` };
26412
+ return {
26413
+ edit: updateNamedImport(declaration, importedName, referenceName, sourceFile),
26414
+ reference: referenceName
26415
+ };
26416
+ }
26417
+ const importedBinding = importedName === referenceName ? importedName : `${importedName} as ${referenceName}`;
26418
+ newImports.push(`import { ${importedBinding} } from '${moduleSpecifier}'`);
26419
+ return { reference: referenceName };
26420
+ }
26421
+ function newImportsEdit(sourceFile, imports) {
26422
+ if (imports.length === 0) return void 0;
26423
+ const lastImport = importDeclarations(sourceFile).at(-1);
26424
+ if (lastImport === void 0) return {
26425
+ end: 0,
26426
+ start: 0,
26427
+ text: `${imports.join("\n")}\n\n`
26428
+ };
26429
+ return {
26430
+ end: lastImport.getEnd(),
26431
+ start: lastImport.getEnd(),
26432
+ text: `\n${imports.join("\n")}`
26433
+ };
26434
+ }
26435
+ function lineIndent(source, position) {
26436
+ const lineStart = source.lastIndexOf("\n", position - 1) + 1;
26437
+ return /^\s*/.exec(source.slice(lineStart, position))?.[0] ?? "";
26438
+ }
26439
+ function gitignoreConfigEntryLines(indent, includeReference = "includeIgnoreFile", fileUrlReference = "fileURLToPath") {
26440
+ return [
26441
+ `${indent}globalThis.process.env.${GITIGNORE_ENVIRONMENT_VARIABLE} === 'false'`,
26442
+ `${indent} ? { ignores: [] }`,
26443
+ `${indent} : ${includeReference}(${fileUrlReference}(new URL('.gitignore', import.meta.url)), {`,
26444
+ `${indent} gitignoreResolution: true,`,
26445
+ `${indent} name: '${GITIGNORE_NAME}',`,
26446
+ `${indent} }),`
26447
+ ];
26448
+ }
26449
+ function controlledGitignoreCallEdit(source, sourceFile, call) {
26450
+ const indent = lineIndent(source, call.getStart(sourceFile));
26451
+ return {
26452
+ end: call.getEnd(),
26453
+ start: call.getStart(sourceFile),
26454
+ text: [
26455
+ `globalThis.process.env.${GITIGNORE_ENVIRONMENT_VARIABLE} === 'false'`,
26456
+ `${indent} ? { ignores: [] }`,
26457
+ `${indent} : ${call.getText(sourceFile)}`
26458
+ ].join("\n")
26459
+ };
26460
+ }
26461
+ function configArrayEdit(source, sourceFile, array, includeReference, fileUrlReference) {
26462
+ const start = array.getStart(sourceFile) + 1;
26463
+ const indent = `${lineIndent(source, array.getStart(sourceFile))} `;
26464
+ return {
26465
+ end: start,
26466
+ start,
26467
+ text: `\n${gitignoreConfigEntryLines(indent, includeReference, fileUrlReference).join("\n")}${source[start] === "\n" || source[start] === "\r" ? "" : `\n${indent}`}`
26468
+ };
26469
+ }
26470
+ function applyEdits(source, edits) {
26471
+ let updated = source;
26472
+ const descendingEdits = [...edits].toSorted((left, right) => right.start - left.start);
26473
+ for (const edit of descendingEdits) updated = `${updated.slice(0, edit.start)}${edit.text}${updated.slice(edit.end)}`;
26474
+ return updated;
26475
+ }
26476
+ function addGitignoreConfig(source) {
26477
+ if (hasGitignoreConfig(source)) return source;
26478
+ const sourceFile = parseConfig(source);
26479
+ const configArray = findConfigArray(sourceFile);
26480
+ if (configArray === void 0) return void 0;
26481
+ const existingIncludeReference = importedReference(sourceFile, "eslint/config", "includeIgnoreFile");
26482
+ if (existingIncludeReference !== void 0) {
26483
+ const existingCall = findRequiredGitignoreCall(configArray, existingIncludeReference, sourceFile, variableInitializers(sourceFile));
26484
+ if (existingCall !== void 0) return applyEdits(source, [controlledGitignoreCallEdit(source, sourceFile, existingCall)]);
26485
+ }
26486
+ const edits = [];
26487
+ const newImports = [];
26488
+ const includeImport = resolveImportReference(sourceFile, "eslint/config", "includeIgnoreFile", newImports);
26489
+ const fileUrlImport = resolveImportReference(sourceFile, "node:url", "fileURLToPath", newImports);
26490
+ if (includeImport.edit !== void 0) edits.push(includeImport.edit);
26491
+ if (fileUrlImport.edit !== void 0) edits.push(fileUrlImport.edit);
26492
+ const importsEdit = newImportsEdit(sourceFile, newImports);
26493
+ if (importsEdit !== void 0) edits.push(importsEdit);
26494
+ edits.push(configArrayEdit(source, sourceFile, configArray, includeImport.reference, fileUrlImport.reference));
26495
+ return applyEdits(source, edits);
26496
+ }
26497
+ //#endregion
26234
26498
  //#region src/actions/lint-init.ts
26235
26499
  function askConfirmation(question) {
26236
26500
  const rl = createInterface({
@@ -26280,16 +26544,21 @@ function getBarrelDescriptorsForRepo(isReact) {
26280
26544
  function formatDisallowedArray(name, imports, message) {
26281
26545
  return `const ${name} = [\n${imports.map((i) => ` { name: '${i}', message: "${message}" },`).join("\n")}\n]`;
26282
26546
  }
26283
- function generateEslintConfig({ barrels, isReact }) {
26547
+ function generateEslintConfig({ barrels, hasGitignore, isReact }) {
26284
26548
  const configPkg = isReact ? "@ariestools/eslint-config-react-flat" : "@ariestools/eslint-config-flat";
26285
26549
  const defaultConfigVarName = "xylabsConfig";
26286
26550
  const recommendedCall = "recommendedConfig({ tier: 3, isTypeChecked: true })";
26287
26551
  const lines = [];
26552
+ if (hasGitignore) lines.push("import { fileURLToPath } from 'node:url'", "");
26288
26553
  if (isReact) lines.push("import {", " configReactStorybook,", " recommendedConfig,", `} from '${configPkg}'`, "");
26289
26554
  else lines.push(`import { recommendedConfig } from '${configPkg}'`, "");
26290
- lines.push("import type { Linter } from 'eslint'", "", `const ${defaultConfigVarName} = ${recommendedCall}`, "");
26555
+ lines.push("import type { Linter } from 'eslint'");
26556
+ if (hasGitignore) lines.push("import { includeIgnoreFile } from 'eslint/config'");
26557
+ lines.push("", `const ${defaultConfigVarName} = ${recommendedCall}`, "");
26291
26558
  for (const barrel of barrels) lines.push(formatDisallowedArray(barrel.configVarName, barrel.imports, barrel.message), "");
26292
- lines.push("const config: Linter.Config[] = [", " { ignores: ['.yarn/**', 'build', '**/build/**', '**/dist/**', 'dist', 'node_modules/**', '**/node_modules/**', '**/*.md', '.claude/worktrees/*'] },", ` ...${defaultConfigVarName},`);
26559
+ lines.push("const config: Linter.Config[] = [");
26560
+ if (hasGitignore) lines.push(...gitignoreConfigEntryLines(" "));
26561
+ lines.push(" { ignores: ['.yarn/**', 'build', '**/build/**', '**/dist/**', 'dist', 'node_modules/**', '**/node_modules/**', '**/*.md', '.claude/worktrees/*'] },", ` ...${defaultConfigVarName},`);
26293
26562
  if (isReact) lines.push(" ...configReactStorybook,");
26294
26563
  if (barrels.length > 0) {
26295
26564
  lines.push(" {", " rules:", " {", " 'no-restricted-imports': [", " 'warn',", " {", " paths: [");
@@ -26385,6 +26654,7 @@ async function lintInit({ isVerbose } = {}) {
26385
26654
  for (const descriptor of getBarrelDescriptorsForRepo(isReact)) if (await askConfirmation(chalk.cyan(`Disallow ${descriptor.pkg} barrel imports? (y/N) `))) enabledBarrels.push(descriptor);
26386
26655
  writeFileSync(configPath, generateEslintConfig({
26387
26656
  barrels: resolveEnabledBarrels(cwd, enabledBarrels, isVerbose),
26657
+ hasGitignore: existsSync(PATH.resolve(cwd, ".gitignore")),
26388
26658
  isReact
26389
26659
  }), "utf8");
26390
26660
  console.log(chalk.green("Generated eslint.config.ts"));
@@ -31478,6 +31748,7 @@ import path from 'node:path'
31478
31748
  import { performance } from 'node:perf_hooks'
31479
31749
  import readline from 'node:readline'
31480
31750
  import { ESLint } from 'eslint'
31751
+ import { includeIgnoreFile } from 'eslint/config'
31481
31752
 
31482
31753
  const marker = ${JSON.stringify(lintNextResultMarker)}
31483
31754
  const cycleRuleFilePatterns = ${JSON.stringify([
@@ -31556,15 +31827,29 @@ function cycleOverrideBlock(options) {
31556
31827
  }
31557
31828
  }
31558
31829
 
31830
+ function gitignoreOverrideBlock(options) {
31831
+ if (options.gitignorePath === undefined) return undefined
31832
+ return includeIgnoreFile(options.gitignorePath, {
31833
+ gitignoreResolution: true,
31834
+ name: 'XY repository .gitignore',
31835
+ })
31836
+ }
31837
+
31838
+ function additionalOverrideBlocks(options) {
31839
+ return [gitignoreOverrideBlock(options), cycleOverrideBlock(options)].filter(Boolean)
31840
+ }
31841
+
31559
31842
  async function createLintEngine(cwd, options) {
31560
31843
  // analyzeTier (legacy) or configOverride force a recommendedConfig preset
31561
31844
  const overrideSpec = options.configOverride ?? options.analyzeTier
31562
31845
  if (overrideSpec) {
31563
- let overrideConfig = await resolveAnalyzeOverrideConfig(cwd, overrideSpec)
31846
+ const gitignoreBlock = gitignoreOverrideBlock(options)
31564
31847
  const cycleBlock = cycleOverrideBlock(options)
31565
- if (cycleBlock !== undefined) {
31566
- overrideConfig = [...overrideConfig, cycleBlock]
31567
- }
31848
+ const overrideConfig = [
31849
+ ...(gitignoreBlock === undefined ? [] : [gitignoreBlock]),
31850
+ ...await resolveAnalyzeOverrideConfig(cwd, overrideSpec),
31851
+ ...(cycleBlock === undefined ? [] : [cycleBlock]),
31852
+ ]
31568
31853
  return new ESLint({
31569
31854
  cache: options.cache,
31570
31855
  cacheLocation: options.cacheLocation ?? path.join(cwd, '.eslintcache'),
@@ -31586,12 +31871,12 @@ async function createLintEngine(cwd, options) {
31586
31871
  cwd,
31587
31872
  fix: options.fix,
31588
31873
  ignorePatterns: options.ignorePatterns ?? defaultIgnorePatterns,
31589
- overrideConfig: cycleOverrideBlock(options),
31874
+ overrideConfig: additionalOverrideBlocks(options),
31590
31875
  warnIgnored: false,
31591
31876
  })
31592
31877
  }
31593
31878
 
31594
- async function runJob(job) {
31879
+ async function runJobWithConfiguredEnvironment(job) {
31595
31880
  const cwd = job.cwd
31596
31881
  const options = job.options ?? {}
31597
31882
  const profile = options.profile === true
@@ -31644,6 +31929,17 @@ async function runJob(job) {
31644
31929
  return payload
31645
31930
  }
31646
31931
 
31932
+ async function runJob(job) {
31933
+ const previousGitignore = process.env.XY_LINT_GITIGNORE
31934
+ process.env.XY_LINT_GITIGNORE = job.options?.gitignore === false ? 'false' : 'true'
31935
+ try {
31936
+ return await runJobWithConfiguredEnvironment(job)
31937
+ } finally {
31938
+ if (previousGitignore === undefined) delete process.env.XY_LINT_GITIGNORE
31939
+ else process.env.XY_LINT_GITIGNORE = previousGitignore
31940
+ }
31941
+ }
31942
+
31647
31943
  const rl = readline.createInterface({ input: process.stdin, crlfDelay: Infinity })
31648
31944
  for await (const line of rl) {
31649
31945
  const trimmed = line.trim()
@@ -32007,7 +32303,7 @@ function emptyPackageResult(pkg) {
32007
32303
  * Classify packages, skip empty/meta as configured, then lint the rest via
32008
32304
  * the persistent ESLint worker pool.
32009
32305
  */
32010
- async function runLintNextPackages({ analyze, analyzeTier, cache, concurrency, cycleDepth, fix, meta, onPackageResult, profile, rootDir, skipEmpty, tierContext, typeChecked, verbose, workspaces }) {
32306
+ async function runLintNextPackages({ analyze, analyzeTier, cache, concurrency, cycleDepth, fix, gitignore, meta, onPackageResult, profile, rootDir, skipEmpty, tierContext, typeChecked, verbose, workspaces }) {
32011
32307
  const forceFull = workspaces.length === 1;
32012
32308
  const classified = workspaces.map((ws) => {
32013
32309
  return {
@@ -32029,6 +32325,8 @@ async function runLintNextPackages({ analyze, analyzeTier, cache, concurrency, c
32029
32325
  }
32030
32326
  const poolSize = Math.min(Math.max(1, concurrency), toLint.length);
32031
32327
  const pool = new LintWorkerPool(rootDir, poolSize);
32328
+ const repositoryGitignorePath = PATH.resolve(rootDir, ".gitignore");
32329
+ const gitignorePath = gitignore && existsSync(repositoryGitignorePath) ? repositoryGitignorePath : void 0;
32032
32330
  if (profile) {
32033
32331
  console.log(chalk.gray(` ESLint workers: ${poolSize} (persistent pool)`));
32034
32332
  if (typeChecked !== "auto") console.log(chalk.gray(` type-checked: ${typeChecked ? "forced on" : "forced off"}`));
@@ -32056,6 +32354,8 @@ async function runLintNextPackages({ analyze, analyzeTier, cache, concurrency, c
32056
32354
  configOverride: analyze ? void 0 : configOverride,
32057
32355
  cycleDepth,
32058
32356
  fix,
32357
+ gitignore,
32358
+ gitignorePath,
32059
32359
  profile,
32060
32360
  verbose
32061
32361
  }
@@ -32526,13 +32826,14 @@ function resolveTierForLint(analyze, rootDir) {
32526
32826
  tierContext: analyzeContext.kind === "ready" ? analyzeContext.tierContext : detectedContext.hasXylabsConfig ? detectedContext : void 0
32527
32827
  };
32528
32828
  }
32529
- function logLintProfileHeader(cache, typeChecked, detectedContext, meta, skipEmpty) {
32829
+ function logLintProfileHeader(cache, gitignore, typeChecked, detectedContext, meta, skipEmpty) {
32530
32830
  console.log(chalk.gray(` ESLint cache: ${cache ? "on" : "off"}`));
32831
+ console.log(chalk.gray(` .gitignore: ${gitignore ? "on" : "off"}`));
32531
32832
  const typeCheckedLabel = typeChecked === "auto" ? `auto (project ${detectedContext.isTypeChecked ? "on" : "off"})` : typeChecked ? "forced on" : "forced off";
32532
32833
  console.log(chalk.gray(` type-checked: ${typeCheckedLabel}`));
32533
32834
  console.log(chalk.gray(` meta packages: ${meta} · skip empty: ${skipEmpty ? "on" : "off"}`));
32534
32835
  }
32535
- async function lintNext({ analyze = false, cache = true, cycleDepth, fix = false, jobs, meta = "full", pkg, profile = false, skipEmpty = true, typeChecked = "auto", verbose = false, workspaces: targetWorkspaces }) {
32836
+ async function lintNext({ analyze = false, cache = true, cycleDepth, fix = false, gitignore = true, jobs, meta = "full", pkg, profile = false, skipEmpty = true, typeChecked = "auto", verbose = false, workspaces: targetWorkspaces }) {
32536
32837
  const rootDir = INIT_CWD();
32537
32838
  const { analyzeContext, detectedContext, tierContext } = resolveTierForLint(analyze, rootDir);
32538
32839
  if (analyzeContext.kind === "invalid") return resultFromExitCode(1);
@@ -32543,7 +32844,7 @@ async function lintNext({ analyze = false, cache = true, cycleDepth, fix = false
32543
32844
  const analyzeStarted = Date.now();
32544
32845
  const label = getLintLabel(analyze, fix, cycleDepth);
32545
32846
  if (analyze && tierContext !== void 0) printAnalyzeRunHeader(workspaces);
32546
- if (profile) logLintProfileHeader(cache, typeChecked, detectedContext, meta, skipEmpty);
32847
+ if (profile) logLintProfileHeader(cache, gitignore, typeChecked, detectedContext, meta, skipEmpty);
32547
32848
  return finishLintNext({
32548
32849
  analyze,
32549
32850
  analyzeStarted,
@@ -32556,6 +32857,7 @@ async function lintNext({ analyze = false, cache = true, cycleDepth, fix = false
32556
32857
  concurrency: jobs,
32557
32858
  cycleDepth,
32558
32859
  fix,
32860
+ gitignore,
32559
32861
  label,
32560
32862
  meta,
32561
32863
  onPackageResult: (index, total, result) => {
@@ -32587,9 +32889,11 @@ function shouldUseIncremental$2(incremental) {
32587
32889
  function shouldUseIncrementalLint({ analyze, fix, incremental, pkg }) {
32588
32890
  return pkg === void 0 && fix !== true && analyze !== true && shouldUseIncremental$2(incremental);
32589
32891
  }
32590
- function lintOptionsHash({ cycleDepth }) {
32892
+ function lintOptionsHash({ cycleDepth, gitignore }) {
32893
+ const gitignorePath = PATH.resolve(INIT_CWD(), ".gitignore");
32591
32894
  return {
32592
32895
  cycleDepth,
32896
+ gitignore: gitignore === false ? false : existsSync(gitignorePath) ? readFileSync(gitignorePath, "utf8") : null,
32593
32897
  strict: isStrictMode()
32594
32898
  };
32595
32899
  }
@@ -32597,13 +32901,14 @@ const lintPackage = ({ pkg, fix, verbose }) => {
32597
32901
  const pm = getPackageManager();
32598
32902
  return runSteps(`${fix ?? false ? "Fix" : "Lint"} [${pkg}]`, [pm.runInWorkspace(pkg, fix ?? false ? "package-fix" : verbose ?? false ? "package-lint-verbose" : "package-lint")]);
32599
32903
  };
32600
- async function lintIncremental({ cache, cycleDepth, fix, jobs, meta, profile, skipEmpty, typeChecked, verbose, workspaces: targetWorkspaces }) {
32904
+ async function lintIncremental({ cache, cycleDepth, fix, gitignore, jobs, meta, profile, skipEmpty, typeChecked, verbose, workspaces: targetWorkspaces }) {
32601
32905
  const pm = getPackageManager();
32602
32906
  const allWorkspaces = targetWorkspaces ?? pm.listWorkspaces();
32603
32907
  if (allWorkspaces.length === 0) return await lintNext({
32604
32908
  cache,
32605
32909
  cycleDepth,
32606
32910
  fix,
32911
+ gitignore,
32607
32912
  jobs,
32608
32913
  meta,
32609
32914
  profile,
@@ -32613,7 +32918,10 @@ async function lintIncremental({ cache, cycleDepth, fix, jobs, meta, profile, sk
32613
32918
  });
32614
32919
  const plan = createIncrementalPlan({
32615
32920
  action: "lint",
32616
- options: lintOptionsHash({ cycleDepth }),
32921
+ options: lintOptionsHash({
32922
+ cycleDepth,
32923
+ gitignore
32924
+ }),
32617
32925
  pm,
32618
32926
  isVerbose: verbose,
32619
32927
  workspaces: allWorkspaces
@@ -32623,7 +32931,10 @@ async function lintIncremental({ cache, cycleDepth, fix, jobs, meta, profile, sk
32623
32931
  console.log(chalk.gray(" No changed packages to lint."));
32624
32932
  writeIncrementalSnapshot({
32625
32933
  action: "lint",
32626
- options: lintOptionsHash({ cycleDepth }),
32934
+ options: lintOptionsHash({
32935
+ cycleDepth,
32936
+ gitignore
32937
+ }),
32627
32938
  pm,
32628
32939
  workspaces: allWorkspaces
32629
32940
  });
@@ -32633,6 +32944,7 @@ async function lintIncremental({ cache, cycleDepth, fix, jobs, meta, profile, sk
32633
32944
  cache,
32634
32945
  cycleDepth,
32635
32946
  fix,
32947
+ gitignore,
32636
32948
  jobs,
32637
32949
  meta,
32638
32950
  profile,
@@ -32643,13 +32955,16 @@ async function lintIncremental({ cache, cycleDepth, fix, jobs, meta, profile, sk
32643
32955
  });
32644
32956
  if (isCleanResult(result)) writeIncrementalSnapshot({
32645
32957
  action: "lint",
32646
- options: lintOptionsHash({ cycleDepth }),
32958
+ options: lintOptionsHash({
32959
+ cycleDepth,
32960
+ gitignore
32961
+ }),
32647
32962
  pm,
32648
32963
  workspaces: allWorkspaces
32649
32964
  });
32650
32965
  return result;
32651
32966
  }
32652
- const lint = ({ analyze, cache, cycleDepth, fix, incremental, jobs, meta, prev, pkg, profile, skipEmpty, typeChecked, verbose, workspaces }) => {
32967
+ const lint = ({ analyze, cache, cycleDepth, fix, gitignore, incremental, jobs, meta, prev, pkg, profile, skipEmpty, typeChecked, verbose, workspaces }) => {
32653
32968
  if (analyze === true && fix === true) {
32654
32969
  console.error("The --analyze option cannot be combined with --fix");
32655
32970
  return 1;
@@ -32664,6 +32979,7 @@ const lint = ({ analyze, cache, cycleDepth, fix, incremental, jobs, meta, prev,
32664
32979
  cache,
32665
32980
  cycleDepth,
32666
32981
  fix,
32982
+ gitignore,
32667
32983
  jobs,
32668
32984
  meta,
32669
32985
  profile,
@@ -32676,6 +32992,7 @@ const lint = ({ analyze, cache, cycleDepth, fix, incremental, jobs, meta, prev,
32676
32992
  analyze,
32677
32993
  cache,
32678
32994
  fix,
32995
+ gitignore,
32679
32996
  jobs,
32680
32997
  meta,
32681
32998
  pkg,
@@ -39938,7 +40255,15 @@ function fixRedundantRules(eslintConfigPath, redundant) {
39938
40255
  }
39939
40256
  }
39940
40257
  function formatConfigFile(eslintConfigPath) {
39941
- spawnSync("eslint", ["--shouldFix", eslintConfigPath], { stdio: "inherit" });
40258
+ spawnSync("eslint", ["--fix", eslintConfigPath], { stdio: "inherit" });
40259
+ }
40260
+ function fixGitignoreConfig(eslintConfigPath) {
40261
+ const source = readFileSync(eslintConfigPath, "utf8");
40262
+ const updated = addGitignoreConfig(source);
40263
+ if (updated === void 0 || updated === source) return false;
40264
+ writeFileSync(eslintConfigPath, updated, "utf8");
40265
+ console.log(chalk.green("Fixed: added repository .gitignore to ESLint config"));
40266
+ return true;
39942
40267
  }
39943
40268
  function fixConfigMismatch(eslintConfigPath, configDir, source, sharedPkg, expectedPkg) {
39944
40269
  writeFileSync(eslintConfigPath, source.replaceAll(sharedPkg, () => expectedPkg), "utf8");
@@ -40002,6 +40327,19 @@ const LINTLINT_RULES = [
40002
40327
  fixable: true,
40003
40328
  id: "lintlint.config-package"
40004
40329
  },
40330
+ {
40331
+ check: ({ eslintConfigPath, hasGitignoreFile, source }, { fix }) => {
40332
+ if (!hasGitignoreFile || hasGitignoreConfig(source)) return {};
40333
+ const message = "ESLint config does not include the repository .gitignore with Git-relative pattern resolution";
40334
+ if (!fix) return { diagnostics: lintlintDiagnostics("lintlint.gitignore", [message]) };
40335
+ if (fixGitignoreConfig(eslintConfigPath)) return { fixedCount: 1 };
40336
+ return { diagnostics: lintlintDiagnostics("lintlint.gitignore", [`${message}; automatic fix could not find the exported flat-config array`]) };
40337
+ },
40338
+ defaultLevel: "warn",
40339
+ description: "ESLint config includes the repository .gitignore for CLI and editor parity",
40340
+ fixable: true,
40341
+ id: "lintlint.gitignore"
40342
+ },
40005
40343
  {
40006
40344
  check: ({ eslintConfigPath, results }, { fix }) => {
40007
40345
  if (results.redundant.length === 0) return {};
@@ -40037,6 +40375,7 @@ async function runLintlintChecks(eslintConfigPath, configDir, source, sharedPkg,
40037
40375
  context: {
40038
40376
  configDir,
40039
40377
  eslintConfigPath,
40378
+ hasGitignoreFile: existsSync(PATH.resolve(configDir, ".gitignore")),
40040
40379
  isVerbose,
40041
40380
  mismatch,
40042
40381
  results,
@@ -40049,7 +40388,7 @@ async function runLintlintChecks(eslintConfigPath, configDir, source, sharedPkg,
40049
40388
  strict: isStrictMode()
40050
40389
  });
40051
40390
  if (shouldFix && result.envelope.data.fixedCount > 0) formatConfigFile(eslintConfigPath);
40052
- if (result.envelope.data.diagnostics.length === 0 && result.envelope.data.fixedCount === 0) console.log(chalk.green("No redundant or overridden rules found"));
40391
+ if (result.envelope.data.diagnostics.length === 0 && result.envelope.data.fixedCount === 0) console.log(chalk.green("ESLint config checks passed"));
40053
40392
  return result;
40054
40393
  }
40055
40394
  async function lintlint({ shouldFix, isVerbose } = {}) {
@@ -42263,13 +42602,14 @@ const relintPackage = ({ pkg, fix, verbose }) => {
42263
42602
  const pm = getPackageManager();
42264
42603
  return runSteps(`${fix ?? false ? "Fix" : "Lint"} [${pkg}]`, [pm.runInWorkspace(pkg, fix ?? false ? "package-fix" : verbose ?? false ? "package-lint-verbose" : "package-lint")]);
42265
42604
  };
42266
- const relint = ({ fix, jobs, pkg, prev, verbose }) => {
42605
+ const relint = ({ fix, gitignore, jobs, pkg, prev, verbose }) => {
42267
42606
  if (!(prev ?? false)) {
42268
42607
  cleanLintCaches(pkg);
42269
42608
  clearIncrementalSnapshot("lint");
42270
42609
  return lint({
42271
42610
  cache: false,
42272
42611
  fix,
42612
+ gitignore,
42273
42613
  incremental: true,
42274
42614
  jobs,
42275
42615
  pkg,
@@ -51482,7 +51822,7 @@ const fixCommand = {
51482
51822
  function lintLintBuilder(yargs) {
51483
51823
  return yargs.option("fix", {
51484
51824
  default: false,
51485
- description: "Remove redundant rules from local config",
51825
+ description: "Fix supported ESLint config issues",
51486
51826
  type: "boolean"
51487
51827
  }).option("rules", {
51488
51828
  default: false,
@@ -51504,7 +51844,7 @@ async function handleLintLintCommand(argv) {
51504
51844
  const lintLintSubcommand = {
51505
51845
  builder: lintLintBuilder,
51506
51846
  command: "lint",
51507
- describe: "Check redundant or overridden ESLint rules vs shared config",
51847
+ describe: "Check the local ESLint config against toolchain conventions",
51508
51848
  handler: handleLintLintCommand
51509
51849
  };
51510
51850
  const lintlintCommand = {
@@ -51575,6 +51915,10 @@ const runCommand = {
51575
51915
  default: false,
51576
51916
  description: "Clear lint caches and run ESLint from a fresh snapshot",
51577
51917
  type: "boolean"
51918
+ }).option("gitignore", {
51919
+ default: true,
51920
+ description: "Ignore files matched by the repository root .gitignore (disable with --no-gitignore)",
51921
+ type: "boolean"
51578
51922
  }).option("next", {
51579
51923
  default: false,
51580
51924
  description: "Deprecated: per-package lint is the default",
@@ -51617,6 +51961,7 @@ const runCommand = {
51617
51961
  }
51618
51962
  if (Boolean(argv.fresh)) {
51619
51963
  await withEnvelope("lint", () => relint({
51964
+ gitignore: argv.gitignore,
51620
51965
  jobs: argv.jobs,
51621
51966
  pkg: argv.package,
51622
51967
  prev: argv.prev,
@@ -51629,6 +51974,7 @@ const runCommand = {
51629
51974
  analyze: argv.analyze,
51630
51975
  cache: argv.cache,
51631
51976
  fix: argv.fix,
51977
+ gitignore: argv.gitignore,
51632
51978
  incremental: argv.incremental !== false,
51633
51979
  jobs: argv.jobs,
51634
51980
  meta: argv.meta,