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
Reimplement unamed-task rule as name[missing] #2263
Conversation
bb4ef5e
to
ee1a8eb
Compare
This reimplementation will allow us to implement closely related extra checks. Related: ansible#2171 ansible#2170 ansible#2169 ansible#2036
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dang. Sorry I didn't review before this was merged. I have a few questions to address in a follow-up.
) -> Union[bool, str, MatchError]: | ||
if not task.get("name"): | ||
return self.create_matcherror( | ||
linenumber=task["__line__"], tag="name[missing]", filename=file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the LINE_NUMBER_KEY constant in ansiblelint.utils.LINE_NUMBER_KEY
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this bypasses some of the enrichment that happens in matchtasks()
like details
and match.task
.
ansible-lint/src/ansiblelint/rules/__init__.py
Lines 162 to 177 in a5f0d52
if isinstance(result, MatchError): | |
if result.tag in skipped_tags: | |
continue | |
match = result | |
else: | |
message = None | |
if isinstance(result, str): | |
message = result | |
task_msg = "Task/Handler: " + ansiblelint.utils.task_to_str(task) | |
match = self.create_matcherror( | |
message=message, | |
linenumber=task[ansiblelint.utils.LINE_NUMBER_KEY], | |
details=task_msg, | |
filename=file, | |
) | |
match.task = task |
I'm not sure where we should add that. Maybe matchtasks()
should be refactored to update details
if it is not set, and add match.task
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was aware about missing details but I was not sure what to include in them. The reality is that the generic "name" description is no longer relevant for various violations.
Probably we need to add some longer descriptions but we need to write the text for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2277 should address my feedback here.
This reimplementation will allow us to implement closely related extra checks such
name[casing]
,name[imperative]
,name[unique]
,name[suffix]
.Related: #2171 #2170 #2169