Skip to content

Commit a22c5ce

Browse files
committedFeb 6, 2020
Add starting column number to violation output string (refs #52).
1 parent 2fb5506 commit a22c5ce

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed
 

‎markdownlint.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,12 @@ function prepareFileList(files, fileExtensions, previousResults) {
116116
}
117117

118118
function printResult(lintResult) {
119-
const results = flatten(Object.keys(lintResult).map(function (file) {
120-
return lintResult[file].map(function (result) {
119+
const results = flatten(Object.keys(lintResult).map(file => {
120+
return lintResult[file].map(result => {
121121
return {
122122
file: file,
123123
lineNumber: result.lineNumber,
124+
column: (result.errorRange && result.errorRange[0]) || 0,
124125
names: result.ruleNames.join('/'),
125126
description: result.ruleDescription +
126127
(result.errorDetail ? ' [' + result.errorDetail + ']' : '') +
@@ -130,12 +131,14 @@ function printResult(lintResult) {
130131
}));
131132
let lintResultString = '';
132133
if (results.length > 0) {
133-
results.sort(function (a, b) {
134+
results.sort((a, b) => {
134135
return a.file.localeCompare(b.file) || a.lineNumber - b.lineNumber ||
135136
a.names.localeCompare(b.names) || a.description.localeCompare(b.description);
136137
});
137-
lintResultString = results.map(function (result) {
138-
return result.file + ':' + result.lineNumber + ' ' + result.names + ' ' + result.description;
138+
lintResultString = results.map(result => {
139+
const {file, lineNumber, column, names, description} = result;
140+
const columnText = column ? `:${column}` : '';
141+
return `${file}:${lineNumber}${columnText} ${names} ${description}`;
139142
}).join('\n');
140143
// Note: process.exit(1) will end abruptly, interrupting asynchronous IO
141144
// streams (e.g., when the output is being piped). Just set the exit code

‎test/test.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import path from 'path';
55
import test from 'ava';
66
import execa from 'execa';
77

8-
const errorPattern = /(\.md|\.markdown|\.mdf|stdin):\d+ MD\d{3}/gm;
8+
const errorPattern = /(\.md|\.markdown|\.mdf|stdin):\d+(:\d+)? MD\d{3}/gm;
99

1010
process.chdir('./test');
1111

@@ -226,10 +226,10 @@ test('linting results are sorted by file/line/names/description', async t => {
226226
'incorrect.md:1 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## header 2"]',
227227
'incorrect.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## header 2"]',
228228
'incorrect.md:2 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Above] [Context: "# header"]',
229-
'incorrect.md:5 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]',
230-
'incorrect.md:11 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]',
231-
'incorrect.md:17 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]',
232-
'incorrect.md:23 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]',
229+
'incorrect.md:5:1 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]',
230+
'incorrect.md:11:1 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]',
231+
'incorrect.md:17:1 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]',
232+
'incorrect.md:23:1 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]',
233233
''
234234
].join('\n');
235235
t.deepEqual(error.stdout, '');
@@ -376,7 +376,7 @@ function getCwdConfigFileTest(extension) {
376376
t.fail();
377377
} catch (error) {
378378
const expected = [
379-
'heading-dollar.md:1 MD026/no-trailing-punctuation Trailing punctuation in heading [Punctuation: \'$\']',
379+
'heading-dollar.md:1:10 MD026/no-trailing-punctuation Trailing punctuation in heading [Punctuation: \'$\']',
380380
''
381381
].join('\n');
382382
t.deepEqual(error.stdout, '');
@@ -637,8 +637,8 @@ test('.markdownlintignore is applied correctly', async t => {
637637
t.fail();
638638
} catch (error) {
639639
const expected = [
640-
'incorrect.md:1 MD047/single-trailing-newline Files should end with a single newline character',
641-
'subdir/incorrect.markdown:1 MD047/single-trailing-newline Files should end with a single newline character',
640+
'incorrect.md:1:8 MD047/single-trailing-newline Files should end with a single newline character',
641+
'subdir/incorrect.markdown:1:8 MD047/single-trailing-newline Files should end with a single newline character',
642642
''
643643
].join('\n');
644644
t.deepEqual(error.stdout, '');
@@ -656,8 +656,8 @@ test('--ignore-path works with .markdownlintignore', async t => {
656656
t.fail();
657657
} catch (error) {
658658
const expected = [
659-
'incorrect.md:1 MD047/single-trailing-newline Files should end with a single newline character',
660-
'subdir/incorrect.markdown:1 MD047/single-trailing-newline Files should end with a single newline character',
659+
'incorrect.md:1:8 MD047/single-trailing-newline Files should end with a single newline character',
660+
'subdir/incorrect.markdown:1:8 MD047/single-trailing-newline Files should end with a single newline character',
661661
''
662662
].join('\n');
663663
t.deepEqual(error.stdout, '');
@@ -675,7 +675,7 @@ test('--ignore-path works with .ignorefile', async t => {
675675
t.fail();
676676
} catch (error) {
677677
const expected = [
678-
'incorrect.markdown:1 MD047/single-trailing-newline Files should end with a single newline character',
678+
'incorrect.markdown:1:8 MD047/single-trailing-newline Files should end with a single newline character',
679679
''
680680
].join('\n');
681681
t.deepEqual(error.stdout, '');

0 commit comments

Comments
 (0)
Please sign in to comment.