feat: print linter match with context #2303
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issues
N/A
Description
Formats a lint match with surrounding context for debug output.
This is a handy little tool for when you're working on a new
ExprLinter.Using the new
match_to_lint_with_contextmethod it will print the run of text that matches, along with the text before and after it dimmed using ANSI escape codes.This can help you hone in your
Exprbefore you start working on extracting the lint.When you're wondering about false positives or trying to sort them out, this helps you see what the most common previous or next words, or several words tend to be.
It does its best to filter out distracting markup that's sometimes between tokens and printed if you just do
toks.span()?.get_content_string(src)since that will get everything between the start and the end. You would've seen this when linting Markdown files containing HTML on the command line.Works great from
cargo testor via the smarts in the editor and Rust LSP, and works really great from the newharper-cli lintrun over a directory full of files.Demo
How Has This Been Tested?
Manually.
Checklist