Skip to content

Commit 9b51f66

Browse files
Fix markdownlint output format (#5085)
* test: Add failing tests for markdownlint 0.47.0 output format Add two new test cases to verify the markdownlint handler's ability to parse output from version 0.47.0, which includes severity keywords ("error" or "warning"). These tests will fail with the current implementation, demonstrating the need for a fix to handle the new output format. The tests specifically verify: - Parsing of error severity keyword - Parsing of warning severity keyword - Correct mapping of severity to ALE type (E/W) Backward compatibility with version 0.46.0 is already verified by the existing ests. * fix: Update markdownlint handler for version 0.47.0 output format Update the markdownlint handler to support the new output format introduced in version 0.47.0, which includes severity keywords ("error" and "warning") after the column number. Changes: - Updated regex pattern to capture optional severity keyword - Added type mapping logic (error → 'E', warning → 'W') - Adjusted match indices for rule ID and description text - Maintained backward compatibility with version 0.46.0 All tests now pass, including the new tests for 0.47.0 format. * style: Fix vint linting errors in markdownlint handler - Add blank line before if statement for better readability - Replace `==#` with `is#` for case-sensitive comparison
1 parent e3c1528 commit 9b51f66

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

autoload/ale/handlers/markdownlint.vim

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22
" Description: Adds support for markdownlint
33

44
function! ale#handlers#markdownlint#Handle(buffer, lines) abort
5-
let l:pattern=': \?\(\d\+\)\(:\(\d\+\)\?\)\? \(MD\d\{3}/[A-Za-z0-9-/]\+\) \(.*\)$'
5+
let l:pattern=': \?\(\d\+\)\(:\(\d\+\)\?\)\? \(error\|warning\)\? \?\(MD\d\{3}/[A-Za-z0-9-/]\+\) \(.*\)$'
66
let l:output=[]
77

88
for l:match in ale#util#GetMatches(a:lines, l:pattern)
9+
let l:type = 'W'
10+
11+
if l:match[4] is# 'error'
12+
let l:type = 'E'
13+
endif
14+
915
let l:result = ({
1016
\ 'lnum': l:match[1] + 0,
11-
\ 'code': l:match[4],
12-
\ 'text': l:match[5],
13-
\ 'type': 'W',
17+
\ 'code': l:match[5],
18+
\ 'text': l:match[6],
19+
\ 'type': l:type,
1420
\})
1521

1622
if len(l:match[3]) > 0

test/handler/test_markdownlint_handler.vader

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,33 @@ Execute(The Markdownlint handler should parse output with multiple slashes in ru
3232
\ ale#handlers#markdownlint#Handle(0, [
3333
\ 'README.md:10 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Above] [Context: "### something"]'
3434
\ ])
35+
36+
Execute(The Markdownlint handler should parse output with error severity (0.47.0+)):
37+
AssertEqual
38+
\ [
39+
\ {
40+
\ 'lnum': 3,
41+
\ 'col': 1,
42+
\ 'code': 'MD051/link-fragments',
43+
\ 'text': 'Link fragments should be valid [Context: "[Installation](#installation)"]',
44+
\ 'type': 'E'
45+
\ }
46+
\ ],
47+
\ ale#handlers#markdownlint#Handle(0, [
48+
\ 'test.md:3:1 error MD051/link-fragments Link fragments should be valid [Context: "[Installation](#installation)"]'
49+
\ ])
50+
51+
Execute(The Markdownlint handler should parse output with warning severity (0.47.0+)):
52+
AssertEqual
53+
\ [
54+
\ {
55+
\ 'lnum': 3,
56+
\ 'col': 1,
57+
\ 'code': 'MD051/link-fragments',
58+
\ 'text': 'Link fragments should be valid [Context: "[Installation](#installation)"]',
59+
\ 'type': 'W'
60+
\ }
61+
\ ],
62+
\ ale#handlers#markdownlint#Handle(0, [
63+
\ 'test.md:3:1 warning MD051/link-fragments Link fragments should be valid [Context: "[Installation](#installation)"]'
64+
\ ])

0 commit comments

Comments
 (0)