-
Notifications
You must be signed in to change notification settings - Fork 688
Add noqa skips in otherwise empty lines to the next non-empty line #4567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This will have to wait until we finish the changes started in #4564 - adding support for ansible 2.19 with data tagging. There were a really big number of changes related to this and they also affect this area. |
That makes sense. I already noticed that PR. I didn't see any commit to I'd happily contribute as soon as refactoring is done, just ping me again |
…the next non-empty line
@ssbarnea I guess the data tagging changes are integrated now, any chance you could take a look again? |
This addresses #3935
So what it does:
traverse_yaml
to flatten lists within there (these are required for a ruamel CommentMap, please don't ask any further, afaik these are entirely undocumented)#noqa
and inserting them into thelintable
, postprocessing is done on thelintable
.# noqa
is the start of the line, minus some whitespace/indentation.# noqa
on that line, the skip is added to the next non-empty line.This is something required for me in order to suppress errors on yaml multiline strings, as reported by the issue referenced.
In general I think the solution is quite hacky, so this can also be seen as a proof of concept. The whole flattening thing and how ruamel works with comments is quite weird. As in the context of
_get_rule_skips_from_yaml
only a map of{lineno: rule_to_skip}
is what we're interested in, it might be easier to just go over the content of a file, check each line for_noqa_comment_re
match. The whole tree structure ofCommentMap
is annoying to traverse, a simple iterator over all comments would do it (don't know if that's inpyyaml
?) and would be more accurate for comments not attached to objects in a line.