@ariestools/toolchain 8.7.12 → 8.7.13
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/actions/lint-init.d.ts.map +1 -1
- package/dist/actions/lint.d.ts +3 -1
- package/dist/actions/lint.d.ts.map +1 -1
- package/dist/actions/lintNext.d.ts +6 -1
- package/dist/actions/lintNext.d.ts.map +1 -1
- package/dist/actions/lintNextRun.d.ts +2 -1
- package/dist/actions/lintNextRun.d.ts.map +1 -1
- package/dist/actions/lintNextWorker.d.ts +3 -1
- package/dist/actions/lintNextWorker.d.ts.map +1 -1
- package/dist/actions/lintlint.d.ts +1 -0
- package/dist/actions/lintlint.d.ts.map +1 -1
- package/dist/actions/lintlintGitignore.d.ts +4 -0
- package/dist/actions/lintlintGitignore.d.ts.map +1 -0
- package/dist/actions/relint.d.ts +2 -1
- package/dist/actions/relint.d.ts.map +1 -1
- package/dist/bin/xy.mjs +278 -23
- package/dist/bin/xy.mjs.map +1 -1
- package/dist/xy/lint/lint/runCommand.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/bin/xy.mjs
CHANGED
|
@@ -26231,6 +26231,191 @@ 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
|
+
function parseConfig(source) {
|
|
26237
|
+
return ts.createSourceFile("eslint.config.ts", source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
26238
|
+
}
|
|
26239
|
+
function importDeclarations(sourceFile) {
|
|
26240
|
+
return sourceFile.statements.filter(ts.isImportDeclaration);
|
|
26241
|
+
}
|
|
26242
|
+
function moduleName(declaration) {
|
|
26243
|
+
return ts.isStringLiteral(declaration.moduleSpecifier) ? declaration.moduleSpecifier.text : void 0;
|
|
26244
|
+
}
|
|
26245
|
+
function importedReference(sourceFile, moduleSpecifier, importedName) {
|
|
26246
|
+
for (const declaration of importDeclarations(sourceFile)) {
|
|
26247
|
+
if (moduleName(declaration) !== moduleSpecifier) continue;
|
|
26248
|
+
const bindings = declaration.importClause?.namedBindings;
|
|
26249
|
+
if (bindings === void 0) continue;
|
|
26250
|
+
if (ts.isNamespaceImport(bindings)) return `${bindings.name.text}.${importedName}`;
|
|
26251
|
+
for (const specifier of bindings.elements) if ((specifier.propertyName?.text ?? specifier.name.text) === importedName) return specifier.name.text;
|
|
26252
|
+
}
|
|
26253
|
+
}
|
|
26254
|
+
function variableInitializers(sourceFile) {
|
|
26255
|
+
const initializers = /* @__PURE__ */ new Map();
|
|
26256
|
+
for (const statement of sourceFile.statements) {
|
|
26257
|
+
if (!ts.isVariableStatement(statement)) continue;
|
|
26258
|
+
for (const declaration of statement.declarationList.declarations) if (ts.isIdentifier(declaration.name) && declaration.initializer !== void 0) initializers.set(declaration.name.text, declaration.initializer);
|
|
26259
|
+
}
|
|
26260
|
+
return initializers;
|
|
26261
|
+
}
|
|
26262
|
+
function unwrapConfigArray(expression, initializers) {
|
|
26263
|
+
const visited = /* @__PURE__ */ new Set();
|
|
26264
|
+
let current = expression;
|
|
26265
|
+
while (!ts.isArrayLiteralExpression(current)) {
|
|
26266
|
+
if (ts.isParenthesizedExpression(current) || ts.isAsExpression(current) || ts.isSatisfiesExpression(current) || ts.isTypeAssertionExpression(current)) {
|
|
26267
|
+
current = current.expression;
|
|
26268
|
+
continue;
|
|
26269
|
+
}
|
|
26270
|
+
if (ts.isCallExpression(current)) {
|
|
26271
|
+
const [firstArgument] = current.arguments;
|
|
26272
|
+
if (firstArgument === void 0) return void 0;
|
|
26273
|
+
current = firstArgument;
|
|
26274
|
+
continue;
|
|
26275
|
+
}
|
|
26276
|
+
if (!ts.isIdentifier(current) || visited.has(current.text)) return void 0;
|
|
26277
|
+
visited.add(current.text);
|
|
26278
|
+
const initializer = initializers.get(current.text);
|
|
26279
|
+
if (initializer === void 0) return void 0;
|
|
26280
|
+
current = initializer;
|
|
26281
|
+
}
|
|
26282
|
+
return current;
|
|
26283
|
+
}
|
|
26284
|
+
function findConfigArray(sourceFile) {
|
|
26285
|
+
const initializers = variableInitializers(sourceFile);
|
|
26286
|
+
for (const statement of sourceFile.statements) {
|
|
26287
|
+
if (!ts.isExportAssignment(statement) || statement.isExportEquals) continue;
|
|
26288
|
+
return unwrapConfigArray(statement.expression, initializers);
|
|
26289
|
+
}
|
|
26290
|
+
}
|
|
26291
|
+
function expressionReferencesGitignore(expression, sourceFile, initializers, visited = /* @__PURE__ */ new Set()) {
|
|
26292
|
+
if (expression.getText(sourceFile).includes(".gitignore")) return true;
|
|
26293
|
+
if (!ts.isIdentifier(expression) || visited.has(expression.text)) return false;
|
|
26294
|
+
visited.add(expression.text);
|
|
26295
|
+
const initializer = initializers.get(expression.text);
|
|
26296
|
+
return initializer !== void 0 && expressionReferencesGitignore(initializer, sourceFile, initializers, visited);
|
|
26297
|
+
}
|
|
26298
|
+
function enablesGitignoreResolution(expression) {
|
|
26299
|
+
if (expression === void 0 || !ts.isObjectLiteralExpression(expression)) return false;
|
|
26300
|
+
return expression.properties.some((property) => {
|
|
26301
|
+
if (!ts.isPropertyAssignment(property)) return false;
|
|
26302
|
+
return property.name.getText().replaceAll(/["']/g, "") === "gitignoreResolution" && property.initializer.kind === ts.SyntaxKind.TrueKeyword;
|
|
26303
|
+
});
|
|
26304
|
+
}
|
|
26305
|
+
function isRequiredGitignoreCall(node, includeReference, sourceFile, initializers) {
|
|
26306
|
+
if (!ts.isCallExpression(node) || node.expression.getText(sourceFile) !== includeReference) return false;
|
|
26307
|
+
const [ignorePath, options] = node.arguments;
|
|
26308
|
+
return ignorePath !== void 0 && expressionReferencesGitignore(ignorePath, sourceFile, initializers) && enablesGitignoreResolution(options);
|
|
26309
|
+
}
|
|
26310
|
+
function hasGitignoreConfig(source) {
|
|
26311
|
+
const sourceFile = parseConfig(source);
|
|
26312
|
+
const includeReference = importedReference(sourceFile, "eslint/config", "includeIgnoreFile");
|
|
26313
|
+
const configArray = findConfigArray(sourceFile);
|
|
26314
|
+
if (includeReference === void 0 || configArray === void 0) return false;
|
|
26315
|
+
const resolvedIncludeReference = includeReference;
|
|
26316
|
+
const initializers = variableInitializers(sourceFile);
|
|
26317
|
+
let found = false;
|
|
26318
|
+
function visit(node) {
|
|
26319
|
+
if (found) return;
|
|
26320
|
+
if (isRequiredGitignoreCall(node, resolvedIncludeReference, sourceFile, initializers)) {
|
|
26321
|
+
found = true;
|
|
26322
|
+
return;
|
|
26323
|
+
}
|
|
26324
|
+
ts.forEachChild(node, visit);
|
|
26325
|
+
}
|
|
26326
|
+
visit(configArray);
|
|
26327
|
+
return found;
|
|
26328
|
+
}
|
|
26329
|
+
function updateNamedImport(declaration, importedName, sourceFile) {
|
|
26330
|
+
const clause = declaration.importClause;
|
|
26331
|
+
const bindings = clause?.namedBindings;
|
|
26332
|
+
const elements = bindings !== void 0 && ts.isNamedImports(bindings) ? [...bindings.elements] : [];
|
|
26333
|
+
const namedImports = ts.factory.createNamedImports([...elements, ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier(importedName))]);
|
|
26334
|
+
const updatedClause = ts.factory.updateImportClause(clause ?? ts.factory.createImportClause(false, void 0, namedImports), false, clause?.name, namedImports);
|
|
26335
|
+
const updated = ts.factory.updateImportDeclaration(declaration, declaration.modifiers, updatedClause, declaration.moduleSpecifier, declaration.attributes);
|
|
26336
|
+
const printer = ts.createPrinter({
|
|
26337
|
+
newLine: ts.NewLineKind.LineFeed,
|
|
26338
|
+
omitTrailingSemicolon: true
|
|
26339
|
+
});
|
|
26340
|
+
return {
|
|
26341
|
+
end: declaration.getEnd(),
|
|
26342
|
+
start: declaration.getStart(sourceFile),
|
|
26343
|
+
text: printer.printNode(ts.EmitHint.Unspecified, updated, sourceFile)
|
|
26344
|
+
};
|
|
26345
|
+
}
|
|
26346
|
+
function resolveImportReference(sourceFile, moduleSpecifier, importedName, newImports) {
|
|
26347
|
+
const existingReference = importedReference(sourceFile, moduleSpecifier, importedName);
|
|
26348
|
+
if (existingReference !== void 0) return { reference: existingReference };
|
|
26349
|
+
for (const declaration of importDeclarations(sourceFile)) {
|
|
26350
|
+
if (moduleName(declaration) !== moduleSpecifier || declaration.importClause?.isTypeOnly === true) continue;
|
|
26351
|
+
const bindings = declaration.importClause?.namedBindings;
|
|
26352
|
+
if (bindings !== void 0 && ts.isNamespaceImport(bindings)) return { reference: `${bindings.name.text}.${importedName}` };
|
|
26353
|
+
return {
|
|
26354
|
+
edit: updateNamedImport(declaration, importedName, sourceFile),
|
|
26355
|
+
reference: importedName
|
|
26356
|
+
};
|
|
26357
|
+
}
|
|
26358
|
+
newImports.push(`import { ${importedName} } from '${moduleSpecifier}'`);
|
|
26359
|
+
return { reference: importedName };
|
|
26360
|
+
}
|
|
26361
|
+
function newImportsEdit(sourceFile, imports) {
|
|
26362
|
+
if (imports.length === 0) return void 0;
|
|
26363
|
+
const lastImport = importDeclarations(sourceFile).at(-1);
|
|
26364
|
+
if (lastImport === void 0) return {
|
|
26365
|
+
end: 0,
|
|
26366
|
+
start: 0,
|
|
26367
|
+
text: `${imports.join("\n")}\n\n`
|
|
26368
|
+
};
|
|
26369
|
+
return {
|
|
26370
|
+
end: lastImport.getEnd(),
|
|
26371
|
+
start: lastImport.getEnd(),
|
|
26372
|
+
text: `\n${imports.join("\n")}`
|
|
26373
|
+
};
|
|
26374
|
+
}
|
|
26375
|
+
function lineIndent(source, position) {
|
|
26376
|
+
const lineStart = source.lastIndexOf("\n", position - 1) + 1;
|
|
26377
|
+
return /^\s*/.exec(source.slice(lineStart, position))?.[0] ?? "";
|
|
26378
|
+
}
|
|
26379
|
+
function gitignoreConfigEntryLines(indent, includeReference = "includeIgnoreFile", fileUrlReference = "fileURLToPath") {
|
|
26380
|
+
return [
|
|
26381
|
+
`${indent}${includeReference}(${fileUrlReference}(new URL('.gitignore', import.meta.url)), {`,
|
|
26382
|
+
`${indent} gitignoreResolution: true,`,
|
|
26383
|
+
`${indent} name: '${GITIGNORE_NAME}',`,
|
|
26384
|
+
`${indent}}),`
|
|
26385
|
+
];
|
|
26386
|
+
}
|
|
26387
|
+
function configArrayEdit(source, sourceFile, array, includeReference, fileUrlReference) {
|
|
26388
|
+
const start = array.getStart(sourceFile) + 1;
|
|
26389
|
+
const indent = `${lineIndent(source, array.getStart(sourceFile))} `;
|
|
26390
|
+
return {
|
|
26391
|
+
end: start,
|
|
26392
|
+
start,
|
|
26393
|
+
text: `\n${gitignoreConfigEntryLines(indent, includeReference, fileUrlReference).join("\n")}${source[start] === "\n" || source[start] === "\r" ? "" : `\n${indent}`}`
|
|
26394
|
+
};
|
|
26395
|
+
}
|
|
26396
|
+
function applyEdits(source, edits) {
|
|
26397
|
+
let updated = source;
|
|
26398
|
+
const descendingEdits = [...edits].toSorted((left, right) => right.start - left.start);
|
|
26399
|
+
for (const edit of descendingEdits) updated = `${updated.slice(0, edit.start)}${edit.text}${updated.slice(edit.end)}`;
|
|
26400
|
+
return updated;
|
|
26401
|
+
}
|
|
26402
|
+
function addGitignoreConfig(source) {
|
|
26403
|
+
if (hasGitignoreConfig(source)) return source;
|
|
26404
|
+
const sourceFile = parseConfig(source);
|
|
26405
|
+
const configArray = findConfigArray(sourceFile);
|
|
26406
|
+
if (configArray === void 0) return void 0;
|
|
26407
|
+
const edits = [];
|
|
26408
|
+
const newImports = [];
|
|
26409
|
+
const includeImport = resolveImportReference(sourceFile, "eslint/config", "includeIgnoreFile", newImports);
|
|
26410
|
+
const fileUrlImport = resolveImportReference(sourceFile, "node:url", "fileURLToPath", newImports);
|
|
26411
|
+
if (includeImport.edit !== void 0) edits.push(includeImport.edit);
|
|
26412
|
+
if (fileUrlImport.edit !== void 0) edits.push(fileUrlImport.edit);
|
|
26413
|
+
const importsEdit = newImportsEdit(sourceFile, newImports);
|
|
26414
|
+
if (importsEdit !== void 0) edits.push(importsEdit);
|
|
26415
|
+
edits.push(configArrayEdit(source, sourceFile, configArray, includeImport.reference, fileUrlImport.reference));
|
|
26416
|
+
return applyEdits(source, edits);
|
|
26417
|
+
}
|
|
26418
|
+
//#endregion
|
|
26234
26419
|
//#region src/actions/lint-init.ts
|
|
26235
26420
|
function askConfirmation(question) {
|
|
26236
26421
|
const rl = createInterface({
|
|
@@ -26280,16 +26465,21 @@ function getBarrelDescriptorsForRepo(isReact) {
|
|
|
26280
26465
|
function formatDisallowedArray(name, imports, message) {
|
|
26281
26466
|
return `const ${name} = [\n${imports.map((i) => ` { name: '${i}', message: "${message}" },`).join("\n")}\n]`;
|
|
26282
26467
|
}
|
|
26283
|
-
function generateEslintConfig({ barrels, isReact }) {
|
|
26468
|
+
function generateEslintConfig({ barrels, hasGitignore, isReact }) {
|
|
26284
26469
|
const configPkg = isReact ? "@ariestools/eslint-config-react-flat" : "@ariestools/eslint-config-flat";
|
|
26285
26470
|
const defaultConfigVarName = "xylabsConfig";
|
|
26286
26471
|
const recommendedCall = "recommendedConfig({ tier: 3, isTypeChecked: true })";
|
|
26287
26472
|
const lines = [];
|
|
26473
|
+
if (hasGitignore) lines.push("import { fileURLToPath } from 'node:url'", "");
|
|
26288
26474
|
if (isReact) lines.push("import {", " configReactStorybook,", " recommendedConfig,", `} from '${configPkg}'`, "");
|
|
26289
26475
|
else lines.push(`import { recommendedConfig } from '${configPkg}'`, "");
|
|
26290
|
-
lines.push("import type { Linter } from 'eslint'"
|
|
26476
|
+
lines.push("import type { Linter } from 'eslint'");
|
|
26477
|
+
if (hasGitignore) lines.push("import { includeIgnoreFile } from 'eslint/config'");
|
|
26478
|
+
lines.push("", `const ${defaultConfigVarName} = ${recommendedCall}`, "");
|
|
26291
26479
|
for (const barrel of barrels) lines.push(formatDisallowedArray(barrel.configVarName, barrel.imports, barrel.message), "");
|
|
26292
|
-
lines.push("const config: Linter.Config[] = ["
|
|
26480
|
+
lines.push("const config: Linter.Config[] = [");
|
|
26481
|
+
if (hasGitignore) lines.push(...gitignoreConfigEntryLines(" "));
|
|
26482
|
+
lines.push(" { ignores: ['.yarn/**', 'build', '**/build/**', '**/dist/**', 'dist', 'node_modules/**', '**/node_modules/**', '**/*.md', '.claude/worktrees/*'] },", ` ...${defaultConfigVarName},`);
|
|
26293
26483
|
if (isReact) lines.push(" ...configReactStorybook,");
|
|
26294
26484
|
if (barrels.length > 0) {
|
|
26295
26485
|
lines.push(" {", " rules:", " {", " 'no-restricted-imports': [", " 'warn',", " {", " paths: [");
|
|
@@ -26385,6 +26575,7 @@ async function lintInit({ isVerbose } = {}) {
|
|
|
26385
26575
|
for (const descriptor of getBarrelDescriptorsForRepo(isReact)) if (await askConfirmation(chalk.cyan(`Disallow ${descriptor.pkg} barrel imports? (y/N) `))) enabledBarrels.push(descriptor);
|
|
26386
26576
|
writeFileSync(configPath, generateEslintConfig({
|
|
26387
26577
|
barrels: resolveEnabledBarrels(cwd, enabledBarrels, isVerbose),
|
|
26578
|
+
hasGitignore: existsSync(PATH.resolve(cwd, ".gitignore")),
|
|
26388
26579
|
isReact
|
|
26389
26580
|
}), "utf8");
|
|
26390
26581
|
console.log(chalk.green("Generated eslint.config.ts"));
|
|
@@ -31478,6 +31669,7 @@ import path from 'node:path'
|
|
|
31478
31669
|
import { performance } from 'node:perf_hooks'
|
|
31479
31670
|
import readline from 'node:readline'
|
|
31480
31671
|
import { ESLint } from 'eslint'
|
|
31672
|
+
import { includeIgnoreFile } from 'eslint/config'
|
|
31481
31673
|
|
|
31482
31674
|
const marker = ${JSON.stringify(lintNextResultMarker)}
|
|
31483
31675
|
const cycleRuleFilePatterns = ${JSON.stringify([
|
|
@@ -31556,15 +31748,29 @@ function cycleOverrideBlock(options) {
|
|
|
31556
31748
|
}
|
|
31557
31749
|
}
|
|
31558
31750
|
|
|
31751
|
+
function gitignoreOverrideBlock(options) {
|
|
31752
|
+
if (options.gitignorePath === undefined) return undefined
|
|
31753
|
+
return includeIgnoreFile(options.gitignorePath, {
|
|
31754
|
+
gitignoreResolution: true,
|
|
31755
|
+
name: 'XY repository .gitignore',
|
|
31756
|
+
})
|
|
31757
|
+
}
|
|
31758
|
+
|
|
31759
|
+
function additionalOverrideBlocks(options) {
|
|
31760
|
+
return [gitignoreOverrideBlock(options), cycleOverrideBlock(options)].filter(Boolean)
|
|
31761
|
+
}
|
|
31762
|
+
|
|
31559
31763
|
async function createLintEngine(cwd, options) {
|
|
31560
31764
|
// analyzeTier (legacy) or configOverride force a recommendedConfig preset
|
|
31561
31765
|
const overrideSpec = options.configOverride ?? options.analyzeTier
|
|
31562
31766
|
if (overrideSpec) {
|
|
31563
|
-
|
|
31767
|
+
const gitignoreBlock = gitignoreOverrideBlock(options)
|
|
31564
31768
|
const cycleBlock = cycleOverrideBlock(options)
|
|
31565
|
-
|
|
31566
|
-
|
|
31567
|
-
|
|
31769
|
+
const overrideConfig = [
|
|
31770
|
+
...(gitignoreBlock === undefined ? [] : [gitignoreBlock]),
|
|
31771
|
+
...await resolveAnalyzeOverrideConfig(cwd, overrideSpec),
|
|
31772
|
+
...(cycleBlock === undefined ? [] : [cycleBlock]),
|
|
31773
|
+
]
|
|
31568
31774
|
return new ESLint({
|
|
31569
31775
|
cache: options.cache,
|
|
31570
31776
|
cacheLocation: options.cacheLocation ?? path.join(cwd, '.eslintcache'),
|
|
@@ -31586,7 +31792,7 @@ async function createLintEngine(cwd, options) {
|
|
|
31586
31792
|
cwd,
|
|
31587
31793
|
fix: options.fix,
|
|
31588
31794
|
ignorePatterns: options.ignorePatterns ?? defaultIgnorePatterns,
|
|
31589
|
-
overrideConfig:
|
|
31795
|
+
overrideConfig: additionalOverrideBlocks(options),
|
|
31590
31796
|
warnIgnored: false,
|
|
31591
31797
|
})
|
|
31592
31798
|
}
|
|
@@ -32007,7 +32213,7 @@ function emptyPackageResult(pkg) {
|
|
|
32007
32213
|
* Classify packages, skip empty/meta as configured, then lint the rest via
|
|
32008
32214
|
* the persistent ESLint worker pool.
|
|
32009
32215
|
*/
|
|
32010
|
-
async function runLintNextPackages({ analyze, analyzeTier, cache, concurrency, cycleDepth, fix, meta, onPackageResult, profile, rootDir, skipEmpty, tierContext, typeChecked, verbose, workspaces }) {
|
|
32216
|
+
async function runLintNextPackages({ analyze, analyzeTier, cache, concurrency, cycleDepth, fix, gitignore, meta, onPackageResult, profile, rootDir, skipEmpty, tierContext, typeChecked, verbose, workspaces }) {
|
|
32011
32217
|
const forceFull = workspaces.length === 1;
|
|
32012
32218
|
const classified = workspaces.map((ws) => {
|
|
32013
32219
|
return {
|
|
@@ -32029,6 +32235,8 @@ async function runLintNextPackages({ analyze, analyzeTier, cache, concurrency, c
|
|
|
32029
32235
|
}
|
|
32030
32236
|
const poolSize = Math.min(Math.max(1, concurrency), toLint.length);
|
|
32031
32237
|
const pool = new LintWorkerPool(rootDir, poolSize);
|
|
32238
|
+
const repositoryGitignorePath = PATH.resolve(rootDir, ".gitignore");
|
|
32239
|
+
const gitignorePath = gitignore && existsSync(repositoryGitignorePath) ? repositoryGitignorePath : void 0;
|
|
32032
32240
|
if (profile) {
|
|
32033
32241
|
console.log(chalk.gray(` ESLint workers: ${poolSize} (persistent pool)`));
|
|
32034
32242
|
if (typeChecked !== "auto") console.log(chalk.gray(` type-checked: ${typeChecked ? "forced on" : "forced off"}`));
|
|
@@ -32056,6 +32264,7 @@ async function runLintNextPackages({ analyze, analyzeTier, cache, concurrency, c
|
|
|
32056
32264
|
configOverride: analyze ? void 0 : configOverride,
|
|
32057
32265
|
cycleDepth,
|
|
32058
32266
|
fix,
|
|
32267
|
+
gitignorePath,
|
|
32059
32268
|
profile,
|
|
32060
32269
|
verbose
|
|
32061
32270
|
}
|
|
@@ -32526,13 +32735,14 @@ function resolveTierForLint(analyze, rootDir) {
|
|
|
32526
32735
|
tierContext: analyzeContext.kind === "ready" ? analyzeContext.tierContext : detectedContext.hasXylabsConfig ? detectedContext : void 0
|
|
32527
32736
|
};
|
|
32528
32737
|
}
|
|
32529
|
-
function logLintProfileHeader(cache, typeChecked, detectedContext, meta, skipEmpty) {
|
|
32738
|
+
function logLintProfileHeader(cache, gitignore, typeChecked, detectedContext, meta, skipEmpty) {
|
|
32530
32739
|
console.log(chalk.gray(` ESLint cache: ${cache ? "on" : "off"}`));
|
|
32740
|
+
console.log(chalk.gray(` .gitignore: ${gitignore ? "on" : "off"}`));
|
|
32531
32741
|
const typeCheckedLabel = typeChecked === "auto" ? `auto (project ${detectedContext.isTypeChecked ? "on" : "off"})` : typeChecked ? "forced on" : "forced off";
|
|
32532
32742
|
console.log(chalk.gray(` type-checked: ${typeCheckedLabel}`));
|
|
32533
32743
|
console.log(chalk.gray(` meta packages: ${meta} · skip empty: ${skipEmpty ? "on" : "off"}`));
|
|
32534
32744
|
}
|
|
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 }) {
|
|
32745
|
+
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
32746
|
const rootDir = INIT_CWD();
|
|
32537
32747
|
const { analyzeContext, detectedContext, tierContext } = resolveTierForLint(analyze, rootDir);
|
|
32538
32748
|
if (analyzeContext.kind === "invalid") return resultFromExitCode(1);
|
|
@@ -32543,7 +32753,7 @@ async function lintNext({ analyze = false, cache = true, cycleDepth, fix = false
|
|
|
32543
32753
|
const analyzeStarted = Date.now();
|
|
32544
32754
|
const label = getLintLabel(analyze, fix, cycleDepth);
|
|
32545
32755
|
if (analyze && tierContext !== void 0) printAnalyzeRunHeader(workspaces);
|
|
32546
|
-
if (profile) logLintProfileHeader(cache, typeChecked, detectedContext, meta, skipEmpty);
|
|
32756
|
+
if (profile) logLintProfileHeader(cache, gitignore, typeChecked, detectedContext, meta, skipEmpty);
|
|
32547
32757
|
return finishLintNext({
|
|
32548
32758
|
analyze,
|
|
32549
32759
|
analyzeStarted,
|
|
@@ -32556,6 +32766,7 @@ async function lintNext({ analyze = false, cache = true, cycleDepth, fix = false
|
|
|
32556
32766
|
concurrency: jobs,
|
|
32557
32767
|
cycleDepth,
|
|
32558
32768
|
fix,
|
|
32769
|
+
gitignore,
|
|
32559
32770
|
label,
|
|
32560
32771
|
meta,
|
|
32561
32772
|
onPackageResult: (index, total, result) => {
|
|
@@ -32587,9 +32798,11 @@ function shouldUseIncremental$2(incremental) {
|
|
|
32587
32798
|
function shouldUseIncrementalLint({ analyze, fix, incremental, pkg }) {
|
|
32588
32799
|
return pkg === void 0 && fix !== true && analyze !== true && shouldUseIncremental$2(incremental);
|
|
32589
32800
|
}
|
|
32590
|
-
function lintOptionsHash({ cycleDepth }) {
|
|
32801
|
+
function lintOptionsHash({ cycleDepth, gitignore }) {
|
|
32802
|
+
const gitignorePath = PATH.resolve(INIT_CWD(), ".gitignore");
|
|
32591
32803
|
return {
|
|
32592
32804
|
cycleDepth,
|
|
32805
|
+
gitignore: gitignore === false ? false : existsSync(gitignorePath) ? readFileSync(gitignorePath, "utf8") : null,
|
|
32593
32806
|
strict: isStrictMode()
|
|
32594
32807
|
};
|
|
32595
32808
|
}
|
|
@@ -32597,13 +32810,14 @@ const lintPackage = ({ pkg, fix, verbose }) => {
|
|
|
32597
32810
|
const pm = getPackageManager();
|
|
32598
32811
|
return runSteps(`${fix ?? false ? "Fix" : "Lint"} [${pkg}]`, [pm.runInWorkspace(pkg, fix ?? false ? "package-fix" : verbose ?? false ? "package-lint-verbose" : "package-lint")]);
|
|
32599
32812
|
};
|
|
32600
|
-
async function lintIncremental({ cache, cycleDepth, fix, jobs, meta, profile, skipEmpty, typeChecked, verbose, workspaces: targetWorkspaces }) {
|
|
32813
|
+
async function lintIncremental({ cache, cycleDepth, fix, gitignore, jobs, meta, profile, skipEmpty, typeChecked, verbose, workspaces: targetWorkspaces }) {
|
|
32601
32814
|
const pm = getPackageManager();
|
|
32602
32815
|
const allWorkspaces = targetWorkspaces ?? pm.listWorkspaces();
|
|
32603
32816
|
if (allWorkspaces.length === 0) return await lintNext({
|
|
32604
32817
|
cache,
|
|
32605
32818
|
cycleDepth,
|
|
32606
32819
|
fix,
|
|
32820
|
+
gitignore,
|
|
32607
32821
|
jobs,
|
|
32608
32822
|
meta,
|
|
32609
32823
|
profile,
|
|
@@ -32613,7 +32827,10 @@ async function lintIncremental({ cache, cycleDepth, fix, jobs, meta, profile, sk
|
|
|
32613
32827
|
});
|
|
32614
32828
|
const plan = createIncrementalPlan({
|
|
32615
32829
|
action: "lint",
|
|
32616
|
-
options: lintOptionsHash({
|
|
32830
|
+
options: lintOptionsHash({
|
|
32831
|
+
cycleDepth,
|
|
32832
|
+
gitignore
|
|
32833
|
+
}),
|
|
32617
32834
|
pm,
|
|
32618
32835
|
isVerbose: verbose,
|
|
32619
32836
|
workspaces: allWorkspaces
|
|
@@ -32623,7 +32840,10 @@ async function lintIncremental({ cache, cycleDepth, fix, jobs, meta, profile, sk
|
|
|
32623
32840
|
console.log(chalk.gray(" No changed packages to lint."));
|
|
32624
32841
|
writeIncrementalSnapshot({
|
|
32625
32842
|
action: "lint",
|
|
32626
|
-
options: lintOptionsHash({
|
|
32843
|
+
options: lintOptionsHash({
|
|
32844
|
+
cycleDepth,
|
|
32845
|
+
gitignore
|
|
32846
|
+
}),
|
|
32627
32847
|
pm,
|
|
32628
32848
|
workspaces: allWorkspaces
|
|
32629
32849
|
});
|
|
@@ -32633,6 +32853,7 @@ async function lintIncremental({ cache, cycleDepth, fix, jobs, meta, profile, sk
|
|
|
32633
32853
|
cache,
|
|
32634
32854
|
cycleDepth,
|
|
32635
32855
|
fix,
|
|
32856
|
+
gitignore,
|
|
32636
32857
|
jobs,
|
|
32637
32858
|
meta,
|
|
32638
32859
|
profile,
|
|
@@ -32643,13 +32864,16 @@ async function lintIncremental({ cache, cycleDepth, fix, jobs, meta, profile, sk
|
|
|
32643
32864
|
});
|
|
32644
32865
|
if (isCleanResult(result)) writeIncrementalSnapshot({
|
|
32645
32866
|
action: "lint",
|
|
32646
|
-
options: lintOptionsHash({
|
|
32867
|
+
options: lintOptionsHash({
|
|
32868
|
+
cycleDepth,
|
|
32869
|
+
gitignore
|
|
32870
|
+
}),
|
|
32647
32871
|
pm,
|
|
32648
32872
|
workspaces: allWorkspaces
|
|
32649
32873
|
});
|
|
32650
32874
|
return result;
|
|
32651
32875
|
}
|
|
32652
|
-
const lint = ({ analyze, cache, cycleDepth, fix, incremental, jobs, meta, prev, pkg, profile, skipEmpty, typeChecked, verbose, workspaces }) => {
|
|
32876
|
+
const lint = ({ analyze, cache, cycleDepth, fix, gitignore, incremental, jobs, meta, prev, pkg, profile, skipEmpty, typeChecked, verbose, workspaces }) => {
|
|
32653
32877
|
if (analyze === true && fix === true) {
|
|
32654
32878
|
console.error("The --analyze option cannot be combined with --fix");
|
|
32655
32879
|
return 1;
|
|
@@ -32664,6 +32888,7 @@ const lint = ({ analyze, cache, cycleDepth, fix, incremental, jobs, meta, prev,
|
|
|
32664
32888
|
cache,
|
|
32665
32889
|
cycleDepth,
|
|
32666
32890
|
fix,
|
|
32891
|
+
gitignore,
|
|
32667
32892
|
jobs,
|
|
32668
32893
|
meta,
|
|
32669
32894
|
profile,
|
|
@@ -32676,6 +32901,7 @@ const lint = ({ analyze, cache, cycleDepth, fix, incremental, jobs, meta, prev,
|
|
|
32676
32901
|
analyze,
|
|
32677
32902
|
cache,
|
|
32678
32903
|
fix,
|
|
32904
|
+
gitignore,
|
|
32679
32905
|
jobs,
|
|
32680
32906
|
meta,
|
|
32681
32907
|
pkg,
|
|
@@ -39938,7 +40164,15 @@ function fixRedundantRules(eslintConfigPath, redundant) {
|
|
|
39938
40164
|
}
|
|
39939
40165
|
}
|
|
39940
40166
|
function formatConfigFile(eslintConfigPath) {
|
|
39941
|
-
spawnSync("eslint", ["--
|
|
40167
|
+
spawnSync("eslint", ["--fix", eslintConfigPath], { stdio: "inherit" });
|
|
40168
|
+
}
|
|
40169
|
+
function fixGitignoreConfig(eslintConfigPath) {
|
|
40170
|
+
const source = readFileSync(eslintConfigPath, "utf8");
|
|
40171
|
+
const updated = addGitignoreConfig(source);
|
|
40172
|
+
if (updated === void 0 || updated === source) return false;
|
|
40173
|
+
writeFileSync(eslintConfigPath, updated, "utf8");
|
|
40174
|
+
console.log(chalk.green("Fixed: added repository .gitignore to ESLint config"));
|
|
40175
|
+
return true;
|
|
39942
40176
|
}
|
|
39943
40177
|
function fixConfigMismatch(eslintConfigPath, configDir, source, sharedPkg, expectedPkg) {
|
|
39944
40178
|
writeFileSync(eslintConfigPath, source.replaceAll(sharedPkg, () => expectedPkg), "utf8");
|
|
@@ -40002,6 +40236,19 @@ const LINTLINT_RULES = [
|
|
|
40002
40236
|
fixable: true,
|
|
40003
40237
|
id: "lintlint.config-package"
|
|
40004
40238
|
},
|
|
40239
|
+
{
|
|
40240
|
+
check: ({ eslintConfigPath, hasGitignoreFile, source }, { fix }) => {
|
|
40241
|
+
if (!hasGitignoreFile || hasGitignoreConfig(source)) return {};
|
|
40242
|
+
const message = "ESLint config does not include the repository .gitignore with Git-relative pattern resolution";
|
|
40243
|
+
if (!fix) return { diagnostics: lintlintDiagnostics("lintlint.gitignore", [message]) };
|
|
40244
|
+
if (fixGitignoreConfig(eslintConfigPath)) return { fixedCount: 1 };
|
|
40245
|
+
return { diagnostics: lintlintDiagnostics("lintlint.gitignore", [`${message}; automatic fix could not find the exported flat-config array`]) };
|
|
40246
|
+
},
|
|
40247
|
+
defaultLevel: "warn",
|
|
40248
|
+
description: "ESLint config includes the repository .gitignore for CLI and editor parity",
|
|
40249
|
+
fixable: true,
|
|
40250
|
+
id: "lintlint.gitignore"
|
|
40251
|
+
},
|
|
40005
40252
|
{
|
|
40006
40253
|
check: ({ eslintConfigPath, results }, { fix }) => {
|
|
40007
40254
|
if (results.redundant.length === 0) return {};
|
|
@@ -40037,6 +40284,7 @@ async function runLintlintChecks(eslintConfigPath, configDir, source, sharedPkg,
|
|
|
40037
40284
|
context: {
|
|
40038
40285
|
configDir,
|
|
40039
40286
|
eslintConfigPath,
|
|
40287
|
+
hasGitignoreFile: existsSync(PATH.resolve(configDir, ".gitignore")),
|
|
40040
40288
|
isVerbose,
|
|
40041
40289
|
mismatch,
|
|
40042
40290
|
results,
|
|
@@ -40049,7 +40297,7 @@ async function runLintlintChecks(eslintConfigPath, configDir, source, sharedPkg,
|
|
|
40049
40297
|
strict: isStrictMode()
|
|
40050
40298
|
});
|
|
40051
40299
|
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("
|
|
40300
|
+
if (result.envelope.data.diagnostics.length === 0 && result.envelope.data.fixedCount === 0) console.log(chalk.green("ESLint config checks passed"));
|
|
40053
40301
|
return result;
|
|
40054
40302
|
}
|
|
40055
40303
|
async function lintlint({ shouldFix, isVerbose } = {}) {
|
|
@@ -42263,13 +42511,14 @@ const relintPackage = ({ pkg, fix, verbose }) => {
|
|
|
42263
42511
|
const pm = getPackageManager();
|
|
42264
42512
|
return runSteps(`${fix ?? false ? "Fix" : "Lint"} [${pkg}]`, [pm.runInWorkspace(pkg, fix ?? false ? "package-fix" : verbose ?? false ? "package-lint-verbose" : "package-lint")]);
|
|
42265
42513
|
};
|
|
42266
|
-
const relint = ({ fix, jobs, pkg, prev, verbose }) => {
|
|
42514
|
+
const relint = ({ fix, gitignore, jobs, pkg, prev, verbose }) => {
|
|
42267
42515
|
if (!(prev ?? false)) {
|
|
42268
42516
|
cleanLintCaches(pkg);
|
|
42269
42517
|
clearIncrementalSnapshot("lint");
|
|
42270
42518
|
return lint({
|
|
42271
42519
|
cache: false,
|
|
42272
42520
|
fix,
|
|
42521
|
+
gitignore,
|
|
42273
42522
|
incremental: true,
|
|
42274
42523
|
jobs,
|
|
42275
42524
|
pkg,
|
|
@@ -51482,7 +51731,7 @@ const fixCommand = {
|
|
|
51482
51731
|
function lintLintBuilder(yargs) {
|
|
51483
51732
|
return yargs.option("fix", {
|
|
51484
51733
|
default: false,
|
|
51485
|
-
description: "
|
|
51734
|
+
description: "Fix supported ESLint config issues",
|
|
51486
51735
|
type: "boolean"
|
|
51487
51736
|
}).option("rules", {
|
|
51488
51737
|
default: false,
|
|
@@ -51504,7 +51753,7 @@ async function handleLintLintCommand(argv) {
|
|
|
51504
51753
|
const lintLintSubcommand = {
|
|
51505
51754
|
builder: lintLintBuilder,
|
|
51506
51755
|
command: "lint",
|
|
51507
|
-
describe: "Check
|
|
51756
|
+
describe: "Check the local ESLint config against toolchain conventions",
|
|
51508
51757
|
handler: handleLintLintCommand
|
|
51509
51758
|
};
|
|
51510
51759
|
const lintlintCommand = {
|
|
@@ -51575,6 +51824,10 @@ const runCommand = {
|
|
|
51575
51824
|
default: false,
|
|
51576
51825
|
description: "Clear lint caches and run ESLint from a fresh snapshot",
|
|
51577
51826
|
type: "boolean"
|
|
51827
|
+
}).option("gitignore", {
|
|
51828
|
+
default: true,
|
|
51829
|
+
description: "Ignore files matched by the repository root .gitignore (disable with --no-gitignore)",
|
|
51830
|
+
type: "boolean"
|
|
51578
51831
|
}).option("next", {
|
|
51579
51832
|
default: false,
|
|
51580
51833
|
description: "Deprecated: per-package lint is the default",
|
|
@@ -51617,6 +51870,7 @@ const runCommand = {
|
|
|
51617
51870
|
}
|
|
51618
51871
|
if (Boolean(argv.fresh)) {
|
|
51619
51872
|
await withEnvelope("lint", () => relint({
|
|
51873
|
+
gitignore: argv.gitignore,
|
|
51620
51874
|
jobs: argv.jobs,
|
|
51621
51875
|
pkg: argv.package,
|
|
51622
51876
|
prev: argv.prev,
|
|
@@ -51629,6 +51883,7 @@ const runCommand = {
|
|
|
51629
51883
|
analyze: argv.analyze,
|
|
51630
51884
|
cache: argv.cache,
|
|
51631
51885
|
fix: argv.fix,
|
|
51886
|
+
gitignore: argv.gitignore,
|
|
51632
51887
|
incremental: argv.incremental !== false,
|
|
51633
51888
|
jobs: argv.jobs,
|
|
51634
51889
|
meta: argv.meta,
|