Modify invalid_name_checker snake case checks#1340
Conversation
Coverage Report for CI Build 26054787114Coverage increased (+0.01%) to 90.553%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
|
|
||
| def _to_snake_case(name: str) -> str: | ||
| """Converts a name to snake_case format.""" | ||
| return re.sub(r"([a-z0-9])([A-Z])", r"\1_\2", name).lower() |
There was a problem hiding this comment.
In the _is_in_snake_case method, the regex also requires that the name begin with a letter (a-z). However, the current suggested approach will not correctly return a word that is in snake case.
In general I think it's hard to generate a good suggestion if the variable doesn't start with a letter already.
So I recommend (1) modifying the return type to str | None, returning None when no valid suggestion can be generated, and (2) modifying the check functions below to only display the suggested fix if one is returned.
| f'Module name "{name}" should be in snake_case format. Modules should be all-lowercase ' | ||
| f"names, with each name separated by underscores." | ||
| f"names, with each name separated by underscores. " | ||
| f'Suggested fix: "{suggested_name}".' |
There was a problem hiding this comment.
In general, if there is a suggestion then I'd like it to appear in the second sentence, e.g. f'Module name "{name}" should be in snake_case format. Suggested fix: ...'
Proposed Changes
Modified the check functions in invalid_name_checker.py that use snake_case format (module, function and variable, method and attribute, and argument names), to include a suggested fix for invalid names. Added _to_snake_case helper function to parse invalid names into snake_case format and updated the tests for module, function and variable, method and attribute, and argument names to include the suggested fix.
...
Screenshots of your changes (if applicable)
Type of Change
Checklist
Before opening your pull request:
After opening your pull request:
Questions and Comments