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
Added TooLongVariableNameViolation #291
Conversation
Pull Request Test Coverage Report for Build 681
💛 - 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.
Thanks for starting to work on this rule!
You can continue to implement the business logic for this rule, while we are releasing the 0.3.0
version.
Later, I will come back for the full review and we will merge it into 0.4.0
.
Does this sound fine to you?
@sobolevn yup sure no problem! |
|
||
# Correct: | ||
totalPrice = 100 | ||
coursesEnrolled = 5 |
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.
Just nitpicking, PEP8 does not recommend camelCase
Function and Variable Names
Function names should be lowercase, with words separated by underscores as necessary to improve readability.
Variable names follow the same convention as function names.
mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility.
we may not want the example to promote wrong notion, especially on a style guide :-)
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 agree with @nixphix
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.
@nixphix Noted! Just made the changes 👍
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!
@Casva can you please also add a business logic and tests for your rule?
@sobolevn sure not a problem! I also noticed that the "TooShortVariableNameViolation" rule was changed to "TooShortNameViolation" and checks for modules, variables, attributes, functions, methods, and classes. Did you want me to change TooLongVariableNameViolation to do the same thing? |
@Casva yes, I have unified logic for variables and modules. It seems reasonable to me, what do you think? |
@sobolevn makes sense to me. |
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 work! Thank you.
Just some documentation fixes and we are ready to go!
False | ||
|
||
""" | ||
return name != constants.UNUSED_VARIABLE and len(name) > max_length |
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 do not care about _
here. Since it is only one char long.
visitor.run() | ||
|
||
assert_errors(visitor, [TooLongNameViolation]) | ||
assert_error_text(visitor, filename.replace('.py', '')) |
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.
Missing new line at the end of the file.
@@ -43,6 +43,9 @@ class Configuration(object): | |||
- ``min-name-length`` - minimum number of chars to define a valid | |||
variable and module name, defaults to | |||
:str:`wemake_python_styleguide.options.defaults.MIN_NAME_LENGTH` | |||
- ``max-name-length`` - maximum number of chars to define a valid | |||
variable name, defaults to |
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.
variable and module name
_Option( | ||
'--max-name-length', | ||
defaults.MAX_NAME_LENGTH, | ||
'Maximum possible length of the variable name.', |
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.
variable and module name
@@ -21,6 +21,9 @@ | |||
#: Minimum variable's name length. | |||
MIN_NAME_LENGTH: Final = 2 | |||
|
|||
#: Maximum variable's name length: |
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.
variable and module name length
@final | ||
class TooLongNameViolation(ASTViolation): | ||
""" | ||
Forbids to have too long variable or module 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.
variable and module names
|
||
.. versionadded:: 0.4.0 | ||
|
||
Note: |
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 do not use Note
anymore, see this commit: e428aab
|
||
""" | ||
|
||
#: Error message shown to the user. |
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 do not use this comment anymore, see this commit e428aab
@sobolevn Alright! Everything should be good to go now! 😄 |
There's a lot of names in the repo that are longer than the default maximum length (29 characters). |
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.
Just a single typo left!
return name != len(name) > max_length |
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.
there's an error here. please, remove name !=
@sobolevn Aand done! 👍 |
@Casva yes, please change it to Also, please take care of some build issues. |
@sobolevn after some mass cleaning up it's almost perfect!
Thanks! |
setup.cfg
Outdated
@@ -11,7 +11,7 @@ branch = True | |||
|
|||
|
|||
[flake8] | |||
max-complexity = 6 | |||
max-complexity = 7 |
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.
Please, do not change this value.
@Casva thanks for your work! We are almost there!
👍 |
@sobolevn Got it, I changed I'm at a loss for refactoring: I've tried grouping the length testers into another method and incorporating that in the original |
@Casva ok, leave this method as P.S. Have you tried this project on your own codebase? What are the results? Do you find it useful? Any feedback is appreciated 🙂 |
@sobolevn alright done! Thanks for all your patience! And yes I tried using it and I realized how poorly I code 😆 |
@Casva it was still failing. Can you please rebase your changes and fix the tests? |
9bcaf66
to
65f5ef8
Compare
7fe9b05
to
3d3bb8a
Compare
Sorry for the delay @sobolevn, been busy with school work. Let me know if there's anything else you need changed! 👍 |
@Casva can you please resolve the merge conflicts once again please? Thanks! |
…gVariableNameViolation rule Updated CHANGELOG.md
…nd associated tests Fixed config MAX_VARIABLE_LENGTH -> MAX_NAME_LENGTH, updated types.py to contain max_name_length added rule integration into noqa and test_noqa Fixed documentation (mainly variable -> variable and module) Forgot extra line at the end of logical.py Reordered imports to match tests Fixed line 188 in logical.py Changed default max-length to 40, changed to tests to reflect this as well
ASTViolation -> MaybeASTViolation in naming.py | fixed multi-line string error (added \) in logical.py | other syntax fixes Removed WrongModuleNamePatternViolation in test_module_name_length.py on line 56 | replaced backslashe line break with indent)
…_check_name under naming.py Removed WrongModuleNamePatternViolation in test_module_name_length.py on line 56 | replaced backslashe line break with indent) Changed max-complexity from 6 to 7 to accomodate new if statement in _check_name under naming.py
Refactored _check_name to include new function _check_name_length; reduces complexity Erased variable assignment in _check_name instead Reverted _check_name back to original
Also removed test in test_naming until _check_name is refactored Removed instances of previous TooLongNameViolation tests in naming.py and test_naming.py
Fixed imports Fixed whitspace issue Workaround for line limit a a a a
@sobolevn rebased and fixed! |
@Casva you have made an amazing job! Thank you very much! |
I have made things!
Checklist
CHANGELOG.md
Related issues
Closes #288
Refs #288
Let me know if anything needs to be changed! 😄