-
Notifications
You must be signed in to change notification settings - Fork 26
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
feat: [FC-0074] add inline code annotation linter for Open edX Events #478
Conversation
Thanks for the pull request, @mariajgrimaldi! This repository is currently maintained by @openedx/axim-engineering. Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.
|
This looks good to me, but I don't know this repo well (and am not a CC on it) so I can't provide an approving review. |
Thank you, @sarina. I'll tag @openedx/axim-engineering as the owners according to the catalog-info.yaml and the bot comment above. |
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.current_module_annotated_event_names = set() | ||
self.current_module_annotation_group_line_numbers = [] |
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.
The current use of self.current_module_annotation_group_line_numbers
for tracking annotation lines looks functional but may be brittle if annotations are not perfectly aligned with the corresponding events so this reliance on order may lead to false positives or negatives in certain scenarios.
I think we could consider using a mapping from line numbers to event names (something like self.current_module_annotations = {line_number: event_name}) to directly associate each annotation with its corresponding event, this could make the logic more robust and reduce potential issues caused by misalignment or unexpected ordering
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.
Thanks for the suggestion! This implementation was inspired by the toggle annotations checker, here: https://github.com/openedx/edx-lint/blob/master/edx_lint/pylint/annotations_check.py#L329-L519 and then modified to fit the events inline code-annotations.
As far as I understand, annotations are visited in check_annotation_group
using the ASTWalker, which visits annotation groups (starting with # ..
) for each module. It finds the line where the annotation group starts, saves it in a queue-like list and saves an identifier, in this case, the event name for the annotation. Then is_annotation_missing
is called for each OpenEdxPublicSignal
instantiation (called call node
). Since they are also visited using the same ASTWalker, the nodes are traversed in the same order, so the annotation groups should match the call node:
# .. event_type: org.openedx.learning.auth.session.login.completed.v1 # <- ANNOTATION GROUP
# .. event_name: SESSION_LOGIN_COMPLETED
# .. event_key_field: user.pii.username
# .. event_description: emitted when the user's login process in the LMS is completed.
# .. event_data: UserData
SESSION_LOGIN_COMPLETED = OpenEdxPublicSignal( # <- CALL NODE
event_type="org.openedx.learning.auth.session.login.completed.v1",
data={
"user": UserData,
}
)
That's why I don't think we would have an issue with unexpected ordering since we're traversing the modules using the same strategy. Also, since we are using the line number queue of each annotation group as our stopping condition, then we'd need the dict to behave like a queue so is_annotation_missing
stops when needed.
Those are the main reasons why I think changing the set and queue for a dict would add more overhead than leaving it as it is. Let me know if you disagree or have any other suggestions considering what I mentioned.
EDIT: maybe something like this could happen, where the event names are switched and the linter won't raise any issues. I'll try to invest some time into figuring out how to cover these cases, I'll let you know what I find!
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.
@Alec4r: I think I've addressed your concerns with these commits:
- Use a dict to store types and other annotations to check against nodes later in
_is_annotation_missing_or_incorrect
, the current annotation group should match the event init arguments (since they're traversed in order) so the check is successful: d1adeda - Check that the event name matches the annotation group besides event type and data: dadaa92
Let me know what you think!
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.
@mariajgrimaldi looks good for me.
@sarina: who else do you think we should tag for a review? |
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.
LGTM
@bmtcril - if this is good to you, could you go ahead and merge? @mariajgrimaldi isn't a CC on this repo. |
Description:
This PR adds a linter for events code-annotations to find missing required fields like: name, type, data and description for Open edX Events. If any of these fields are missing, then a quality error is raised.
You can see it working in this PR: openedx/openedx-events#448 by running
pylint openedx_events/learning/signals.py
:This linter aims to enforce the standard of in-line code annotations for developers to follow when documenting events definitions in the openedx-events (and others) repositories.
I'm open to moving this directly into the openedx-events repo if needed, considering that the linter is kind of specific to that repository.
Merge checklist: