diff --git a/README.md b/README.md index ece6d663..27f859a3 100644 --- a/README.md +++ b/README.md @@ -179,6 +179,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `open` – prepends `http` to address passed to `open`; * `pip_unknown_command` – fixes wrong pip commands, for example `pip instatl/pip install`; * `python_command` – prepends `python` when you trying to run not executable/without `./` python script; +* `quotation_marks` – fixes uneven usage of `'` and `"` when containing args' * `rm_dir` – adds `-rf` when you trying to remove directory; * `sl_ls` – changes `sl` to `ls`; * `ssh_known_hosts` – removes host from `known_hosts` on warning; diff --git a/tests/rules/test_quotation_marks.py b/tests/rules/test_quotation_marks.py new file mode 100644 index 00000000..2963ac77 --- /dev/null +++ b/tests/rules/test_quotation_marks.py @@ -0,0 +1,19 @@ +import pytest +from thefuck.rules.quotation_marks import match, get_new_command +from tests.utils import Command + + +@pytest.mark.parametrize('command', [ + Command(script="git commit -m \'My Message\""), + Command(script="git commit -am \"Mismatched Quotation Marks\'"), + Command(script="echo \"hello\'")]) +def test_match(command): + assert match(command, None) + + +@pytest.mark.parametrize('command, new_command', [ + (Command("git commit -m \'My Message\""), "git commit -m \"My Message\""), + (Command("git commit -am \"Mismatched Quotation Marks\'"), "git commit -am \"Mismatched Quotation Marks\""), + (Command("echo \"hello\'"), "echo \"hello\"")]) +def test_get_new_command(command, new_command): + assert get_new_command(command, None) == new_command diff --git a/thefuck/rules/quotation_marks.py b/thefuck/rules/quotation_marks.py new file mode 100644 index 00000000..75e99dd1 --- /dev/null +++ b/thefuck/rules/quotation_marks.py @@ -0,0 +1,14 @@ +# Fixes careless " and ' usage +# +# Example: +# > git commit -m 'My Message" +# +# +# + +def match(command, settings): + return ('\'' in command.script + and '\"' in command.script) + +def get_new_command(command, settings): + return command.script.replace ('\'', '\"')