diff --git a/README.md b/README.md index 8c7657f3..742ae9cf 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,8 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `django_south_ghost` – adds `--delete-ghost-migrations` to failed because ghosts django south migration; * `django_south_merge` – adds `--merge` to inconsistent django south migration; * `fix_alt_space` – replaces Alt+Space with Space character; -* `javac` – appends missing `.java` when compiling Java files +* `javac` – appends missing `.java` when compiling Java files; +* `java` – removes `.java` extension when running Java programs; * `git_add` – fix *"Did you forget to 'git add'?"*; * `git_checkout` – creates the branch before checking-out; * `git_no_command` – fixes wrong git commands like `git brnch`; diff --git a/tests/rules/test_java.py b/tests/rules/test_java.py new file mode 100644 index 00000000..d51c8806 --- /dev/null +++ b/tests/rules/test_java.py @@ -0,0 +1,17 @@ +import pytest +from thefuck.rules.java import match, get_new_command +from tests.utils import Command + + +@pytest.mark.parametrize('command', [ + Command(script='java foo.java'), + Command(script='java bar.java')]) +def test_match(command): + assert match(command, None) + + +@pytest.mark.parametrize('command, new_command', [ + (Command('java foo.java'), 'java foo'), + (Command('java bar.java'), 'java bar')]) +def test_get_new_command(command, new_command): + assert get_new_command(command, None) == new_command diff --git a/thefuck/rules/java.py b/thefuck/rules/java.py new file mode 100644 index 00000000..31474e80 --- /dev/null +++ b/thefuck/rules/java.py @@ -0,0 +1,13 @@ +# Fixes common java command mistake +# +# Example: +# > java foo.java +# Error: Could not find or load main class foo.java +# + +def match(command, settings): + return (command.script.startswith ('java ') + and command.script.endswith ('.java')) + +def get_new_command(command, settings): + return command.script[:-5]