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
33 changes: 32 additions & 1 deletion __tests__/batch-lint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import { availableParallelism, tmpdir } from 'os';
import * as path from 'path';
import { Piscina } from 'piscina';
import type { LintMdRulesConfig } from '@lint-md/core';
import { STAT_CONCURRENCY_LIMIT, batchLint, getMaxFileSize, resolveAdaptiveConcurrency, runTasksWithLimit } from '../src/utils/batch-lint';
import { STAT_CONCURRENCY_LIMIT, batchLint, getMaxFileSize, keepLintItem, resolveAdaptiveConcurrency, runTasksWithLimit } from '../src/utils/batch-lint';
import type { BatchLintItem } from '../src/types';

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

const RULES_NO_EMPTY_LIST: LintMdRulesConfig = {
'no-empty-list': 2,
Expand Down Expand Up @@ -178,6 +185,30 @@ describe('batchLint', () => {
});
});

describe('keepLintItem', () => {
test('keeps items with a non-empty lint report', () => {
expect(keepLintItem(makeItem({ lintResult: [{ message: 'x', name: 'y', content: 'z', severity: 2, loc: { start: { line: 1, column: 1 }, end: { line: 1, column: 1 } } }] }))).toBe(true);
});

test('drops items with empty lint report and null fixedResult', () => {
expect(keepLintItem(makeItem({ fixedResult: null }))).toBe(false);
});

test('drops items with empty lint report and empty notAppliedFixes', () => {
expect(keepLintItem(makeItem({ fixedResult: { result: 'x', notAppliedFixes: [] } }))).toBe(false);
});

test('keeps items with empty lint report but non-empty notAppliedFixes', () => {
expect(
keepLintItem(
makeItem({
fixedResult: { result: 'x', notAppliedFixes: [{ range: [0, 1], text: 'y' }] },
})
)
).toBe(true);
});
});

describe('getMaxFileSize', () => {
let tmpDir: string;

Expand Down
12 changes: 9 additions & 3 deletions src/utils/batch-lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ export const resolveAdaptiveConcurrency = async (
return Math.min(Math.max(limit, 1), mdFilePaths.length);
};

// Keep a file's result when it has lint findings, or — in fix mode — when
// core left fixes unapplied due to conflicts. notAppliedFixes can in theory
// occur without a lint report, so we must not drop it (see #86 / P1-6
// "partially-unfixed is observable", which the #89 stderr warning surfaces).
export const keepLintItem = (item: BatchLintItem): boolean =>
item.lintResult.length > 0
|| Boolean(item.fixedResult?.notAppliedFixes?.length);

export const batchLint = async (
threadsCount: number,
mdFilePaths: string[],
Expand Down Expand Up @@ -117,9 +125,7 @@ export const batchLint = async (
concurrency
);

return results.filter((item) => {
return item.lintResult.length > 0;
});
return results.filter(keepLintItem);
}
finally {
await lintWorkerPool.destroy();
Expand Down