-
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 linter for Open edX Filters classes definitions #480
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.
|
I pinged the Axim eng team in slack to see if anyone has an opinion on this - I don't, but I'm not a primary maintainer of this repo. |
Thank you, @sarina! I'll tag @openedx/axim-engineering here as the owners according to the catalog-info.yaml. |
Hi @mariajgrimaldi ! My memory isn't great on this, but I think that:
If that's the case I think this is a good place for that check. If it's a requirement that filters only be defined in openedx-filters then I'd expect this check to live there. Otherwise I'm 👍 on this PR, just want to make sure it's in the right place. |
""" | ||
required_sections = [ | ||
(r"Purpose:\s*.*\n", self.DOCSTRING_MISSING_PURPOSE), | ||
(r"Filter Type:\s*.*\n", self.DOCSTRING_MISSING_TYPE), |
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.
We are currently just validating that it's not empty, shouldn't we make this regex more robust to ensure it matches a valid type? Or do we not have a defined set of valid types yet?
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.
Yes, we have a format for the filter_type attribute (see ADR-0004), but even though, there are a lot of cases to consider. A good middle ground to still allow flexibility could be to check that the Filter Type
from the docstring matches the OpenEdxPublicFilter.filter_type
, so we know that docstrings contain accurate information. I can try applying this suggestion to openedx-events as well.
OpenEdxPublicFilter class itself. | ||
|
||
""" | ||
if not node.is_subtype_of("openedx_filters.tooling.OpenEdxPublicFilter"): |
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.
This checker currently validates both whether the class is a subclass of OpenEdxPublicFilter and whether the class name is exactly OpenEdxPublicFilter but this second validation is redundant 'cause by definition, the OpenEdxPublicFilter class cannot be its own subclass, maybe we could do something like this:
if not node.is_subtype_of("openedx_filters.tooling.OpenEdxPublicFilter") or node.name == "OpenEdxPublicFilter":
return
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.
With only the first condition, the linter was reviewing OpenEdxPublicFilter
as well, so I added the second condition to avoid that behavior. I'm doing more tests to see why I was getting that behavior. I'll let you know what I find :)
EDIT: OpenEdxPublicFilter can be its own subtype
>>> node.is_subtype_of("openedx_filters.tooling.OpenEdxPublicFilter")
True
>>> node.name
'OpenEdxPublicFilter'
That's why we need the 2nd condition. I implemented your suggestion to take advantage of the short-circuit behavior.
5d4a122
to
b0c3aec
Compare
|
||
If the filter type is missing or incorrect, return the error message. Otherwise, return. | ||
""" | ||
filter_type = node.locals["filter_type"][0].statement().value.value |
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.
note to self: I think I should do some error handling here (like in https://github.com/openedx/edx-lint/blob/master/edx_lint/pylint/annotations_check.py#L515?).
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 think that makes sense, otherwise I'm 👍 on this
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 implemented our suggestion here: 7455a5e. Thank you!
@bmtcril: Thanks for the insight! So yes, the goal is for filters and events to implement reusable ones in each of the |
I think it just needs a rebase and version bump to be good to go! 🚀 |
7455a5e
to
46ac9a3
Compare
@bmtcril: thank you for the reviews! This is ready for merging when you see fit :) |
All set and released! |
Description:
This PR adds a custom linter for Open edX Filter classes docstrings to check whether new filters follow the specified format:
If a class is missing at least one of the section, then a pylint error is raised:
You can see the linter integrated into the repo in this PR: openedx/openedx-filters#249
I'm open to moving this directly into the openedx-filters repo if needed, considering that the linter is kind of specific to that repository.
Merge checklist: