Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions __tests__/batch-lint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ import { makeNotAppliedFix } from "./helpers/not-applied-fix";

const makeItem = (overrides: Partial<BatchLintItem> = {}): BatchLintItem => ({
path: "doc.md",
lintResult: [],
diagnostics: [],
summary: {
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
},
...overrides,
});

Expand Down Expand Up @@ -60,8 +66,8 @@ describe("batchLint", () => {
fileB,
]);
actionableResults.forEach((item) => {
expect(Array.isArray(item.lintResult)).toBe(true);
expect(item.lintResult.length).toBeGreaterThan(0);
expect(Array.isArray(item.diagnostics)).toBe(true);
expect(item.diagnostics.length).toBeGreaterThan(0);
expect(item.fixedResult == null).toBe(true);
});
});
Expand All @@ -79,7 +85,7 @@ describe("batchLint", () => {

expect(actionableResults).toHaveLength(1);
expect(actionableResults[0].path).toBe(file);
expect(actionableResults[0].lintResult[0].name).toBe("no-empty-list");
expect(actionableResults[0].diagnostics[0].ruleId).toBe("no-empty-list");
});
});

Expand Down Expand Up @@ -207,13 +213,14 @@ describe("keepLintItem", () => {
expect(
keepLintItem(
makeItem({
lintResult: [
diagnostics: [
{
message: "x",
name: "y",
content: "z",
ruleId: "y",
line: 1,
column: 1,
severity: 2,
loc: {
range: {
start: { line: 1, column: 1 },
end: { line: 1, column: 1 },
},
Expand Down
17 changes: 12 additions & 5 deletions __tests__/keep-lint-item.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ const baseItem = (
}
return {
path: "a.md",
lintResult: [],
diagnostics: [],
summary: {
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
},
fixedResult,
...rest,
};
Expand All @@ -30,15 +36,16 @@ describe("keepLintItem", () => {
expect(
keepLintItem(
baseItem({
lintResult: [
diagnostics: [
{
loc: {
range: {
start: { line: 1, column: 1 },
end: { line: 1, column: 2 },
},
message: "x",
name: "r",
content: "x",
ruleId: "r",
line: 1,
column: 1,
severity: 2 as any,
},
],
Expand Down
27 changes: 21 additions & 6 deletions __tests__/lint-worker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ describe("lintWorker executionErrors passthrough", () => {

mockedLintMarkdown.mockReturnValue({
lintResult: [],
diagnostics: [],
summary: {
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
},
fixedResult: null,
fixableErrorCount: 0,
fixableWarningCount: 0,
executionErrors,
} as any);

Expand All @@ -68,9 +73,14 @@ describe("lintWorker executionErrors passthrough", () => {

mockedLintMarkdown.mockReturnValue({
lintResult: [],
diagnostics: [],
summary: {
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
},
fixedResult: null,
fixableErrorCount: 0,
fixableWarningCount: 0,
} as any);

const result = await lintWorker({
Expand All @@ -89,9 +99,14 @@ describe("lintWorker executionErrors passthrough", () => {

mockedFixMarkdown.mockReturnValue({
lintResult: [],
diagnostics: [],
summary: {
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
},
fixedResult: { result: "甲 [链接](https://example.com) 乙\n" },
fixableErrorCount: 0,
fixableWarningCount: 0,
executionErrors: [],
} as any);

Expand Down
8 changes: 7 additions & 1 deletion __tests__/report-execution-errors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ const makeItem = (
executionErrors?: RuleExecutionError[]
): BatchLintItem => ({
path,
lintResult: [],
diagnostics: [],
summary: {
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
},
...(executionErrors ? { executionErrors } : {}),
});

Expand Down
8 changes: 7 additions & 1 deletion __tests__/report-incomplete-fixes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ const makeItem = (
}
return {
path: "docs/example.md",
lintResult: [],
diagnostics: [],
summary: {
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
},
fixedResult,
...rest,
};
Expand Down
8 changes: 7 additions & 1 deletion __tests__/report-unapplied-fixes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { makeNotAppliedFix } from "./helpers/not-applied-fix";

const makeItem = (overrides: Partial<BatchLintItem> = {}): BatchLintItem => ({
path: "doc.md",
lintResult: [],
diagnostics: [],
summary: {
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
},
...overrides,
});

Expand Down
24 changes: 21 additions & 3 deletions __tests__/run-file-lint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,13 @@ describe("runFileLint", () => {
test("reports rule failures to stderr and returns failure without timing", async () => {
const failedResult: BatchLintItem = {
path: "failed.md",
lintResult: [],
diagnostics: [],
summary: {
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
},
executionErrors: [
{
ruleName: "broken-rule",
Expand Down Expand Up @@ -247,12 +253,24 @@ describe("runFileLint", () => {
test("writes actionable fixes and reports metrics for all results", async () => {
const cleanResult: BatchLintItem = {
path: "clean.md",
lintResult: [],
diagnostics: [],
summary: {
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
},
fixedResult: { result: "clean", notAppliedFixes: [] },
};
const actionableResult: BatchLintItem = {
path: "actionable.md",
lintResult: [],
diagnostics: [],
summary: {
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
},
fixedResult: { result: "fixed", notAppliedFixes: [] },
};
const allResults = [cleanResult, actionableResult];
Expand Down
18 changes: 14 additions & 4 deletions __tests__/run-stdin-lint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,14 @@ describe("runStdinLint", () => {
test("reports rule failures to stderr and returns failure without timing", () => {
jest.spyOn(lintCore, "lintMarkdown").mockReturnValue({
lintResult: [],
diagnostics: [],
summary: {
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
},
fixedResult: null,
fixableErrorCount: 0,
fixableWarningCount: 0,
executionErrors: [
{
ruleName: "broken-rule",
Expand Down Expand Up @@ -112,9 +117,14 @@ describe("runStdinLint", () => {
test("keeps fix output pipe-safe when a rule fails", () => {
jest.spyOn(lintCore, "fixMarkdown").mockReturnValue({
lintResult: [],
diagnostics: [],
summary: {
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
},
fixedResult: null,
fixableErrorCount: 0,
fixableWarningCount: 0,
executionErrors: [
{
ruleName: "broken-rule",
Expand Down
61 changes: 41 additions & 20 deletions __tests__/summarize-lint-results.spec.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
import type { LintReportItem } from "@lint-md/core";
import type { LintDiagnostic, LintSummary } from "@lint-md/core";
import type { BatchLintItem } from "../src/types";
import { summarizeLintResults } from "../src/utils/summarize-lint-results";

const makeReportItem = (
const makeDiagnostic = (
severity: number,
overrides: Partial<LintReportItem> = {}
): LintReportItem => ({
name: "rule-x",
overrides: Partial<LintDiagnostic> = {}
): LintDiagnostic => ({
ruleId: "rule-x",
message: "some problem",
content: "x",
severity,
loc: { start: { line: 1, column: 1 }, end: { line: 1, column: 2 } },
line: 1,
column: 1,
range: { start: { line: 1, column: 1 }, end: { line: 1, column: 2 } },
...overrides,
});

const makeSummary = (overrides: Partial<LintSummary> = {}): LintSummary => ({
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
...overrides,
});

const makeItem = (overrides: Partial<BatchLintItem> = {}): BatchLintItem => ({
path: "doc.md",
lintResult: [],
diagnostics: [],
summary: makeSummary(),
...overrides,
});

describe("summarizeLintResults", () => {
test("counts errors and warnings separately", () => {
const summary = summarizeLintResults([
makeItem({
lintResult: [makeReportItem(2), makeReportItem(2), makeReportItem(1)],
diagnostics: [makeDiagnostic(2), makeDiagnostic(2), makeDiagnostic(1)],
summary: makeSummary({ errorCount: 2, warningCount: 1 }),
}),
]);

Expand All @@ -38,14 +49,22 @@ describe("summarizeLintResults", () => {
const summary = summarizeLintResults([
makeItem({
path: "a.md",
lintResult: [makeReportItem(2), makeReportItem(1)],
fixableErrorCount: 3,
diagnostics: [makeDiagnostic(2), makeDiagnostic(1)],
summary: makeSummary({
errorCount: 1,
warningCount: 1,
fixableErrorCount: 3,
}),
}),
makeItem({
path: "b.md",
lintResult: [makeReportItem(2), makeReportItem(2), makeReportItem(1)],
fixableErrorCount: 1,
fixableWarningCount: 4,
diagnostics: [makeDiagnostic(2), makeDiagnostic(2), makeDiagnostic(1)],
summary: makeSummary({
errorCount: 2,
warningCount: 1,
fixableErrorCount: 1,
fixableWarningCount: 4,
}),
}),
]);

Expand All @@ -61,16 +80,19 @@ describe("summarizeLintResults", () => {
const summary = summarizeLintResults([
makeItem({
path: "doc\u0007.md",
lintResult: [
makeReportItem(2, {
loc: {
diagnostics: [
makeDiagnostic(2, {
line: 3,
column: 5,
range: {
start: { line: 3, column: 5 },
end: { line: 3, column: 6 },
},
message: "bad\nmessage",
name: "rule\tid",
ruleId: "rule\tid",
}),
],
summary: makeSummary({ errorCount: 1 }),
}),
]);

Expand All @@ -91,8 +113,7 @@ describe("summarizeLintResults", () => {
test("drops files without lint problems", () => {
const summary = summarizeLintResults([
makeItem({
fixableErrorCount: 3,
fixableWarningCount: 4,
summary: makeSummary({ fixableErrorCount: 3, fixableWarningCount: 4 }),
}),
]);

Expand Down
Loading