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
add new domain names options #1106
Conversation
Introduce 2 new options: + `--allowed-domain-names` - remove given names from variable names' blacklist + `--forbidden-domain-names` - extends variable names' blacklist with given names The options listed above are used to create variable names' blacklist which is leveraged to detect `WrongVariableNameViolation` violations.
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.
Great work! Thanks a lot!
I have two minor questions and we are good to go.
@@ -109,6 +112,17 @@ def check_attribute_name(self, node: ast.ClassDef) -> None: | |||
naming.UpperCaseAttributeViolation(target, text=target.id), | |||
) | |||
|
|||
@property |
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.
It can be:
- Cached
- Moved to
logic/
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.
- Cached
Current implementation provide caching, it'a similar to @cached_property
from django
.
Do you want to introduce new dependency e.g. cached-property
just for it?
- Moved to
logic/
I can move it there if you want, but could you tell me to which file or maybe I should create new one?
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.
You can create a new one 👍
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.
No new dependecies are required, you can try to use lru_cache
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.
However when the code responsible for creating variable names' blacklist will be moved to logic/
then it should be enough to just assign the result in __init__
:
def __init__(...):
...
self.variable_names_blacklist = logic.create_variable_names_blacklist()
What do 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.
Sounds fine!
*VARIABLE_NAMES_BLACKLIST, | ||
*self._options.forbidden_domain_names, | ||
} | ||
for name in self._options.allowed_domain_names: |
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.
Can we use just set
arithmetic here?
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.
Shouldn't be an error if allowed
and forbidden
names intersects?
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.
At least, if option variables intersect.
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, I agree. But! Only during validation. Not in runtime
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.
is validate_options()
proper place to add above mentioned validation logic?
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.
Yeap!
Pull Request Test Coverage Report for Build 2496
💛 - Coveralls |
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.
Awesome progress, thanks again 👍
@@ -45,7 +45,7 @@ | |||
class _NameValidator(object): | |||
"""Utility class to separate logic from the naming visitor.""" | |||
|
|||
_variable_names_blacklist: Optional[Set[str]] | |||
variable_names_blacklist: Set[str] |
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.
Why is it public?
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.
To be honest I don't know :D I found it more proper/clear when I was writing this code. I will correct it in following commit
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.
Awesome! Thanks!
I will merge it into 0.14
release
Merging into Thanks again! |
I have made things!
Checklist
CHANGELOG.md
Related issue
Closes: #1103
Introduce 2 new options:
--allowed-domain-names
- remove given names from variable names'blacklist
--forbidden-domain-names
- extends variable names' blacklist withgiven names
The options listed above are used to create variable names' blacklist
which is leveraged to detect
WrongVariableNameViolation
violations.