Skip to content

Conversation

@holger-detering
Copy link

Description

Fixes markdownlint handler to support version 0.47.0 output format changes.

Problem

Markdownlint version 0.47.0 changed its output format by adding severity
keywords (error and warning) after the column number. This broke ALE's
parser which expected a fixed format.

Analysis

I'm using vim 9.1 and ALE 4.0.0.

I discovered this bug when installing markdownlint-cli via npm and noticing
that ALE was not parsing the linter output. After comparing the output between
versions 0.46.0 and 0.47.0, I identified that the format change (addition of
severity keywords) was causing the regex pattern in the ALE handler to fail to
match the new output format.

Minimal test case

To reproduce the issue, create a file test.md that should produce linter
error:

# Test

[LinkText](#link)

Configure ALE to use just markdownlint for markdown files:

let g:ale_linters = {'markdown': ['markdownlint']}

Install markdownlint version 0.46.0:

npm install -g [email protected]

Check, if version 0.46.0 is installed:

$ markdownlint --version
0.46.0

Lint test.md:

$ markdownlint test.md
test.md:3:1 MD051/link-fragments Link fragments should be valid [Context: "[LinkText](#link)"]

Opening test.md with vim shows a warning for line 3, column 1.

Next, install markdownlint version 0.47.0:

npm install -g [email protected]

Check, if version 0.47.0 is installed:

$ markdownlint --version
0.47.0

Lint test.md:

$ markdownlint test.md
test.md:3:1 error MD051/link-fragments Link fragments should be valid [Context: "[LinkText](#link)"]

Notice the error after the column number.

Opening test.md with vim shows no error or warning for line 3.

To produce warning instead of error, create a markdownlint config file that
marks 'MD051' as warning, e.g. .markdownlint.yml:

---
'MD051': 'warning'
$ markdownlint test.md
test.md:3:1 warning MD051/link-fragments Link fragments should be valid [Context: "[LinkText](#link)"]

Solution

Updated the markdownlint handler regex pattern to handle the optional severity
keyword while maintaining backward compatibility with version 0.46.0.

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

Testing

  • Added tests for both error and warning severity keywords (0.47.0+)
  • Verified backward compatibility with existing tests (0.46.0)
  • All tests pass

Commits

  1. First commit: Added failing tests demonstrating the bug
  2. Second commit: Fixed the handler to make tests pass

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.
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.
- Add blank line before if statement for better readability
- Replace `==#` with `is#` for case-sensitive comparison
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant