From 7f0f9a966f51a807c921d0edacc2ae597516fbae Mon Sep 17 00:00:00 2001 From: mcarton Date: Mon, 17 Aug 2015 13:44:15 +0200 Subject: [PATCH] Fix some pep8 issues, mostly spaces Before: 4 E101 indentation contains mixed spaces and tabs 20 E122 continuation line missing indentation or outdented 1 E124 closing bracket does not match visual indentation 12 E127 continuation line over-indented for visual indent 22 E128 continuation line under-indented for visual indent 2 E211 whitespace before '(' 12 E302 expected 2 blank lines, found 1 1 E303 too many blank lines (3) 4 E402 module level import not at top of file 123 E501 line too long (81 > 79 characters) 2 E731 do not assign a lambda expression, use a def 3 W191 indentation contains tabs 20 W291 trailing whitespace 3 W293 blank line contains whitespace 2 W391 blank line at end of file 69 W503 line break before binary operator After: 20 E122 continuation line missing indentation or outdented 12 E127 continuation line over-indented for visual indent 22 E128 continuation line under-indented for visual indent 123 E501 line too long (81 > 79 characters) 2 E731 do not assign a lambda expression, use a def 1 W291 trailing whitespace 68 W503 line break before binary operator --- tests/rules/test_composer_not_command.py | 52 +++++++++++++----------- tests/rules/test_dirty_untar.py | 1 + tests/rules/test_fix_file.py | 3 +- tests/rules/test_git_branch_list.py | 1 + tests/rules/test_git_fix_stash.py | 2 +- tests/rules/test_git_not_command.py | 4 +- tests/rules/test_go_run.py | 2 +- tests/rules/test_systemctl.py | 2 +- thefuck/rules/brew_upgrade.py | 8 ++-- thefuck/rules/cd_correction.py | 9 ++-- thefuck/rules/cd_parent.py | 2 + thefuck/rules/go_run.py | 8 ++-- thefuck/rules/has_exists_script.py | 1 - thefuck/rules/history.py | 1 + thefuck/rules/javac.py | 2 +- thefuck/rules/quotation_marks.py | 12 +++--- thefuck/rules/tsuru_not_command.py | 1 - 17 files changed, 57 insertions(+), 54 deletions(-) diff --git a/tests/rules/test_composer_not_command.py b/tests/rules/test_composer_not_command.py index 15e630d3..9ffdd004 100644 --- a/tests/rules/test_composer_not_command.py +++ b/tests/rules/test_composer_not_command.py @@ -5,34 +5,38 @@ from tests.utils import Command @pytest.fixture def composer_not_command(): - return """ - - - [InvalidArgumentException] - Command "udpate" is not defined. - Did you mean this? - update - - -""" + # that weird spacing is part of the actual command output + return ( + '\n' + '\n' + ' \n' + ' [InvalidArgumentException] \n' + ' Command "udpate" is not defined. \n' + ' Did you mean this? \n' + ' update \n' + ' \n' + '\n' + '\n' + ) @pytest.fixture def composer_not_command_one_of_this(): - return """ - - - - [InvalidArgumentException] - Command "pdate" is not defined. - Did you mean one of these? - selfupdate - self-update - update - - - -""" + # that weird spacing is part of the actual command output + return ( + '\n' + '\n' + ' \n' + ' [InvalidArgumentException] \n' + ' Command "pdate" is not defined. \n' + ' Did you mean one of these? \n' + ' selfupdate \n' + ' self-update \n' + ' update \n' + ' \n' + '\n' + '\n' + ) def test_match(composer_not_command, composer_not_command_one_of_this): diff --git a/tests/rules/test_dirty_untar.py b/tests/rules/test_dirty_untar.py index 77d125d2..63bb0edc 100644 --- a/tests/rules/test_dirty_untar.py +++ b/tests/rules/test_dirty_untar.py @@ -40,6 +40,7 @@ parametrize_script = pytest.mark.parametrize('script, fixed', [ ('tar -xvf {}', 'mkdir -p foo && tar -xvf {} -C foo'), ('tar --extract -f {}', 'mkdir -p foo && tar --extract -f {} -C foo')]) + @parametrize_filename @parametrize_script def test_match(tar_error, filename, script, fixed): diff --git a/tests/rules/test_fix_file.py b/tests/rules/test_fix_file.py index 83ac2738..bdbdebee 100644 --- a/tests/rules/test_fix_file.py +++ b/tests/rules/test_fix_file.py @@ -85,8 +85,7 @@ Traceback (most recent call last): File "/usr/lib/python3.4/re.py", line 293, in _compile raise TypeError("first argument must be string or compiled pattern") TypeError: first argument must be string or compiled pattern -""" -), +"""), ('ruby a.rb', 'a.rb', 3, None, """ diff --git a/tests/rules/test_git_branch_list.py b/tests/rules/test_git_branch_list.py index e1d1f23f..4d77e1a4 100644 --- a/tests/rules/test_git_branch_list.py +++ b/tests/rules/test_git_branch_list.py @@ -2,6 +2,7 @@ from thefuck import shells from thefuck.rules.git_branch_list import match, get_new_command from tests.utils import Command + def test_match(): assert match(Command('git branch list'), None) diff --git a/tests/rules/test_git_fix_stash.py b/tests/rules/test_git_fix_stash.py index c9f65b64..6eac71d9 100644 --- a/tests/rules/test_git_fix_stash.py +++ b/tests/rules/test_git_fix_stash.py @@ -10,7 +10,7 @@ usage: git stash list [] or: git stash ( pop | apply ) [--index] [-q|--quiet] [] or: git stash branch [] or: git stash [save [--patch] [-k|--[no-]keep-index] [-q|--quiet] - [-u|--include-untracked] [-a|--all] []] +\t\t [-u|--include-untracked] [-a|--all] []] or: git stash clear ''' diff --git a/tests/rules/test_git_not_command.py b/tests/rules/test_git_not_command.py index 0bff9803..80aa5c92 100644 --- a/tests/rules/test_git_not_command.py +++ b/tests/rules/test_git_not_command.py @@ -30,8 +30,8 @@ def git_not_command_closest(): return '''git: 'tags' is not a git command. See 'git --help'. Did you mean one of these? - stage - tag +\tstage +\ttag ''' diff --git a/tests/rules/test_go_run.py b/tests/rules/test_go_run.py index 0ab140b4..9b5baf6f 100644 --- a/tests/rules/test_go_run.py +++ b/tests/rules/test_go_run.py @@ -4,7 +4,7 @@ from tests.utils import Command @pytest.mark.parametrize('command', [ - Command(script='go run foo'), + Command(script='go run foo'), Command(script='go run bar')]) def test_match(command): assert match(command, None) diff --git a/tests/rules/test_systemctl.py b/tests/rules/test_systemctl.py index 8c8901e8..89619d84 100644 --- a/tests/rules/test_systemctl.py +++ b/tests/rules/test_systemctl.py @@ -3,7 +3,6 @@ from thefuck.rules.systemctl import match, get_new_command from tests.utils import Command - def test_match(): assert match(Command('systemctl nginx start', stderr='Unknown operation \'nginx\'.'), None) assert match(Command('sudo systemctl nginx start', stderr='Unknown operation \'nginx\'.'), None) @@ -13,6 +12,7 @@ def test_match(): assert not match(Command('systemctl nginx', stderr='Unknown operation \'nginx\'.'), None) assert not match(Command('systemctl start wtf', stderr='Failed to start wtf.service: Unit wtf.service failed to load: No such file or directory.'), None) + def test_get_new_command(): assert get_new_command(Command('systemctl nginx start'), None) == "systemctl start nginx" assert get_new_command(Command('sudo systemctl nginx start'), None) == "sudo systemctl start nginx" diff --git a/thefuck/rules/brew_upgrade.py b/thefuck/rules/brew_upgrade.py index 2edfaa80..2022088c 100644 --- a/thefuck/rules/brew_upgrade.py +++ b/thefuck/rules/brew_upgrade.py @@ -1,14 +1,14 @@ # Appends --all to the brew upgrade command -# +# # Example: # > brew upgrade # Warning: brew upgrade with no arguments will change behaviour soon! # It currently upgrades all formula but this will soon change to require '--all'. -# -# + def match(command, settings): - return (command.script == 'brew upgrade') + return command.script == 'brew upgrade' + def get_new_command(command, settings): return command.script + ' --all' diff --git a/thefuck/rules/cd_correction.py b/thefuck/rules/cd_correction.py index 9be10237..81c5ef7c 100644 --- a/thefuck/rules/cd_correction.py +++ b/thefuck/rules/cd_correction.py @@ -1,6 +1,3 @@ -#!/usr/bin/env python -__author__ = "mmussomele" - """Attempts to spellcheck and correct failed cd commands""" import os @@ -8,6 +5,8 @@ from difflib import get_close_matches from thefuck.utils import sudo_support from thefuck.rules import cd_mkdir +__author__ = "mmussomele" + MAX_ALLOWED_DIFF = 0.6 @@ -28,8 +27,8 @@ def match(command, settings): def get_new_command(command, settings): """ Attempt to rebuild the path string by spellchecking the directories. - If it fails (i.e. no directories are a close enough match), then it - defaults to the rules of cd_mkdir. + If it fails (i.e. no directories are a close enough match), then it + defaults to the rules of cd_mkdir. Change sensitivity by changing MAX_ALLOWED_DIFF. Default value is 0.6 """ dest = command.script.split()[1].split(os.sep) diff --git a/thefuck/rules/cd_parent.py b/thefuck/rules/cd_parent.py index fdeb6920..7b1faedb 100644 --- a/thefuck/rules/cd_parent.py +++ b/thefuck/rules/cd_parent.py @@ -7,8 +7,10 @@ # > cd.. # cd..: command not found + def match(command, settings): return command.script == 'cd..' + def get_new_command(command, settings): return 'cd ..' diff --git a/thefuck/rules/go_run.py b/thefuck/rules/go_run.py index 79eedc50..b32c646a 100644 --- a/thefuck/rules/go_run.py +++ b/thefuck/rules/go_run.py @@ -1,14 +1,14 @@ # Appends .go when compiling go files -# +# # Example: # > go run foo # error: go run: no go files listed -# -# + def match(command, settings): - return (command.script.startswith ('go run ') + return (command.script.startswith('go run ') and not command.script.endswith('.go')) + def get_new_command(command, settings): return command.script + '.go' diff --git a/thefuck/rules/has_exists_script.py b/thefuck/rules/has_exists_script.py index 19a7e48c..57a12fd5 100644 --- a/thefuck/rules/has_exists_script.py +++ b/thefuck/rules/has_exists_script.py @@ -11,4 +11,3 @@ def match(command, settings): @sudo_support def get_new_command(command, settings): return u'./{}'.format(command.script) - diff --git a/thefuck/rules/history.py b/thefuck/rules/history.py index c02f522c..1fd011b0 100644 --- a/thefuck/rules/history.py +++ b/thefuck/rules/history.py @@ -23,6 +23,7 @@ def _history_of_exists_without_current(command): if not line.startswith(tf_alias) and not line == command.script and line.split(' ')[0] in executables] + def match(command, settings): return len(get_close_matches(command.script, _history_of_exists_without_current(command))) diff --git a/thefuck/rules/javac.py b/thefuck/rules/javac.py index af19cc71..80e6b258 100644 --- a/thefuck/rules/javac.py +++ b/thefuck/rules/javac.py @@ -4,7 +4,7 @@ # > javac foo # error: Class names, 'foo', are only accepted if annotation # processing is explicitly requested - + def match(command, settings): return (command.script.startswith('javac ') diff --git a/thefuck/rules/quotation_marks.py b/thefuck/rules/quotation_marks.py index 75e99dd1..c6d5e27a 100644 --- a/thefuck/rules/quotation_marks.py +++ b/thefuck/rules/quotation_marks.py @@ -1,14 +1,12 @@ # Fixes careless " and ' usage -# +# # Example: # > git commit -m 'My Message" -# -# -# + def match(command, settings): - return ('\'' in command.script - and '\"' in command.script) + return '\'' in command.script and '\"' in command.script + def get_new_command(command, settings): - return command.script.replace ('\'', '\"') + return command.script.replace('\'', '\"') diff --git a/thefuck/rules/tsuru_not_command.py b/thefuck/rules/tsuru_not_command.py index 1115a3ae..e3f1e4cf 100644 --- a/thefuck/rules/tsuru_not_command.py +++ b/thefuck/rules/tsuru_not_command.py @@ -14,4 +14,3 @@ def get_new_command(command, settings): command.stderr)[0] return replace_command(command, broken_cmd, get_all_matched_commands(command.stderr)) -