feat: surface core executionErrors and exit(1) (#96) - #101
Merged
Conversation
Adapt @lint-md/core 2.1.5 (core #185), which returns rule execution errors as a structured list (RuleExecutionError[]) instead of throwing or logging implicitly. The CLI previously dropped them, so a crashing rule produced a silent exit(0) and let CI pass. - types.ts: BatchLintItem.executionErrors?: RuleExecutionError[] - lint-worker.ts: pass result.executionErrors through to the caller - batch-lint.ts: keepLintItem now also retains items that carry executionErrors, so the warning + exit(1) have a target - report-execution-errors.ts (new): getExecutionErrorWarnings() emits one stderr line per error (not deduped across rounds/phases) and hasExecutionErrors() for the exit gate. Path / ruleName / nodeType / message are all sanitized. nodeType is omitted when absent. - lint-md.ts: surface executionErrors on every path (stdin lint/fix, file lint/fix) via the dedicated stderr channel, after the report / fixes are written. Exit 1 is taken regardless of --suppress-warnings, since a rule failure is a hard error, not a document-level lint finding. Built on the #98 { allResults, actionableResults } result shape; the helper mirrors report-incomplete-fixes.ts. Tests: lint-worker mock passthrough, keepLintItem retention, and report-execution-errors behaviour (multi-error, missing nodeType, no dedupe, sanitization).
…truncated pipe output P1: the four execution-error exit points previously called process.exit(1) right after writing stdout (stdin --fix) / stderr diagnostics. On POSIX pipes, process.exit() can terminate before stdout/stderr flush, truncating the fixed markdown in and dropping the error diagnostics. Switch to process.exitCode = 1 so the process exits naturally and all buffered I/O completes (Node docs: set process.exitCode rather than calling process.exit()). P2: extract the shared exit-decision into emitExecutionErrorsAndSetExitCode() (diagnostics -> stderr, sets process.exitCode = 1, returns whether errors existed) and route all four entry points (stdin lint/fix, file lint/fix) through it. Add direct unit tests for the contract: writes diagnostics, sets exitCode = 1, no-op when empty, idempotent at 1. The helper keeps the --suppress-warnings bypass and per-round/phase, no-dedupe, sanitized output from reportExecutionErrors(). Verified: npm run build / npm test (152 pass, +6) / npm run lint all green.
…d early-return on lint failure Store emitExecutionErrorsAndSetExitCode()'s return value as hasRuleFailures and reuse it in the existing exit decision, instead of re-scanning items with hasExecutionErrors() and re-assigning process.exitCode. Add an early return once the exit code is set so stdin lint and file lint no longer emit the trailing 'Done in ...' timing line after a failure, matching the previous process.exit(1) behaviour.
…p trailing Done line Save emitExecutionErrorsAndSetExitCode()'s return value and return after the dev metrics block when a rule failure is present, so file --fix no longer prints the trailing 'Done in …' timing line on failure — matching the previous process.exit(1) behaviour. Writes, stderr diagnostics, exit code and IO flushing are unaffected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
适配 core #185(已随 @lint-md/core 2.1.5 发布)
core 2.1.5 把规则执行失败从"隐式 console.error / 抛错"改为结构化返回
LintMdResult.executionErrors: RuleExecutionError[]。CLI 之前全链路漏掉它,导致有规则执行错误时仍 exit(0)、CI 静默通过。改动
src/types.tsBatchLintItem.executionErrors?: RuleExecutionError[]src/utils/lint-worker.tsexecutionErrors: result.executionErrorssrc/utils/batch-lint.tskeepLintItem加 `src/utils/report-execution-errors.tsgetExecutionErrorWarnings()/hasExecutionErrors()src/lint-md.tsexit(1)判定关键决策(与 issue 评审一致)
--suppress-warnings抑制:rule 执行失败是硬错误,不是文档级 lint 警告,CLI 必须 stderr + exit(1)。getReportData()的errorCount/ 表格,保持"X problems"语义不变。--fix在完成safeWriteFile后输出 errors 再 exit(1):保留其他正常规则产生的修复,同时让 CI 明确失败。{ allResults, actionableResults }结构:helper 入参BatchLintItem[],调用方按路径传actionableResults/ 临时 item;与report-incomplete-fixes.ts共存、不互相调用。round;严格 1:1 输出,丢"同一规则不同轮失败"的核心诊断。文案
sanitizeTerminalText()验证
npm run build✅npm test:17 套件 / 146 用例全过(较 feat: surface fix convergence warnings (#98) #100 基线净增 12 个)npm run lint(tsc --noEmit + prettier --check)✅report-execution-errors.ts覆盖率 100%BatchLintItem/ mocklintMarkdown单测文件
src/utils/report-execution-errors.ts、__tests__/lint-worker.spec.ts、__tests__/report-execution-errors.spec.tssrc/types.ts、src/utils/lint-worker.ts、src/utils/batch-lint.ts、src/lint-md.ts、__tests__/keep-lint-item.spec.tsCloses #96