Skip to content

Commit bea81c4

Browse files
committed
Update violation summary output to include severity.
1 parent 5174cac commit bea81c4

2 files changed

Lines changed: 28 additions & 25 deletions

File tree

markdownlint.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ function printResult(lintResult) {
154154
lineNumber: result.lineNumber,
155155
column: (result.errorRange && result.errorRange[0]) || 0,
156156
names: result.ruleNames.join('/'),
157-
description: result.ruleDescription + (result.errorDetail ? ' [' + result.errorDetail + ']' : '') + (result.errorContext ? ' [Context: "' + result.errorContext + '"]' : '')
157+
description: result.ruleDescription + (result.errorDetail ? ' [' + result.errorDetail + ']' : '') + (result.errorContext ? ' [Context: "' + result.errorContext + '"]' : ''),
158+
severity: result.severity
158159
};
159160
})
160161
);
@@ -169,9 +170,9 @@ function printResult(lintResult) {
169170

170171
lintResultString = results
171172
.map(result => {
172-
const {file, lineNumber, column, names, description} = result;
173+
const {file, lineNumber, column, names, description, severity} = result;
173174
const columnText = column ? `:${column}` : '';
174-
return `${file}:${lineNumber}${columnText} ${names} ${description}`;
175+
return `${file}:${lineNumber}${columnText} ${severity} ${names} ${description}`;
175176
})
176177
.join('\n');
177178
}

test/test.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const __dirname = path.dirname(__filename);
2424
const importWithTypeJson = async file => JSON.parse(await fsPromises.readFile(path.resolve(__dirname, file)));
2525

2626
const packageJson = await importWithTypeJson('../package.json');
27-
const errorPattern = /(\.md|\.markdown|\.mdf|stdin):\d+(:\d+)? MD\d{3}/gm;
27+
const errorPattern = /(\.md|\.markdown|\.mdf|stdin):\d+(:\d+)? error MD\d{3}/gm;
2828

2929
process.chdir('./test');
3030

@@ -111,7 +111,7 @@ test('linting of incorrect Markdown file fails and prints issues', async t => {
111111
t.fail();
112112
} catch (error) {
113113
t.is(error.stdout, '');
114-
const expected = ['incorrect.md:1 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## header 2"]', 'incorrect.md:1 MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## header 2"]', 'incorrect.md:2 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Above] [Context: "# header"]'].join('\n');
114+
const expected = ['incorrect.md:1 error MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## header 2"]', 'incorrect.md:1 warning MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## header 2"]', 'incorrect.md:2 error MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Above] [Context: "# header"]'].join('\n');
115115
t.is(error.stderr, expected);
116116
t.is(error.exitCode, 1);
117117
}
@@ -337,7 +337,9 @@ test('linting results are sorted by file/line/names/description', async t => {
337337
await spawn('../markdownlint.js', ['--config', 'test-config.json', 'incorrect.md']);
338338
t.fail();
339339
} catch (error) {
340-
const expected = ['incorrect.md:1 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## header 2"]', 'incorrect.md:1 MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## header 2"]', 'incorrect.md:2 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Above] [Context: "# header"]', 'incorrect.md:5:1 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]', 'incorrect.md:11:1 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]', 'incorrect.md:17:1 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]', 'incorrect.md:23:1 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]'].join('\n');
340+
const expected = ['incorrect.md:1 error MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## header 2"]', 'incorrect.md:1 error MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## header 2"]', 'incorrect.md:2 error MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Above] [Context: "# header"]', 'incorrect.md:5:1 error MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]', 'incorrect.md:11:1 error MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]', 'incorrect.md:17:1 error MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]', 'incorrect.md:23:1 error MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]'].join(
341+
'\n'
342+
);
341343
t.is(error.stdout, '');
342344
t.is(error.stderr, expected);
343345
t.is(error.exitCode, 1);
@@ -527,7 +529,7 @@ function getCwdConfigFileTest(extension) {
527529
});
528530
t.fail();
529531
} catch (error) {
530-
const expected = ["heading-dollar.md:1:10 MD026/no-trailing-punctuation Trailing punctuation in heading [Punctuation: '$']"].join('\n');
532+
const expected = ["heading-dollar.md:1:10 error MD026/no-trailing-punctuation Trailing punctuation in heading [Punctuation: '$']"].join('\n');
531533
t.is(error.stdout, '');
532534
t.is(error.stderr, expected);
533535
t.is(error.exitCode, 1);
@@ -601,7 +603,7 @@ test('Custom rule from single file loaded', async t => {
601603
await spawn('../markdownlint.js', ['--rules', 'custom-rules/files/test-rule-1.cjs', '--stdin'], {stdin});
602604
t.fail();
603605
} catch (error) {
604-
const expected = ['stdin:1 test-rule-1 Test rule broken'].join('\n');
606+
const expected = ['stdin:1 error test-rule-1 Test rule broken'].join('\n');
605607
t.is(error.stdout, '');
606608
t.is(error.stderr, expected);
607609
t.is(error.exitCode, 1);
@@ -614,7 +616,7 @@ test('Multiple custom rules from single file loaded', async t => {
614616
await spawn('../markdownlint.js', ['--rules', 'custom-rules/files/test-rule-3-4.cjs', '--stdin'], {stdin});
615617
t.fail();
616618
} catch (error) {
617-
const expected = ['stdin:1 test-rule-3 Test rule 3 broken', 'stdin:1 test-rule-4 Test rule 4 broken'].join('\n');
619+
const expected = ['stdin:1 error test-rule-3 Test rule 3 broken', 'stdin:1 error test-rule-4 Test rule 4 broken'].join('\n');
618620
t.is(error.stdout, '');
619621
t.is(error.stderr, expected);
620622
t.is(error.exitCode, 1);
@@ -627,7 +629,7 @@ test('Custom rules from directory loaded', async t => {
627629
await spawn('../markdownlint.js', ['--rules', 'custom-rules/files', '--stdin'], {stdin});
628630
t.fail();
629631
} catch (error) {
630-
const expected = ['stdin:1 test-rule-1 Test rule broken', 'stdin:1 test-rule-2 Test rule 2 broken', 'stdin:1 test-rule-3 Test rule 3 broken', 'stdin:1 test-rule-4 Test rule 4 broken'].join('\n');
632+
const expected = ['stdin:1 error test-rule-1 Test rule broken', 'stdin:1 error test-rule-2 Test rule 2 broken', 'stdin:1 error test-rule-3 Test rule 3 broken', 'stdin:1 error test-rule-4 Test rule 4 broken'].join('\n');
631633
t.is(error.stdout, '');
632634
t.is(error.stderr, expected);
633635
t.is(error.exitCode, 1);
@@ -640,7 +642,7 @@ test('Custom rules from glob loaded', async t => {
640642
await spawn('../markdownlint.js', ['--rules', 'custom-rules/files/**/*.cjs', '--stdin'], {stdin});
641643
t.fail();
642644
} catch (error) {
643-
const expected = ['stdin:1 test-rule-1 Test rule broken', 'stdin:1 test-rule-2 Test rule 2 broken', 'stdin:1 test-rule-3 Test rule 3 broken', 'stdin:1 test-rule-4 Test rule 4 broken'].join('\n');
645+
const expected = ['stdin:1 error test-rule-1 Test rule broken', 'stdin:1 error test-rule-2 Test rule 2 broken', 'stdin:1 error test-rule-3 Test rule 3 broken', 'stdin:1 error test-rule-4 Test rule 4 broken'].join('\n');
644646
t.is(error.stdout, '');
645647
t.is(error.stderr, expected);
646648
t.is(error.exitCode, 1);
@@ -653,7 +655,7 @@ test('Custom rule from node_modules package loaded', async t => {
653655
await spawn('../markdownlint.js', ['--rules', 'markdownlint-cli-local-test-rule', '--stdin'], {stdin});
654656
t.fail();
655657
} catch (error) {
656-
const expected = ['stdin:1 markdownlint-cli-local-test-rule Test rule package broken'].join('\n');
658+
const expected = ['stdin:1 error markdownlint-cli-local-test-rule Test rule package broken'].join('\n');
657659
t.is(error.stdout, '');
658660
t.is(error.stderr, expected);
659661
t.is(error.exitCode, 1);
@@ -669,7 +671,7 @@ test('Custom rule from node_modules package loaded relative to cwd', async t =>
669671
});
670672
t.fail();
671673
} catch (error) {
672-
const expected = ['stdin:1 markdownlint-cli-local-test-rule Test rule package relative to cwd broken'].join('\n');
674+
const expected = ['stdin:1 error markdownlint-cli-local-test-rule Test rule package relative to cwd broken'].join('\n');
673675
t.is(error.stdout, '');
674676
t.is(error.stderr, expected);
675677
t.is(error.exitCode, 1);
@@ -683,7 +685,7 @@ test('Custom rule with scoped package name via --rules', async t => {
683685
});
684686
t.fail();
685687
} catch (error) {
686-
const expected = ['scoped-test.md:1 scoped-rule Scoped rule'].join('\n');
688+
const expected = ['scoped-test.md:1 error scoped-rule Scoped rule'].join('\n');
687689
t.is(error.stdout, '');
688690
t.is(error.stderr, expected);
689691
t.is(error.exitCode, 1);
@@ -696,7 +698,7 @@ test('Custom rule from package loaded', async t => {
696698
await spawn('../markdownlint.js', ['--rules', './custom-rules/markdownlint-cli-local-test-rule', '--stdin'], {stdin});
697699
t.fail();
698700
} catch (error) {
699-
const expected = ['stdin:1 markdownlint-cli-local-test-rule Test rule package broken'].join('\n');
701+
const expected = ['stdin:1 error markdownlint-cli-local-test-rule Test rule package broken'].join('\n');
700702
t.is(error.stdout, '');
701703
t.is(error.stderr, expected);
702704
t.is(error.exitCode, 1);
@@ -709,7 +711,7 @@ test('Custom rule from several packages loaded', async t => {
709711
await spawn('../markdownlint.js', ['--rules', './custom-rules/markdownlint-cli-local-test-rule', '--rules', './custom-rules/markdownlint-cli-local-test-rule-other', '--stdin'], {stdin});
710712
t.fail();
711713
} catch (error) {
712-
const expected = ['stdin:1 markdownlint-cli-local-test-rule Test rule package broken', 'stdin:1 markdownlint-cli-local-test-rule-other Test rule package other broken'].join('\n');
714+
const expected = ['stdin:1 error markdownlint-cli-local-test-rule Test rule package broken', 'stdin:1 error markdownlint-cli-local-test-rule-other Test rule package other broken'].join('\n');
713715
t.is(error.stdout, '');
714716
t.is(error.stderr, expected);
715717
t.is(error.exitCode, 1);
@@ -736,7 +738,7 @@ test('fixing errors in a file yields fewer errors', async t => {
736738
await spawn('../markdownlint.js', ['--fix', '--config', 'test-config.json', fixFileA]);
737739
t.fail();
738740
} catch (error) {
739-
const expected = [fixFileA + ':1 MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## header 2"]'].join('\n');
741+
const expected = [fixFileA + ':1 error MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## header 2"]'].join('\n');
740742
t.is(error.stdout, '');
741743
t.is(error.stderr, expected);
742744
t.is(error.exitCode, 1);
@@ -783,7 +785,7 @@ test('.markdownlintignore is applied correctly', async t => {
783785
});
784786
t.fail();
785787
} catch (error) {
786-
const expected = ['incorrect.md:1:8 MD047/single-trailing-newline Files should end with a single newline character', 'subdir/incorrect.markdown:1:8 MD047/single-trailing-newline Files should end with a single newline character'].join('\n');
788+
const expected = ['incorrect.md:1:8 error MD047/single-trailing-newline Files should end with a single newline character', 'subdir/incorrect.markdown:1:8 error MD047/single-trailing-newline Files should end with a single newline character'].join('\n');
787789
t.is(error.stdout, '');
788790
t.is(error.stderr.replaceAll('\\', '/'), expected);
789791
t.is(error.exitCode, 1);
@@ -797,7 +799,7 @@ test('.markdownlintignore works with semi-absolute paths', async t => {
797799
});
798800
t.fail();
799801
} catch (error) {
800-
const expected = ['./incorrect.md:1:8 MD047/single-trailing-newline Files should end with a single newline character'].join('\n');
802+
const expected = ['./incorrect.md:1:8 error MD047/single-trailing-newline Files should end with a single newline character'].join('\n');
801803
t.is(error.stdout, '');
802804
t.is(error.stderr, expected);
803805
t.is(error.exitCode, 1);
@@ -811,7 +813,7 @@ test('--ignore-path works with .markdownlintignore', async t => {
811813
});
812814
t.fail();
813815
} catch (error) {
814-
const expected = ['incorrect.md:1:8 MD047/single-trailing-newline Files should end with a single newline character', 'subdir/incorrect.markdown:1:8 MD047/single-trailing-newline Files should end with a single newline character'].join('\n');
816+
const expected = ['incorrect.md:1:8 error MD047/single-trailing-newline Files should end with a single newline character', 'subdir/incorrect.markdown:1:8 error MD047/single-trailing-newline Files should end with a single newline character'].join('\n');
815817
t.is(error.stdout, '');
816818
t.is(error.stderr.replaceAll('\\', '/'), expected);
817819
t.is(error.exitCode, 1);
@@ -825,7 +827,7 @@ test('--ignore-path works with .ignorefile', async t => {
825827
});
826828
t.fail();
827829
} catch (error) {
828-
const expected = ['incorrect.markdown:1:8 MD047/single-trailing-newline Files should end with a single newline character'].join('\n');
830+
const expected = ['incorrect.markdown:1:8 error MD047/single-trailing-newline Files should end with a single newline character'].join('\n');
829831
t.is(error.stdout, '');
830832
t.is(error.stderr, expected);
831833
t.is(error.exitCode, 1);
@@ -893,7 +895,7 @@ test('--enable flag', async t => {
893895
t.fail();
894896
} catch (error) {
895897
t.is(error.stdout, '');
896-
t.is(error.stderr, 'incorrect.md:1 MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## header 2"]');
898+
t.is(error.stderr, 'incorrect.md:1 error MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## header 2"]');
897899
t.is(error.exitCode, 1);
898900
}
899901
});
@@ -904,7 +906,7 @@ test('--enable flag does not modify already enabled rules', async t => {
904906
t.fail();
905907
} catch (error) {
906908
t.is(error.stdout, '');
907-
t.is(error.stderr, 'correct.md:1 MD043/required-headings Required heading structure [Expected: # First; Actual: # header]');
909+
t.is(error.stderr, 'correct.md:1 error MD043/required-headings Required heading structure [Expected: # First; Actual: # header]');
908910
t.is(error.exitCode, 1);
909911
}
910912
});
@@ -915,7 +917,7 @@ test('--enable flag accepts rule alias', async t => {
915917
t.fail();
916918
} catch (error) {
917919
t.is(error.stdout, '');
918-
t.is(error.stderr, 'incorrect.md:1 MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## header 2"]');
920+
t.is(error.stderr, 'incorrect.md:1 error MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## header 2"]');
919921
t.is(error.exitCode, 1);
920922
}
921923
});
@@ -932,7 +934,7 @@ test('--disable flag', async t => {
932934
t.fail();
933935
} catch (error) {
934936
t.is(error.stdout, '');
935-
t.is(error.stderr, 'incorrect.md:1 MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## header 2"]');
937+
t.is(error.stderr, 'incorrect.md:1 error MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## header 2"]');
936938
t.is(error.exitCode, 1);
937939
}
938940
});

0 commit comments

Comments
 (0)