Add noqa skips in otherwise empty lines to the next non-empty line#4567
Merged
ssbarnea merged 1 commit intoansible:mainfrom Jun 17, 2025
Merged
Add noqa skips in otherwise empty lines to the next non-empty line#4567ssbarnea merged 1 commit intoansible:mainfrom
ssbarnea merged 1 commit intoansible:mainfrom
Conversation
Member
|
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. |
Contributor
Author
|
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 |
Contributor
Author
|
@ssbarnea I guess the data tagging changes are integrated now, any chance you could take a look again? |
ssbarnea
approved these changes
Jun 17, 2025
Add postprocessing which adds noqa skips in otherwise empty lines to the next non-empty line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes: #3935
So what it does:
traverse_yamlto flatten lists within there (these are required for a ruamel CommentMap, please don't ask any further, afaik these are entirely undocumented)#noqaand inserting them into thelintable, postprocessing is done on thelintable.# noqais the start of the line, minus some whitespace/indentation.# noqaon 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_yamlonly 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_rematch. The whole tree structure ofCommentMapis 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.