Add invalid name checker uppercase and pascal case suggested fixes#1341
Add invalid name checker uppercase and pascal case suggested fixes#1341a1-su wants to merge 4 commits into
Conversation
Coverage Report for CI Build 26200273900Warning Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes. Coverage decreased (-0.006%) to 90.533%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
david-yz-liu
left a comment
There was a problem hiding this comment.
@a1-su nice work. In addition to the inline comment I left, (1) see the comments I left on https://github.com/pyta-uoft/pyta/pull/1340/changes (they also apply here), and (2) make sure to update the changelog.
| """Returns a PascalCase version of `name`.""" | ||
| prefix, words, _ = _parse_name(name) | ||
|
|
||
| return prefix + "".join(word.capitalize() for word in words) |
There was a problem hiding this comment.
With pascal case we will allow allcaps words, e.g. JSONParser. So I wouldn't use str.capitalize directly but instead manually ensure the first letter is capitalized.
There was a problem hiding this comment.
No problem 👍. As a side note, one unintended consequence may be that even though it works for a name like parseJSONText to ParseJSONText, for a name like UPPER_CASE_NAME, this gets converted to UPPERCASENAME instead of UpperCaseName.
Proposed Changes
Adds suggested naming fixes for the
UPPER_CASE_WITH_UNDERSCORESandPascalCasevariable names in theinvalid_name_checker.py. Added the_to_upper_case_with_underscoresand_to_pascal_casehelper functions and corresponding tests.Type of Change
(Write an
Xor a brief description next to the type or types that best describe your changes.)Checklist
(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the
[ ]into a[x]in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)Before opening your pull request:
After opening your pull request:
Questions and Comments
(Include any questions or comments you have regarding your changes.)
The
CHANGELOG.mdwasn't updated as it should have been updated in Rachel's PRWhile I know a single trailing underscore is sometimes used by libraries to denote different things, such as that a method is in-place, in the conversion to
UPPERCASE_WITH_UNDERSCORES, I've allowed multiple trailing underscores because the regex in the function_is_in_upper_case_with_underscoresunconventionally allows it. If this is something that should should be flagged, feel free to let me know and I can change both functions.pyta/packages/python-ta/src/python_ta/checkers/invalid_name_checker.py
Lines 73 to 82 in 6ef78a0
This is less related to this specific PR, but I noticed that the
_check_method_and_attr_namefunction accepts names that start with three underscores (not just two or three)pyta/packages/python-ta/src/python_ta/checkers/invalid_name_checker.py
Lines 195 to 203 in 6ef78a0
Due to the fact after the "__" is spliced,
_is_in_snake_casestill accepts a leading underscorepyta/packages/python-ta/src/python_ta/checkers/invalid_name_checker.py
Lines 45 to 56 in 6ef78a0
I'm not sure if this is intentional or not, but triple underscore-prefixed variables in Python seem uncommon to me.