-
Notifications
You must be signed in to change notification settings - Fork 65
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 --name argument #131
Conversation
Please have a look at the docs builds error. |
@jimmylai Can you please look into it? |
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 suggestion, but how would it look using the path (like chained_isinstance_check.py
) when there is no name supplied (convert the path's stem into ChainedIsinstanceCheck
)
fixit/cli/add_new_rule.py
Outdated
def create_rule_file(file_path: Path) -> None: | ||
def is_valid_name(name: str) -> str: | ||
"""Check for valid rule name """ | ||
if name.endswith(("Rule", "Rules", "rule", "rules")): |
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.
if name.endswith(("Rule", "Rules", "rule", "rules")): | |
if name.casefold().endswith(("rule", "rules")): |
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.
Done
fixit/cli/add_new_rule.py
Outdated
def is_valid_name(name: str) -> str: | ||
"""Check for valid rule name """ | ||
if name.endswith(("Rule", "Rules", "rule", "rules")): | ||
raise NameError("Please enter rule name without the suffix, `rule` or `Rule`") |
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 would be more consistent if you use single quotes instead of backticks (just like KeyError etc.)
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.
Also, NameError doesn't suit well, maybe use ValueError?
fixit/cli/add_new_rule.py
Outdated
"""Check for valid rule name """ | ||
if name.endswith(("Rule", "Rules", "rule", "rules")): | ||
raise NameError("Please enter rule name without the suffix, `rule` or `Rule`") | ||
return snake_to_camelcase(name) if name else "" |
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 omit if name else ""
since snake_to_camelcase
with empty string would result with an empty string.
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.
done
Done. Nice idea |
docs/source/build_a_lint_rule.ipynb
Outdated
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} | ||
} |
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 newline at the end
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.
done
For some reason, this error just show up recently. |
I am also getting this error in local dev. |
We can use something like this. file_content = """\
class C:
...content of In[2]
""" then write |
docs/source/getting_started.ipynb
Outdated
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"nbsphinx": "hidden" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"file_content = \"\"\"\\\n", | ||
"from typing import Dict\n", | ||
"\n", | ||
"\n", | ||
"class C(object):\n", | ||
" attr = \"ab\" \"cd\" \"ef\" \"gh\"\n", | ||
"\n", | ||
" def method(self) -> Dict[int, str]:\n", | ||
" filtered_char = []\n", | ||
" for char in self.attr:\n", | ||
" if char is not \"a\":\n", | ||
" filtered_char.append(char)\n", | ||
"\n", | ||
" index_to_char = dict([(idx, char) for idx, char in enumerate(filtered_char)])\n", | ||
" return index_to_char\n", | ||
"\"\"\"" | ||
] | ||
}, |
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.
Copy the example code is not ideal. It'll make the future updated less easy.
I've found a workaround in #133
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'll revert it. Thanks
2726995
to
b4ada29
Compare
docs/source/build_a_lint_rule.ipynb
Outdated
"- ``--path`` is used to create rule file at path given in ``--path``, Default is ``fixit/rules/new.py``\n", | ||
"- ``--name`` is used to assign the name of the rule and should be in snake case, Default is name of the rule file if ``path`` provided else `new`. Otherwise, considers the value specified in ``--name``\n", |
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.
"- ``--path`` is used to create rule file at path given in ``--path``, Default is ``fixit/rules/new.py``\n", | |
"- ``--name`` is used to assign the name of the rule and should be in snake case, Default is name of the rule file if ``path`` provided else `new`. Otherwise, considers the value specified in ``--name``\n", | |
"- ``--path`` is used to create rule file at path given in ``--path``, defaults to ``fixit/rules/new.py``\n", | |
"- ``--name`` is used to assign the name of the rule and should be in snake case, defaults to the rule file name if ``path`` provided else `new`. Otherwise, considers the value specified in ``--name``\n", |
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.
done
fixit/cli/add_new_rule.py
Outdated
"--name", | ||
type=str, | ||
default="", | ||
help="Name of the rule, Default is New", |
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.
help="Name of the rule, Default is New", | |
help="Name of the rule, defaults to `New`", |
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.
done
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.
Other than comments, LGTM.
Thanks for contributing!
b4ada29
to
3772a2f
Compare
Summary
Refer #119
--name
argument to fixit's add_new_rule CLIpython -m fixit.cli.add_new_rule --path fixit/rules/my_rule.py --name abcd
--file
=fixit/rules/my_rule.py
--name
=abcd
The file will be created at
fixit/rules/my_rule.py
with class nameabcd
asAbcdRule
snake_to_camelcase
function tofixit/cli/utils.py
docs/source/build_a_lint_rule.ipynb
Test Plan