From e9d29726bc391c5f6beb0d33eae26022bd232402 Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Wed, 5 Oct 2016 11:00:39 -0400 Subject: [PATCH 01/27] Run flake8 using Travis CI --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index d4e591b9..97bc3f50 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,11 +34,13 @@ before_install: - if [[ $TRAVIS_OS_NAME == "osx" ]]; then source venv/bin/activate; fi - pip install -U pip - pip install -U coveralls + - pip install -U flake8 install: - pip install -Ur requirements.txt - python setup.py develop - rm -rf build script: + - flake8 - export COVERAGE_PYTHON_VERSION=python-${TRAVIS_PYTHON_VERSION:0:1} - export RUN_TESTS="coverage run --source=thefuck,tests -m py.test -v --capture=sys tests" - if [[ $TRAVIS_PYTHON_VERSION == 3.5 && $TRAVIS_OS_NAME != "osx" ]]; then $RUN_TESTS --enable-functional; fi From 22b005cebb524b88f014c3c7e8e79a16afe781cf Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Wed, 5 Oct 2016 11:08:02 -0400 Subject: [PATCH 02/27] Fix flake8 errors: E731 do not assign a lambda expression, use a def --- tests/test_utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index c9290894..ac45a7b1 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -18,8 +18,7 @@ from tests.utils import Command def test_default_settings(settings, override, old, new): settings.clear() settings.update(old) - fn = lambda _: _ - default_settings(override)(fn)(None) + default_settings(override)(lambda _: _)(None) assert settings == new From 93302c74b5d73256e439c4556af0780f82f60cb6 Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Wed, 5 Oct 2016 11:12:06 -0400 Subject: [PATCH 03/27] Fix flake8 errors: E101/W191 indentation contains (mixed spaces and) tabs --- tests/rules/test_brew_link.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/rules/test_brew_link.py b/tests/rules/test_brew_link.py index 14b13c7a..5e0f1462 100644 --- a/tests/rules/test_brew_link.py +++ b/tests/rules/test_brew_link.py @@ -6,15 +6,15 @@ from thefuck.rules.brew_link import get_new_command, match @pytest.fixture def stderr(): return ("Error: Could not symlink bin/gcp\n" - "Target /usr/local/bin/gcp\n" - "already exists. You may want to remove it:\n" - "rm '/usr/local/bin/gcp'\n" - "\n" - "To force the link and overwrite all conflicting files:\n" - "brew link --overwrite coreutils\n" - "\n" - "To list all files that would be deleted:\n" - "brew link --overwrite --dry-run coreutils\n") + "Target /usr/local/bin/gcp\n" + "already exists. You may want to remove it:\n" + "rm '/usr/local/bin/gcp'\n" + "\n" + "To force the link and overwrite all conflicting files:\n" + "brew link --overwrite coreutils\n" + "\n" + "To list all files that would be deleted:\n" + "brew link --overwrite --dry-run coreutils\n") @pytest.fixture From 10d409e6e2f3bd2ebdabd38f30045e4c0c2dca01 Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Wed, 5 Oct 2016 11:13:01 -0400 Subject: [PATCH 04/27] Fix flake8 errors: E225 missing whitespace around operator --- tests/rules/test_brew_link.py | 2 +- tests/rules/test_brew_uninstall.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/rules/test_brew_link.py b/tests/rules/test_brew_link.py index 5e0f1462..26f42aff 100644 --- a/tests/rules/test_brew_link.py +++ b/tests/rules/test_brew_link.py @@ -29,7 +29,7 @@ def test_match(stderr, script): @pytest.mark.parametrize('script', ['brew link coreutils']) def test_not_match(script): - stderr='' + stderr = '' assert not match(Command(script=script, stderr=stderr)) diff --git a/tests/rules/test_brew_uninstall.py b/tests/rules/test_brew_uninstall.py index e01ffc1e..cba0d424 100644 --- a/tests/rules/test_brew_uninstall.py +++ b/tests/rules/test_brew_uninstall.py @@ -22,7 +22,7 @@ def test_match(stdout, script): @pytest.mark.parametrize('script', ['brew remove gnuplot']) def test_not_match(script): - stdout='Uninstalling /usr/local/Cellar/gnuplot/5.0.4_1... (44 files, 2.3M)\n' + stdout = 'Uninstalling /usr/local/Cellar/gnuplot/5.0.4_1... (44 files, 2.3M)\n' assert not match(Command(script=script, stdout=stdout)) From 283eb09c192a2dade1db948fef72ade0b7764a9b Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Wed, 5 Oct 2016 11:14:33 -0400 Subject: [PATCH 05/27] Fix flake8 errors: E231 missing whitespace after ',' --- tests/rules/test_fab_command_not_found.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/rules/test_fab_command_not_found.py b/tests/rules/test_fab_command_not_found.py index 361c3742..da596b6b 100644 --- a/tests/rules/test_fab_command_not_found.py +++ b/tests/rules/test_fab_command_not_found.py @@ -45,5 +45,5 @@ def test_not_match(command): 'fab prepare_extension:version=2016 deploy:beta=true -H the.fuck'), ]) def test_get_new_command(script, result): - command = Command(script, stdout,stderr) + command = Command(script, stdout, stderr) assert get_new_command(command) == result From dcc13bd2d2d99868acf6d049518d4ed9f9c45ae0 Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Wed, 5 Oct 2016 11:16:43 -0400 Subject: [PATCH 06/27] Fix flake8 errors: F841, E265 This commented-out test caused a couple flake8 errors, so get rid of it: * F841 local variable 'cmd' is assigned to but never used * E265 block comment should start with '# ' See https://github.com/nvbn/thefuck/pull/563#discussion_r82104360 --- tests/rules/test_fix_file.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/rules/test_fix_file.py b/tests/rules/test_fix_file.py index 30f5fa1d..46de1a2a 100644 --- a/tests/rules/test_fix_file.py +++ b/tests/rules/test_fix_file.py @@ -227,10 +227,6 @@ def test_get_new_command(mocker, monkeypatch, test): mocker.patch('os.path.isfile', return_value=True) monkeypatch.setenv('EDITOR', 'dummy_editor') - cmd = Command(script=test[0], stdout=test[4], stderr=test[5]) - #assert (get_new_command(cmd, Settings({})) == - # 'dummy_editor {} +{} && {}'.format(test[1], test[2], test[0])) - @pytest.mark.parametrize('test', tests) @pytest.mark.usefixtures('no_memoize') From b221b04d0fd63463066453316d024f0b6f61532d Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Wed, 5 Oct 2016 11:18:10 -0400 Subject: [PATCH 07/27] Fix flake8 errors: F811 redefinition of unused... --- tests/rules/test_git_push_pull.py | 14 ++------------ tests/rules/test_ln_s_order.py | 11 +---------- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/tests/rules/test_git_push_pull.py b/tests/rules/test_git_push_pull.py index afa74748..93e41bc2 100644 --- a/tests/rules/test_git_push_pull.py +++ b/tests/rules/test_git_push_pull.py @@ -39,12 +39,7 @@ To /tmp/bar @pytest.mark.parametrize('command', [ Command(script='git push', stderr=git_err), Command(script='git push nvbn', stderr=git_err), - Command(script='git push nvbn master', stderr=git_err)]) -def test_match(command): - assert match(command) - - -@pytest.mark.parametrize('command', [ + Command(script='git push nvbn master', stderr=git_err), Command(script='git push', stderr=git_err2), Command(script='git push nvbn', stderr=git_err2), Command(script='git push nvbn master', stderr=git_err2)]) @@ -68,12 +63,7 @@ def test_not_match(command): (Command(script='git push nvbn', stderr=git_err), 'git pull nvbn && git push nvbn'), (Command(script='git push nvbn master', stderr=git_err), - 'git pull nvbn master && git push nvbn master')]) -def test_get_new_command(command, output): - assert get_new_command(command) == output - - -@pytest.mark.parametrize('command, output', [ + 'git pull nvbn master && git push nvbn master'), (Command(script='git push', stderr=git_err2), 'git pull && git push'), (Command(script='git push nvbn', stderr=git_err2), 'git pull nvbn && git push nvbn'), diff --git a/tests/rules/test_ln_s_order.py b/tests/rules/test_ln_s_order.py index d4119f40..8501b664 100644 --- a/tests/rules/test_ln_s_order.py +++ b/tests/rules/test_ln_s_order.py @@ -11,16 +11,6 @@ def file_exists(mocker): get_stderr = "ln: failed to create symbolic link '{}': File exists".format -@pytest.mark.usefixtures('file_exists') -@pytest.mark.parametrize('script', [ - 'ln -s dest source', - 'ln dest -s source', - 'ln dest source -s']) -def test_match(script): - stderr = get_stderr('source') - assert match(Command(script, stderr=stderr)) - - @pytest.mark.parametrize('script, stderr, exists', [ ('ln dest source', get_stderr('source'), True), ('ls -s dest source', get_stderr('source'), True), @@ -38,4 +28,5 @@ def test_not_match(file_exists, script, stderr, exists): ('ln dest source -s', 'ln source -s dest')]) def test_match(script, result): stderr = get_stderr('source') + assert match(Command(script, stderr=stderr)) assert get_new_command(Command(script, stderr=stderr)) == result From 37161832aab8ecb611f9a80e1b58fc57866cdc14 Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Wed, 5 Oct 2016 11:20:21 -0400 Subject: [PATCH 08/27] Fix flake8 errors: E123 closing bracket does not match indentation of opening bracket's line --- tests/rules/test_git_remote_seturl_add.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/rules/test_git_remote_seturl_add.py b/tests/rules/test_git_remote_seturl_add.py index 8b8667e5..8679fca7 100644 --- a/tests/rules/test_git_remote_seturl_add.py +++ b/tests/rules/test_git_remote_seturl_add.py @@ -14,8 +14,7 @@ def test_match(command): Command('git remote add origin url'), Command('git remote remove origin'), Command('git remote prune origin'), - Command('git remote set-branches origin branch') - ]) + Command('git remote set-branches origin branch')]) def test_not_match(command): assert not match(command) From 797b42cfd752d4ce43fdce616280710478420197 Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Wed, 5 Oct 2016 11:20:42 -0400 Subject: [PATCH 09/27] Fix flake8 errors: E302 expected 2 blank lines, found 1 --- tests/rules/test_git_remote_seturl_add.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/rules/test_git_remote_seturl_add.py b/tests/rules/test_git_remote_seturl_add.py index 8679fca7..011d6207 100644 --- a/tests/rules/test_git_remote_seturl_add.py +++ b/tests/rules/test_git_remote_seturl_add.py @@ -18,6 +18,7 @@ def test_match(command): def test_not_match(command): assert not match(command) + @pytest.mark.parametrize('command, new_command', [ (Command('git remote set-url origin git@github.com:nvbn/thefuck.git'), 'git remote add origin git@github.com:nvbn/thefuck.git')]) From 725605cd20b29e200f6aaa90f29053bc623b0e51 Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Wed, 5 Oct 2016 11:25:37 -0400 Subject: [PATCH 10/27] Fix flake8 errors: E711 comparison to None should be 'if cond is not None:' --- thefuck/rules/unknown_command.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thefuck/rules/unknown_command.py b/thefuck/rules/unknown_command.py index ee7139e2..30a90bc8 100644 --- a/thefuck/rules/unknown_command.py +++ b/thefuck/rules/unknown_command.py @@ -3,8 +3,8 @@ from thefuck.utils import replace_command def match(command): - return (re.search(r"([^:]*): Unknown command.*", command.stderr) != None - and re.search(r"Did you mean ([^?]*)?", command.stderr) != None) + return (re.search(r"([^:]*): Unknown command.*", command.stderr) is not None + and re.search(r"Did you mean ([^?]*)?", command.stderr) is not None) def get_new_command(command): From c4c6f506f401c27a7c9b5f6e3a8068b726211b2d Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Thu, 6 Oct 2016 09:20:12 -0400 Subject: [PATCH 11/27] Ignore flake8 errors with inline comments: E402 module level import not at top of file https://github.com/nvbn/thefuck/pull/563#discussion_r82105200 --- thefuck/main.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/thefuck/main.py b/thefuck/main.py index 6ca89ac2..6896554e 100644 --- a/thefuck/main.py +++ b/thefuck/main.py @@ -3,16 +3,16 @@ from .system import init_output init_output() -from argparse import ArgumentParser -from pprint import pformat -import sys -from . import logs, types -from .shells import shell -from .conf import settings -from .corrector import get_corrected_commands -from .exceptions import EmptyCommand -from .utils import get_installation_info, get_alias -from .ui import select_command +from argparse import ArgumentParser # noqa: E402 +from pprint import pformat # noqa: E402 +import sys # noqa: E402 +from . import logs, types # noqa: E402 +from .shells import shell # noqa: E402 +from .conf import settings # noqa: E402 +from .corrector import get_corrected_commands # noqa: E402 +from .exceptions import EmptyCommand # noqa: E402 +from .utils import get_installation_info, get_alias # noqa: E402 +from .ui import select_command # noqa: E402 def fix_command(): From fb3d8d1e012c0be59e191e68aa461ef0bfb19e8d Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Thu, 6 Oct 2016 13:38:36 -0400 Subject: [PATCH 12/27] Ignore flake8 errors with inline comments: F401,F403 --- thefuck/system/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thefuck/system/__init__.py b/thefuck/system/__init__.py index cc4698ac..bb13c30b 100644 --- a/thefuck/system/__init__.py +++ b/thefuck/system/__init__.py @@ -2,6 +2,6 @@ import sys if sys.platform == 'win32': - from .win32 import * + from .win32 import * # noqa: F401,F403 else: - from .unix import * + from .unix import * # noqa: F401,F403 From 432878bd773319cf034d3070697e8601d4201b6d Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Thu, 6 Oct 2016 13:51:39 -0400 Subject: [PATCH 13/27] Ignore flake8 errors with inline comments: W291 trailing whitespace See https://github.com/PyCQA/pycodestyle/pull/243 --- tests/rules/test_django_south_ghost.py | 2 +- tests/rules/test_mvn_no_command.py | 2 +- tests/rules/test_mvn_unknown_lifecycle_phase.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/rules/test_django_south_ghost.py b/tests/rules/test_django_south_ghost.py index 83656467..bbc83fe5 100644 --- a/tests/rules/test_django_south_ghost.py +++ b/tests/rules/test_django_south_ghost.py @@ -37,7 +37,7 @@ south.exceptions.GhostMigrations: ! I'm not trusting myself; either fix this yourself by fiddling ! with the south_migrationhistory table, or pass --delete-ghost-migrations ! to South to have it delete ALL of these records (this may not be good). -''' +''' # noqa def test_match(stderr): diff --git a/tests/rules/test_mvn_no_command.py b/tests/rules/test_mvn_no_command.py index 1871716c..7e729457 100644 --- a/tests/rules/test_mvn_no_command.py +++ b/tests/rules/test_mvn_no_command.py @@ -25,7 +25,7 @@ def test_match(command): [INFO] Finished at: Wed Aug 26 13:05:47 BST 2015 [INFO] Final Memory: 6M/240M [INFO] ------------------------------------------------------------------------ -"""), +"""), # noqa Command(script='mvn --help'), Command(script='mvn -v') ]) diff --git a/tests/rules/test_mvn_unknown_lifecycle_phase.py b/tests/rules/test_mvn_unknown_lifecycle_phase.py index c4b4b7a5..b880fd20 100644 --- a/tests/rules/test_mvn_unknown_lifecycle_phase.py +++ b/tests/rules/test_mvn_unknown_lifecycle_phase.py @@ -25,7 +25,7 @@ def test_match(command): [INFO] Finished at: Wed Aug 26 13:05:47 BST 2015 [INFO] Final Memory: 6M/240M [INFO] ------------------------------------------------------------------------ -"""), +"""), # noqa Command(script='mvn --help'), Command(script='mvn -v') ]) From a9d55e9c62eb7de990c8f118ac71e9065712465f Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Thu, 6 Oct 2016 14:01:26 -0400 Subject: [PATCH 14/27] Fix flake8 errors: E128 continuation line under-indented for visual indent See https://github.com/nvbn/thefuck/pull/563#discussion_r82492221 --- tests/rules/test_fix_file.py | 6 +++--- tests/rules/test_has_exists_script.py | 2 +- tests/rules/test_unknown_command.py | 8 ++++---- tests/rules/test_vagrant_up.py | 4 ++-- thefuck/rules/git_pull_uncommitted_changes.py | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/rules/test_fix_file.py b/tests/rules/test_fix_file.py index 46de1a2a..70921cb8 100644 --- a/tests/rules/test_fix_file.py +++ b/tests/rules/test_fix_file.py @@ -191,7 +191,7 @@ E NameError: name 'mocker' is not defined /home/thefuck/tests/rules/test_fix_file.py:218: NameError """, ''), -) +) # noqa @pytest.mark.parametrize('test', tests) @@ -239,7 +239,7 @@ def test_get_new_command_with_settings(mocker, monkeypatch, test, settings): if test[3]: assert (get_new_command(cmd) == - u'dummy_editor {} +{}:{} && {}'.format(test[1], test[2], test[3], test[0])) + u'dummy_editor {} +{}:{} && {}'.format(test[1], test[2], test[3], test[0])) else: assert (get_new_command(cmd) == - u'dummy_editor {} +{} && {}'.format(test[1], test[2], test[0])) + u'dummy_editor {} +{} && {}'.format(test[1], test[2], test[0])) diff --git a/tests/rules/test_has_exists_script.py b/tests/rules/test_has_exists_script.py index c6b4b1ed..7ddb7b89 100644 --- a/tests/rules/test_has_exists_script.py +++ b/tests/rules/test_has_exists_script.py @@ -7,7 +7,7 @@ def test_match(): with patch('os.path.exists', return_value=True): assert match(Command(script='main', stderr='main: command not found')) assert match(Command(script='main --help', - stderr='main: command not found')) + stderr='main: command not found')) assert not match(Command(script='main', stderr='')) with patch('os.path.exists', return_value=False): diff --git a/tests/rules/test_unknown_command.py b/tests/rules/test_unknown_command.py index 9a2d37e7..7e7f9aa7 100644 --- a/tests/rules/test_unknown_command.py +++ b/tests/rules/test_unknown_command.py @@ -23,12 +23,12 @@ def test_not_match(command): @pytest.mark.parametrize('command, new_command', [ (Command('hdfs dfs ls', - stderr='ls: Unknown command\nDid you mean -ls? This command begins with a dash.'), ['hdfs dfs -ls']), + stderr='ls: Unknown command\nDid you mean -ls? This command begins with a dash.'), ['hdfs dfs -ls']), (Command('hdfs dfs rm /foo/bar', - stderr='rm: Unknown command\nDid you mean -rm? This command begins with a dash.'), ['hdfs dfs -rm /foo/bar']), + stderr='rm: Unknown command\nDid you mean -rm? This command begins with a dash.'), ['hdfs dfs -rm /foo/bar']), (Command('./bin/hdfs dfs ls -R /foo/bar', - stderr='ls: Unknown command\nDid you mean -ls? This command begins with a dash.'), ['./bin/hdfs dfs -ls -R /foo/bar']), + stderr='ls: Unknown command\nDid you mean -ls? This command begins with a dash.'), ['./bin/hdfs dfs -ls -R /foo/bar']), (Command('./bin/hdfs dfs -Dtest=fred ls -R /foo/bar', - stderr='ls: Unknown command\nDid you mean -ls? This command begins with a dash.'), ['./bin/hdfs dfs -Dtest=fred -ls -R /foo/bar'])]) + stderr='ls: Unknown command\nDid you mean -ls? This command begins with a dash.'), ['./bin/hdfs dfs -Dtest=fred -ls -R /foo/bar'])]) def test_get_new_command(command, new_command): assert get_new_command(command) == new_command diff --git a/tests/rules/test_vagrant_up.py b/tests/rules/test_vagrant_up.py index 19d7b335..4319eed6 100644 --- a/tests/rules/test_vagrant_up.py +++ b/tests/rules/test_vagrant_up.py @@ -27,8 +27,8 @@ def test_not_match(command): (Command(script='vagrant ssh', stderr='VM must be running to open SSH connection. Run `vagrant up`\nto start the virtual machine.'), 'vagrant up && vagrant ssh'), (Command(script='vagrant ssh devbox', stderr='VM must be running to open SSH connection. Run `vagrant up`\nto start the virtual machine.'), ['vagrant up devbox && vagrant ssh devbox', 'vagrant up && vagrant ssh devbox']), (Command(script='vagrant rdp', - stderr='VM must be created before running this command. Run `vagrant up` first.'), 'vagrant up && vagrant rdp'), + stderr='VM must be created before running this command. Run `vagrant up` first.'), 'vagrant up && vagrant rdp'), (Command(script='vagrant rdp devbox', - stderr='VM must be created before running this command. Run `vagrant up` first.'), ['vagrant up devbox && vagrant rdp devbox', 'vagrant up && vagrant rdp devbox'])]) + stderr='VM must be created before running this command. Run `vagrant up` first.'), ['vagrant up devbox && vagrant rdp devbox', 'vagrant up && vagrant rdp devbox'])]) def test_get_new_command(command, new_command): assert get_new_command(command) == new_command diff --git a/thefuck/rules/git_pull_uncommitted_changes.py b/thefuck/rules/git_pull_uncommitted_changes.py index 8e9a640d..3a8be31a 100644 --- a/thefuck/rules/git_pull_uncommitted_changes.py +++ b/thefuck/rules/git_pull_uncommitted_changes.py @@ -6,7 +6,7 @@ from thefuck.specific.git import git_support def match(command): return ('pull' in command.script and ('You have unstaged changes' in command.stderr - or 'contains uncommitted changes' in command.stderr)) + or 'contains uncommitted changes' in command.stderr)) @git_support From 1b30c00546479b56d242ab6e95417cb81203cca6 Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Thu, 6 Oct 2016 14:03:15 -0400 Subject: [PATCH 15/27] Fix flake8 errors: E122 continuation line missing indentation or outdented --- thefuck/types.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/thefuck/types.py b/thefuck/types.py index 527cf651..64d8c718 100644 --- a/thefuck/types.py +++ b/thefuck/types.py @@ -171,9 +171,9 @@ class Rule(object): return 'Rule(name={}, match={}, get_new_command={}, ' \ 'enabled_by_default={}, side_effect={}, ' \ 'priority={}, requires_output)'.format( - self.name, self.match, self.get_new_command, - self.enabled_by_default, self.side_effect, - self.priority, self.requires_output) + self.name, self.match, self.get_new_command, + self.enabled_by_default, self.side_effect, + self.priority, self.requires_output) @classmethod def from_path(cls, path): From e0cab4fa1bd7a43253751dc75ba32d199a46707a Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Thu, 6 Oct 2016 14:51:22 -0400 Subject: [PATCH 16/27] Fix flake8 errors: E126 continuation line over-indented for hanging indent --- tests/rules/test_brew_unknown_command.py | 4 ++-- tests/rules/test_composer_not_command.py | 6 ++--- tests/rules/test_dirty_untar.py | 2 +- tests/rules/test_django_south_merge.py | 4 ++-- tests/rules/test_git_not_command.py | 4 ++-- tests/rules/test_git_pull.py | 4 ++-- .../test_git_pull_uncommitted_changes.py | 4 ++-- tests/rules/test_git_pull_unstaged_changes.py | 4 ++-- tests/rules/test_git_stash.py | 10 ++++----- tests/rules/test_lein_not_task.py | 4 ++-- tests/rules/test_python_command.py | 4 ++-- tests/rules/test_rm_root.py | 4 ++-- tests/rules/test_sed_unterminated_s.py | 16 +++++++------- tests/test_types.py | 8 +++---- thefuck/main.py | 9 ++++---- thefuck/rules/brew_unknown_command.py | 4 ++-- thefuck/rules/dirty_unzip.py | 2 +- thefuck/rules/workon_doesnt_exists.py | 4 ++-- thefuck/shells/tcsh.py | 6 ++--- thefuck/types.py | 22 +++++++++---------- 20 files changed, 62 insertions(+), 63 deletions(-) diff --git a/tests/rules/test_brew_unknown_command.py b/tests/rules/test_brew_unknown_command.py index 45e02f67..2185b867 100644 --- a/tests/rules/test_brew_unknown_command.py +++ b/tests/rules/test_brew_unknown_command.py @@ -21,8 +21,8 @@ def test_match(brew_unknown_cmd): def test_get_new_command(brew_unknown_cmd, brew_unknown_cmd2): - assert get_new_command(Command('brew inst', stderr=brew_unknown_cmd)) \ - == ['brew list', 'brew install', 'brew uninstall'] + assert (get_new_command(Command('brew inst', stderr=brew_unknown_cmd)) + == ['brew list', 'brew install', 'brew uninstall']) cmds = get_new_command(Command('brew instaa', stderr=brew_unknown_cmd2)) assert 'brew install' in cmds diff --git a/tests/rules/test_composer_not_command.py b/tests/rules/test_composer_not_command.py index c4e4a5a4..bb0a45dc 100644 --- a/tests/rules/test_composer_not_command.py +++ b/tests/rules/test_composer_not_command.py @@ -48,9 +48,9 @@ def test_match(composer_not_command, composer_not_command_one_of_this): def test_get_new_command(composer_not_command, composer_not_command_one_of_this): - assert get_new_command(Command('composer udpate', - stderr=composer_not_command)) \ - == 'composer update' + assert (get_new_command(Command('composer udpate', + stderr=composer_not_command)) + == 'composer update') assert get_new_command( Command('composer pdate', stderr=composer_not_command_one_of_this)) \ == 'composer selfupdate' diff --git a/tests/rules/test_dirty_untar.py b/tests/rules/test_dirty_untar.py index b33a8900..01ff6927 100644 --- a/tests/rules/test_dirty_untar.py +++ b/tests/rules/test_dirty_untar.py @@ -2,7 +2,7 @@ import os import pytest import tarfile from thefuck.rules.dirty_untar import match, get_new_command, side_effect, \ - tar_extensions + tar_extensions # noqa: E126 from tests.utils import Command diff --git a/tests/rules/test_django_south_merge.py b/tests/rules/test_django_south_merge.py index 13f7dbaf..581a1cf3 100644 --- a/tests/rules/test_django_south_merge.py +++ b/tests/rules/test_django_south_merge.py @@ -39,5 +39,5 @@ def test_match(stderr): def test_get_new_command(): - assert get_new_command(Command('./manage.py migrate auth')) \ - == './manage.py migrate auth --merge' + assert (get_new_command(Command('./manage.py migrate auth')) + == './manage.py migrate auth --merge') diff --git a/tests/rules/test_git_not_command.py b/tests/rules/test_git_not_command.py index 6257767e..a65e3a3d 100644 --- a/tests/rules/test_git_not_command.py +++ b/tests/rules/test_git_not_command.py @@ -49,8 +49,8 @@ def test_match(git_not_command, git_command, git_not_command_one_of_this): def test_get_new_command(git_not_command, git_not_command_one_of_this, git_not_command_closest): - assert get_new_command(Command('git brnch', stderr=git_not_command)) \ - == ['git branch'] + assert (get_new_command(Command('git brnch', stderr=git_not_command)) + == ['git branch']) assert get_new_command(Command('git st', stderr=git_not_command_one_of_this)) \ == ['git stats', 'git stash', 'git stage'] assert get_new_command(Command('git tags', stderr=git_not_command_closest)) \ diff --git a/tests/rules/test_git_pull.py b/tests/rules/test_git_pull.py index 11c50171..d24e400c 100644 --- a/tests/rules/test_git_pull.py +++ b/tests/rules/test_git_pull.py @@ -25,5 +25,5 @@ def test_match(stderr): def test_get_new_command(stderr): - assert get_new_command(Command('git pull', stderr=stderr)) \ - == "git branch --set-upstream-to=origin/master master && git pull" + assert (get_new_command(Command('git pull', stderr=stderr)) + == "git branch --set-upstream-to=origin/master master && git pull") diff --git a/tests/rules/test_git_pull_uncommitted_changes.py b/tests/rules/test_git_pull_uncommitted_changes.py index 480b31d8..e32a7370 100644 --- a/tests/rules/test_git_pull_uncommitted_changes.py +++ b/tests/rules/test_git_pull_uncommitted_changes.py @@ -15,5 +15,5 @@ def test_match(stderr): def test_get_new_command(stderr): - assert get_new_command(Command('git pull', stderr=stderr)) \ - == "git stash && git pull && git stash pop" + assert (get_new_command(Command('git pull', stderr=stderr)) + == "git stash && git pull && git stash pop") diff --git a/tests/rules/test_git_pull_unstaged_changes.py b/tests/rules/test_git_pull_unstaged_changes.py index a8cbb4c3..ef3d94ea 100644 --- a/tests/rules/test_git_pull_unstaged_changes.py +++ b/tests/rules/test_git_pull_unstaged_changes.py @@ -15,5 +15,5 @@ def test_match(stderr): def test_get_new_command(stderr): - assert get_new_command(Command('git pull', stderr=stderr)) \ - == "git stash && git pull && git stash pop" + assert (get_new_command(Command('git pull', stderr=stderr)) + == "git stash && git pull && git stash pop") diff --git a/tests/rules/test_git_stash.py b/tests/rules/test_git_stash.py index da9aded7..53cdce42 100644 --- a/tests/rules/test_git_stash.py +++ b/tests/rules/test_git_stash.py @@ -4,14 +4,14 @@ from tests.utils import Command cherry_pick_error = ( - 'error: Your local changes would be overwritten by cherry-pick.\n' - 'hint: Commit your changes or stash them to proceed.\n' - 'fatal: cherry-pick failed') + 'error: Your local changes would be overwritten by cherry-pick.\n' + 'hint: Commit your changes or stash them to proceed.\n' + 'fatal: cherry-pick failed') rebase_error = ( - 'Cannot rebase: Your index contains uncommitted changes.\n' - 'Please commit or stash them.') + 'Cannot rebase: Your index contains uncommitted changes.\n' + 'Please commit or stash them.') @pytest.mark.parametrize('command', [ diff --git a/tests/rules/test_lein_not_task.py b/tests/rules/test_lein_not_task.py index b4fc4498..8b3420c2 100644 --- a/tests/rules/test_lein_not_task.py +++ b/tests/rules/test_lein_not_task.py @@ -19,5 +19,5 @@ def test_match(is_not_task): def test_get_new_command(is_not_task): - assert get_new_command(Command(script='lein rpl --help', stderr=is_not_task)) \ - == ['lein repl --help', 'lein jar --help'] + assert (get_new_command(Command(script='lein rpl --help', stderr=is_not_task)) + == ['lein repl --help', 'lein jar --help']) diff --git a/tests/rules/test_python_command.py b/tests/rules/test_python_command.py index 053457da..234d2e54 100644 --- a/tests/rules/test_python_command.py +++ b/tests/rules/test_python_command.py @@ -8,5 +8,5 @@ def test_match(): def test_get_new_command(): - assert get_new_command(Command('./test_sudo.py'))\ - == 'python ./test_sudo.py' + assert (get_new_command(Command('./test_sudo.py')) + == 'python ./test_sudo.py') diff --git a/tests/rules/test_rm_root.py b/tests/rules/test_rm_root.py index 47c243f8..fe419904 100644 --- a/tests/rules/test_rm_root.py +++ b/tests/rules/test_rm_root.py @@ -17,5 +17,5 @@ def test_not_match(command): def test_get_new_command(): - assert get_new_command(Command(script='rm -rf /')) \ - == 'rm -rf / --no-preserve-root' + assert (get_new_command(Command(script='rm -rf /')) + == 'rm -rf / --no-preserve-root') diff --git a/tests/rules/test_sed_unterminated_s.py b/tests/rules/test_sed_unterminated_s.py index 0c890efd..7b2bf78d 100644 --- a/tests/rules/test_sed_unterminated_s.py +++ b/tests/rules/test_sed_unterminated_s.py @@ -18,11 +18,11 @@ def test_match(sed_unterminated_s): def test_get_new_command(sed_unterminated_s): - assert get_new_command(Command('sed -e s/foo/bar', stderr=sed_unterminated_s)) \ - == 'sed -e s/foo/bar/' - assert get_new_command(Command('sed -es/foo/bar', stderr=sed_unterminated_s)) \ - == 'sed -es/foo/bar/' - assert get_new_command(Command(r"sed -e 's/\/foo/bar'", stderr=sed_unterminated_s)) \ - == r"sed -e 's/\/foo/bar/'" - assert get_new_command(Command(r"sed -e s/foo/bar -es/baz/quz", stderr=sed_unterminated_s)) \ - == r"sed -e s/foo/bar/ -es/baz/quz/" + assert (get_new_command(Command('sed -e s/foo/bar', stderr=sed_unterminated_s)) + == 'sed -e s/foo/bar/') + assert (get_new_command(Command('sed -es/foo/bar', stderr=sed_unterminated_s)) + == 'sed -es/foo/bar/') + assert (get_new_command(Command(r"sed -e 's/\/foo/bar'", stderr=sed_unterminated_s)) + == r"sed -e 's/\/foo/bar/'") + assert (get_new_command(Command(r"sed -e s/foo/bar -es/baz/quz", stderr=sed_unterminated_s)) + == r"sed -e s/foo/bar/ -es/baz/quz/") diff --git a/tests/test_types.py b/tests/test_types.py index 9cb951ba..d23ed85c 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -13,10 +13,10 @@ from thefuck.system import Path class TestCorrectedCommand(object): def test_equality(self): - assert CorrectedCommand('ls', None, 100) == \ - CorrectedCommand('ls', None, 200) - assert CorrectedCommand('ls', None, 100) != \ - CorrectedCommand('ls', lambda *_: _, 100) + assert (CorrectedCommand('ls', None, 100) == + CorrectedCommand('ls', None, 200)) + assert (CorrectedCommand('ls', None, 100) != + CorrectedCommand('ls', lambda *_: _, 100)) def test_hashable(self): assert {CorrectedCommand('ls', None, 100), diff --git a/thefuck/main.py b/thefuck/main.py index 6896554e..5fa9e7c0 100644 --- a/thefuck/main.py +++ b/thefuck/main.py @@ -59,11 +59,10 @@ def how_to_configure_alias(): def main(): parser = ArgumentParser(prog='thefuck') version = get_installation_info().version - parser.add_argument( - '-v', '--version', - action='version', - version='The Fuck {} using Python {}'.format( - version, sys.version.split()[0])) + parser.add_argument('-v', '--version', + action='version', + version='The Fuck {} using Python {}'.format( + version, sys.version.split()[0])) parser.add_argument('-a', '--alias', action='store_true', help='[custom-alias-name] prints alias for current shell') diff --git a/thefuck/rules/brew_unknown_command.py b/thefuck/rules/brew_unknown_command.py index 35f6e937..1d8186e6 100644 --- a/thefuck/rules/brew_unknown_command.py +++ b/thefuck/rules/brew_unknown_command.py @@ -54,8 +54,8 @@ def _brew_commands(): brew_path_prefix = get_brew_path_prefix() if brew_path_prefix: try: - return _get_brew_commands(brew_path_prefix) \ - + _get_brew_tap_specific_commands(brew_path_prefix) + return (_get_brew_commands(brew_path_prefix) + + _get_brew_tap_specific_commands(brew_path_prefix)) except OSError: pass diff --git a/thefuck/rules/dirty_unzip.py b/thefuck/rules/dirty_unzip.py index 23878f5f..3f74ef14 100644 --- a/thefuck/rules/dirty_unzip.py +++ b/thefuck/rules/dirty_unzip.py @@ -39,7 +39,7 @@ def match(command): def get_new_command(command): return u'{} -d {}'.format( - command.script, shell.quote(_zip_file(command)[:-4])) + command.script, shell.quote(_zip_file(command)[:-4])) def side_effect(old_cmd, command): diff --git a/thefuck/rules/workon_doesnt_exists.py b/thefuck/rules/workon_doesnt_exists.py index 6c97ce49..41d17c07 100644 --- a/thefuck/rules/workon_doesnt_exists.py +++ b/thefuck/rules/workon_doesnt_exists.py @@ -26,7 +26,7 @@ def get_new_command(command): available = _get_all_environments() if available: - return replace_command(command, misspelled_env, available) \ - + [create_new] + return (replace_command(command, misspelled_env, available) + + [create_new]) else: return create_new diff --git a/thefuck/shells/tcsh.py b/thefuck/shells/tcsh.py index 6c355caa..3f5bc004 100644 --- a/thefuck/shells/tcsh.py +++ b/thefuck/shells/tcsh.py @@ -19,9 +19,9 @@ class Tcsh(Generic): def get_aliases(self): proc = Popen(['tcsh', '-ic', 'alias'], stdout=PIPE, stderr=DEVNULL) return dict( - self._parse_alias(alias) - for alias in proc.stdout.read().decode('utf-8').split('\n') - if alias and '\t' in alias) + self._parse_alias(alias) + for alias in proc.stdout.read().decode('utf-8').split('\n') + if alias and '\t' in alias) def _get_history_file_name(self): return os.environ.get("HISTFILE", diff --git a/thefuck/types.py b/thefuck/types.py index 64d8c718..a66f3df8 100644 --- a/thefuck/types.py +++ b/thefuck/types.py @@ -39,8 +39,8 @@ class Command(object): def __eq__(self, other): if isinstance(other, Command): - return (self.script, self.stdout, self.stderr) \ - == (other.script, other.stdout, other.stderr) + return ((self.script, self.stdout, self.stderr) + == (other.script, other.stdout, other.stderr)) else: return False @@ -158,12 +158,12 @@ class Rule(object): def __eq__(self, other): if isinstance(other, Rule): - return (self.name, self.match, self.get_new_command, - self.enabled_by_default, self.side_effect, - self.priority, self.requires_output) \ - == (other.name, other.match, other.get_new_command, - other.enabled_by_default, other.side_effect, - other.priority, other.requires_output) + return ((self.name, self.match, self.get_new_command, + self.enabled_by_default, self.side_effect, + self.priority, self.requires_output) + == (other.name, other.match, other.get_new_command, + other.enabled_by_default, other.side_effect, + other.priority, other.requires_output)) else: return False @@ -171,9 +171,9 @@ class Rule(object): return 'Rule(name={}, match={}, get_new_command={}, ' \ 'enabled_by_default={}, side_effect={}, ' \ 'priority={}, requires_output)'.format( - self.name, self.match, self.get_new_command, - self.enabled_by_default, self.side_effect, - self.priority, self.requires_output) + self.name, self.match, self.get_new_command, + self.enabled_by_default, self.side_effect, + self.priority, self.requires_output) @classmethod def from_path(cls, path): From 521eb03d7afa92b6c4e021157bcd3019c5da551f Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Thu, 6 Oct 2016 15:16:43 -0400 Subject: [PATCH 17/27] Fix flake8 errors: E127 continuation line over-indented for visual indent --- tests/rules/test_brew_link.py | 6 +++--- tests/rules/test_composer_not_command.py | 6 +++--- tests/rules/test_fix_alt_space.py | 4 ++-- tests/rules/test_git_not_command.py | 8 ++++---- tests/test_corrector.py | 4 ++-- tests/test_types.py | 14 +++++++------- tests/test_ui.py | 18 +++++++++--------- thefuck/rules/switch_lang.py | 4 ++-- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/tests/rules/test_brew_link.py b/tests/rules/test_brew_link.py index 26f42aff..0586574c 100644 --- a/tests/rules/test_brew_link.py +++ b/tests/rules/test_brew_link.py @@ -8,13 +8,13 @@ def stderr(): return ("Error: Could not symlink bin/gcp\n" "Target /usr/local/bin/gcp\n" "already exists. You may want to remove it:\n" - "rm '/usr/local/bin/gcp'\n" + " rm '/usr/local/bin/gcp'\n" "\n" "To force the link and overwrite all conflicting files:\n" - "brew link --overwrite coreutils\n" + " brew link --overwrite coreutils\n" "\n" "To list all files that would be deleted:\n" - "brew link --overwrite --dry-run coreutils\n") + " brew link --overwrite --dry-run coreutils\n") @pytest.fixture diff --git a/tests/rules/test_composer_not_command.py b/tests/rules/test_composer_not_command.py index bb0a45dc..717ee3ab 100644 --- a/tests/rules/test_composer_not_command.py +++ b/tests/rules/test_composer_not_command.py @@ -51,6 +51,6 @@ def test_get_new_command(composer_not_command, composer_not_command_one_of_this) assert (get_new_command(Command('composer udpate', stderr=composer_not_command)) == 'composer update') - assert get_new_command( - Command('composer pdate', stderr=composer_not_command_one_of_this)) \ - == 'composer selfupdate' + assert (get_new_command(Command('composer pdate', + stderr=composer_not_command_one_of_this)) + == 'composer selfupdate') diff --git a/tests/rules/test_fix_alt_space.py b/tests/rules/test_fix_alt_space.py index c5b03c50..abc0ed1f 100644 --- a/tests/rules/test_fix_alt_space.py +++ b/tests/rules/test_fix_alt_space.py @@ -18,5 +18,5 @@ def test_match(): def test_get_new_command(): """ Replace the Alt+Space character by a simple space """ - assert get_new_command(Command(u'ps -ef | grep foo'))\ - == 'ps -ef | grep foo' + assert (get_new_command(Command(u'ps -ef | grep foo')) + == 'ps -ef | grep foo') diff --git a/tests/rules/test_git_not_command.py b/tests/rules/test_git_not_command.py index a65e3a3d..0c3c06f7 100644 --- a/tests/rules/test_git_not_command.py +++ b/tests/rules/test_git_not_command.py @@ -51,7 +51,7 @@ def test_get_new_command(git_not_command, git_not_command_one_of_this, git_not_command_closest): assert (get_new_command(Command('git brnch', stderr=git_not_command)) == ['git branch']) - assert get_new_command(Command('git st', stderr=git_not_command_one_of_this)) \ - == ['git stats', 'git stash', 'git stage'] - assert get_new_command(Command('git tags', stderr=git_not_command_closest)) \ - == ['git tag', 'git stage'] + assert (get_new_command(Command('git st', stderr=git_not_command_one_of_this)) + == ['git stats', 'git stash', 'git stage']) + assert (get_new_command(Command('git tags', stderr=git_not_command_closest)) + == ['git tag', 'git stage']) diff --git a/tests/test_corrector.py b/tests/test_corrector.py index 08e4160e..39b3c108 100644 --- a/tests/test_corrector.py +++ b/tests/test_corrector.py @@ -47,8 +47,8 @@ def test_get_corrected_commands(mocker): get_new_command=lambda x: [x.script + '@', x.script + ';'], priority=60)] mocker.patch('thefuck.corrector.get_rules', return_value=rules) - assert [cmd.script for cmd in get_corrected_commands(command)] \ - == ['test!', 'test@', 'test;'] + assert ([cmd.script for cmd in get_corrected_commands(command)] + == ['test!', 'test@', 'test;']) def test_organize_commands(): diff --git a/tests/test_types.py b/tests/test_types.py index d23ed85c..4faf8edf 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -41,8 +41,8 @@ class TestRule(object): priority=900, requires_output=True)) rule_path = os.path.join(os.sep, 'rules', 'bash.py') - assert Rule.from_path(Path(rule_path)) \ - == Rule('bash', match, get_new_command, priority=900) + assert (Rule.from_path(Path(rule_path)) + == Rule('bash', match, get_new_command, priority=900)) load_source.assert_called_once_with('bash', rule_path) @pytest.mark.parametrize('rules, exclude_rules, rule, is_enabled', [ @@ -79,15 +79,15 @@ class TestRule(object): def test_get_corrected_commands_with_rule_returns_list(self): rule = Rule(get_new_command=lambda x: [x.script + '!', x.script + '@'], priority=100) - assert list(rule.get_corrected_commands(Command(script='test'))) \ - == [CorrectedCommand(script='test!', priority=100), - CorrectedCommand(script='test@', priority=200)] + assert (list(rule.get_corrected_commands(Command(script='test'))) + == [CorrectedCommand(script='test!', priority=100), + CorrectedCommand(script='test@', priority=200)]) def test_get_corrected_commands_with_rule_returns_command(self): rule = Rule(get_new_command=lambda x: x.script + '!', priority=100) - assert list(rule.get_corrected_commands(Command(script='test'))) \ - == [CorrectedCommand(script='test!', priority=100)] + assert (list(rule.get_corrected_commands(Command(script='test'))) + == [CorrectedCommand(script='test!', priority=100)]) class TestCommand(object): diff --git a/tests/test_ui.py b/tests/test_ui.py index 90efbac2..1c2a9933 100644 --- a/tests/test_ui.py +++ b/tests/test_ui.py @@ -30,11 +30,11 @@ def test_read_actions(patch_get_key): const.KEY_DOWN, 'j', # Ctrl+C: const.KEY_CTRL_C, 'q']) - assert list(islice(ui.read_actions(), 8)) \ - == [const.ACTION_SELECT, const.ACTION_SELECT, - const.ACTION_PREVIOUS, const.ACTION_PREVIOUS, - const.ACTION_NEXT, const.ACTION_NEXT, - const.ACTION_ABORT, const.ACTION_ABORT] + assert (list(islice(ui.read_actions(), 8)) + == [const.ACTION_SELECT, const.ACTION_SELECT, + const.ACTION_PREVIOUS, const.ACTION_PREVIOUS, + const.ACTION_NEXT, const.ACTION_NEXT, + const.ACTION_ABORT, const.ACTION_ABORT]) def test_command_selector(): @@ -74,8 +74,8 @@ class TestSelectCommand(object): def test_without_confirmation_with_side_effects( self, capsys, commands_with_side_effect, settings): settings.require_confirmation = False - assert ui.select_command(iter(commands_with_side_effect)) \ - == commands_with_side_effect[0] + assert (ui.select_command(iter(commands_with_side_effect)) + == commands_with_side_effect[0]) assert capsys.readouterr() == ('', 'ls (+side effect)\n') def test_with_confirmation(self, capsys, patch_get_key, commands): @@ -91,8 +91,8 @@ class TestSelectCommand(object): def test_with_confirmation_with_side_effct(self, capsys, patch_get_key, commands_with_side_effect): patch_get_key(['\n']) - assert ui.select_command(iter(commands_with_side_effect)) \ - == commands_with_side_effect[0] + assert (ui.select_command(iter(commands_with_side_effect)) + == commands_with_side_effect[0]) assert capsys.readouterr() == ('', u'\x1b[1K\rls (+side effect) [enter/↑/↓/ctrl+c]\n') def test_with_confirmation_select_second(self, capsys, patch_get_key, commands): diff --git a/thefuck/rules/switch_lang.py b/thefuck/rules/switch_lang.py index b1abb63d..60e5780c 100644 --- a/thefuck/rules/switch_lang.py +++ b/thefuck/rules/switch_lang.py @@ -33,8 +33,8 @@ def match(command): if 'not found' not in command.stderr: return False matched_layout = _get_matched_layout(command) - return matched_layout and \ - _switch_command(command, matched_layout) != get_alias() + return (matched_layout and + _switch_command(command, matched_layout) != get_alias()) def get_new_command(command): From f0b9c7cb672c2569e4ebbe18be1b2ffb21807ee8 Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Wed, 5 Oct 2016 11:29:32 -0400 Subject: [PATCH 18/27] Ignore remaining flake8 rules and exclude ./venv/ This should fix the builds. --- tox.ini | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tox.ini b/tox.ini index 1d98a69a..09a0d9db 100644 --- a/tox.ini +++ b/tox.ini @@ -4,3 +4,7 @@ envlist = py27,py33,py34,py35 [testenv] deps = -rrequirements.txt commands = py.test -v --capture=sys + +[flake8] +ignore = E501,W503 +exclude = venv From dda9d55989cd6c499624388ba55f900d0f42d892 Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Thu, 6 Oct 2016 15:37:12 -0400 Subject: [PATCH 19/27] Add flake8 instructions to README.md Also add flake8 to requirements.txt so that it will be installed by: pip install -r requirements.txt --- .travis.yml | 1 - README.md | 6 ++++++ requirements.txt | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 97bc3f50..e7b34ee1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,6 @@ before_install: - if [[ $TRAVIS_OS_NAME == "osx" ]]; then source venv/bin/activate; fi - pip install -U pip - pip install -U coveralls - - pip install -U flake8 install: - pip install -Ur requirements.txt - python setup.py develop diff --git a/README.md b/README.md index 07445c32..b002faf5 100644 --- a/README.md +++ b/README.md @@ -370,6 +370,12 @@ pip install -r requirements.txt python setup.py develop ``` +Run code style checks: + +```bash +flake8 +``` + Run unit tests: ```bash diff --git a/requirements.txt b/requirements.txt index ca9a8cc8..c450e437 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ pip +flake8 pytest mock pytest-mock From 0b0a2220a052855e2e179d713b70c2e86e9964a6 Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Wed, 8 Mar 2017 12:19:50 -0500 Subject: [PATCH 20/27] fixup! Ignore flake8 errors with inline comments: W291 trailing whitespace --- tests/rules/test_yarn_command_not_found.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/rules/test_yarn_command_not_found.py b/tests/rules/test_yarn_command_not_found.py index 67b7823b..d8a11618 100644 --- a/tests/rules/test_yarn_command_not_found.py +++ b/tests/rules/test_yarn_command_not_found.py @@ -82,7 +82,7 @@ yarn_help_stdout = b''' Run `yarn help COMMAND` for more information on specific commands. Visit https://yarnpkg.com/en/docs/cli/ to learn more about Yarn. -''' +''' # noqa @pytest.fixture(autouse=True) From aaf01394db67ea71b84a626ff86d3963a3aad28c Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Wed, 8 Mar 2017 12:39:24 -0500 Subject: [PATCH 21/27] fixup! Fix flake8 errors: E126 continuation line over-indented for hanging indent --- tests/rules/test_git_add_force.py | 4 ++-- tests/rules/test_git_stash_pop.py | 4 ++-- tests/rules/test_git_tag_force.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/rules/test_git_add_force.py b/tests/rules/test_git_add_force.py index abe2bd79..d6d3dd7c 100644 --- a/tests/rules/test_git_add_force.py +++ b/tests/rules/test_git_add_force.py @@ -18,5 +18,5 @@ def test_match(stderr): def test_get_new_command(stderr): - assert get_new_command(Command('git add dist/*.js', stderr=stderr)) \ - == "git add --force dist/*.js" + assert (get_new_command(Command('git add dist/*.js', stderr=stderr)) + == "git add --force dist/*.js") diff --git a/tests/rules/test_git_stash_pop.py b/tests/rules/test_git_stash_pop.py index 1ff34686..2e0578e4 100644 --- a/tests/rules/test_git_stash_pop.py +++ b/tests/rules/test_git_stash_pop.py @@ -14,5 +14,5 @@ def test_match(stderr): def test_get_new_command(stderr): - assert get_new_command(Command('git stash pop', stderr=stderr)) \ - == "git add . && git stash pop && git reset ." + assert (get_new_command(Command('git stash pop', stderr=stderr)) + == "git add . && git stash pop && git reset .") diff --git a/tests/rules/test_git_tag_force.py b/tests/rules/test_git_tag_force.py index 46c96fc6..3a2e40d9 100644 --- a/tests/rules/test_git_tag_force.py +++ b/tests/rules/test_git_tag_force.py @@ -14,5 +14,5 @@ def test_match(stderr): def test_get_new_command(stderr): - assert get_new_command(Command('git tag alert', stderr=stderr)) \ - == "git tag --force alert" + assert (get_new_command(Command('git tag alert', stderr=stderr)) + == "git tag --force alert") From c775937d17a2518a97b0340e46964fb7c46fce29 Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Wed, 8 Mar 2017 12:40:11 -0500 Subject: [PATCH 22/27] fixup! Fix flake8 errors: E101/W191 indentation contains (mixed spaces and) tabs --- thefuck/rules/git_add_force.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thefuck/rules/git_add_force.py b/thefuck/rules/git_add_force.py index 9adc0725..bf7c28b8 100644 --- a/thefuck/rules/git_add_force.py +++ b/thefuck/rules/git_add_force.py @@ -10,4 +10,4 @@ def match(command): @git_support def get_new_command(command): - return replace_argument(command.script, 'add', 'add --force') + return replace_argument(command.script, 'add', 'add --force') From 2c7ce91dd50366dd888e66ed7c42ad25f5b01294 Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Wed, 8 Mar 2017 12:42:24 -0500 Subject: [PATCH 23/27] Fix flake8 errors: F401 'sys' imported but unused --- thefuck/rules/ifconfig_device_not_found.py | 1 - 1 file changed, 1 deletion(-) diff --git a/thefuck/rules/ifconfig_device_not_found.py b/thefuck/rules/ifconfig_device_not_found.py index f8692236..88406991 100644 --- a/thefuck/rules/ifconfig_device_not_found.py +++ b/thefuck/rules/ifconfig_device_not_found.py @@ -1,6 +1,5 @@ import subprocess from thefuck.utils import for_app, replace_command, eager -import sys @for_app('ifconfig') def match(command): From 62a845fd9462884d4688d2bf9b43dc4347775b55 Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Wed, 8 Mar 2017 12:43:05 -0500 Subject: [PATCH 24/27] fixup! Fix flake8 errors: E302 expected 2 blank lines, found 1 --- thefuck/rules/ifconfig_device_not_found.py | 1 + 1 file changed, 1 insertion(+) diff --git a/thefuck/rules/ifconfig_device_not_found.py b/thefuck/rules/ifconfig_device_not_found.py index 88406991..958a6a7c 100644 --- a/thefuck/rules/ifconfig_device_not_found.py +++ b/thefuck/rules/ifconfig_device_not_found.py @@ -1,6 +1,7 @@ import subprocess from thefuck.utils import for_app, replace_command, eager + @for_app('ifconfig') def match(command): return 'error fetching interface information: Device not found' \ From 78515c7bbb81263fa339a67c2aabfa1a4f3c9af9 Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Wed, 8 Mar 2017 12:43:34 -0500 Subject: [PATCH 25/27] Fix flake8 errors: W391 blank line at end of file --- thefuck/rules/ifconfig_device_not_found.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/thefuck/rules/ifconfig_device_not_found.py b/thefuck/rules/ifconfig_device_not_found.py index 958a6a7c..a7e5026f 100644 --- a/thefuck/rules/ifconfig_device_not_found.py +++ b/thefuck/rules/ifconfig_device_not_found.py @@ -21,5 +21,3 @@ def get_new_command(command): interface = command.stderr.split(' ')[0][:-1] possible_interfaces = _get_possible_interfaces() return replace_command(command, interface, possible_interfaces) - - From e009f0a05b1b98793b63ea6333b278168341478f Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Wed, 8 Mar 2017 19:53:54 -0500 Subject: [PATCH 26/27] Fix flake8 errors: E305 expected 2 blank lines after class or function definition --- tests/rules/test_dirty_untar.py | 1 + thefuck/rules/dry.py | 1 + thefuck/rules/fix_file.py | 2 ++ thefuck/rules/git_fix_stash.py | 1 + thefuck/rules/man_no_space.py | 1 + thefuck/rules/pacman.py | 1 + thefuck/system/unix.py | 2 ++ thefuck/system/win32.py | 2 ++ thefuck/utils.py | 4 ++++ 9 files changed, 15 insertions(+) diff --git a/tests/rules/test_dirty_untar.py b/tests/rules/test_dirty_untar.py index 01ff6927..5308a4e5 100644 --- a/tests/rules/test_dirty_untar.py +++ b/tests/rules/test_dirty_untar.py @@ -33,6 +33,7 @@ def tar_error(tmpdir): return fixture + parametrize_extensions = pytest.mark.parametrize('ext', tar_extensions) # (filename as typed by the user, unquoted filename, quoted filename as per shells.quote) diff --git a/thefuck/rules/dry.py b/thefuck/rules/dry.py index cfc91da8..dce9b3d7 100644 --- a/thefuck/rules/dry.py +++ b/thefuck/rules/dry.py @@ -9,6 +9,7 @@ def match(command): def get_new_command(command): return ' '.join(command.script_parts[1:]) + # it should be rare enough to actually have to type twice the same word, so # this rule can have a higher priority to come before things like "cd cd foo" priority = 900 diff --git a/thefuck/rules/fix_file.py b/thefuck/rules/fix_file.py index a83034d4..b10cf047 100644 --- a/thefuck/rules/fix_file.py +++ b/thefuck/rules/fix_file.py @@ -40,6 +40,8 @@ def _make_pattern(pattern): .replace('{line}', '(?P[0-9]+)') \ .replace('{col}', '(?P[0-9]+)') return re.compile(pattern, re.MULTILINE) + + patterns = [_make_pattern(p).search for p in patterns] diff --git a/thefuck/rules/git_fix_stash.py b/thefuck/rules/git_fix_stash.py index 19cef4c3..0ff01b92 100644 --- a/thefuck/rules/git_fix_stash.py +++ b/thefuck/rules/git_fix_stash.py @@ -11,6 +11,7 @@ def match(command): else: return False + # git's output here is too complicated to be parsed (see the test file) stash_commands = ( 'apply', diff --git a/thefuck/rules/man_no_space.py b/thefuck/rules/man_no_space.py index c5869345..2d5d74e6 100644 --- a/thefuck/rules/man_no_space.py +++ b/thefuck/rules/man_no_space.py @@ -6,4 +6,5 @@ def match(command): def get_new_command(command): return u'man {}'.format(command.script[3:]) + priority = 2000 diff --git a/thefuck/rules/pacman.py b/thefuck/rules/pacman.py index 13a08d65..779ed20f 100644 --- a/thefuck/rules/pacman.py +++ b/thefuck/rules/pacman.py @@ -13,4 +13,5 @@ def get_new_command(command): return [formatme.format(pacman, package, command.script) for package in packages] + enabled_by_default, pacman = archlinux_env() diff --git a/thefuck/system/unix.py b/thefuck/system/unix.py index ca878033..0d4565bf 100644 --- a/thefuck/system/unix.py +++ b/thefuck/system/unix.py @@ -35,6 +35,7 @@ def get_key(): return ch + try: from pathlib import Path except ImportError: @@ -44,5 +45,6 @@ except ImportError: def _expanduser(self): return self.__class__(os.path.expanduser(str(self))) + if not hasattr(Path, 'expanduser'): Path.expanduser = _expanduser diff --git a/thefuck/system/win32.py b/thefuck/system/win32.py index 5e49ff6e..2bf3e2e7 100644 --- a/thefuck/system/win32.py +++ b/thefuck/system/win32.py @@ -26,6 +26,7 @@ def get_key(): encoding = sys.stdout.encoding or os.environ.get('PYTHONIOENCODING', 'utf-8') return ch.decode(encoding) + try: from pathlib import Path except ImportError: @@ -35,5 +36,6 @@ except ImportError: def _expanduser(self): return self.__class__(os.path.expanduser(str(self))) + # pathlib's expanduser fails on windows, see http://bugs.python.org/issue19776 Path.expanduser = _expanduser diff --git a/thefuck/utils.py b/thefuck/utils.py index 2bb20a22..29ea2486 100644 --- a/thefuck/utils.py +++ b/thefuck/utils.py @@ -40,6 +40,8 @@ def memoize(fn): return value return wrapper + + memoize.disabled = False @@ -238,6 +240,8 @@ def cache(*depends_on): return value return _cache + + cache.disabled = False From 2fea1f3846e88c24261c66116228f06c5fc8b52c Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Wed, 8 Mar 2017 20:05:23 -0500 Subject: [PATCH 27/27] Run flake8 on AppVeyor --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index 005e0d1a..96da08c9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,4 +20,5 @@ install: - "%PYTHON%/Scripts/pip.exe install -U -r requirements.txt" test_script: + - "%PYTHON%/python.exe -m flake8" - "%PYTHON%/Scripts/py.test.exe -sv"