From d41cbb6810d4d82fdee6e411594c2211ed260326 Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Sun, 26 Mar 2017 15:51:59 -0400 Subject: [PATCH 1/3] Fix heroku_not_command for new stderr format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit heroku updated its command suggestion formatting, so account for that. For example: $ heroku log ▸ log is not a heroku command. ▸ Perhaps you meant logs? ▸ Run heroku _ to run heroku logs. ▸ Run heroku help for a list of available commands. $ fuck heroku logs [enter/↑/↓/ctrl+c] --- tests/rules/test_heroku_not_command.py | 27 ++++++++++++-------------- thefuck/rules/heroku_not_command.py | 14 +++---------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/tests/rules/test_heroku_not_command.py b/tests/rules/test_heroku_not_command.py index b322fec4..be67eae9 100644 --- a/tests/rules/test_heroku_not_command.py +++ b/tests/rules/test_heroku_not_command.py @@ -1,34 +1,31 @@ +# -*- coding: utf-8 -*- + import pytest from tests.utils import Command from thefuck.rules.heroku_not_command import match, get_new_command -def suggest_stderr(cmd): - return ''' ! `{}` is not a heroku command. - ! Perhaps you meant `logs`, `pg`. - ! See `heroku help` for a list of available commands.'''.format(cmd) +suggest_stderr = ''' + ▸ log is not a heroku command. + ▸ Perhaps you meant logs? + ▸ Run heroku _ to run heroku logs. + ▸ Run heroku help for a list of available commands.''' -no_suggest_stderr = ''' ! `aaaaa` is not a heroku command. - ! See `heroku help` for a list of available commands.''' - - -@pytest.mark.parametrize('cmd', ['log', 'pge']) +@pytest.mark.parametrize('cmd', ['log']) def test_match(cmd): assert match( - Command('heroku {}'.format(cmd), stderr=suggest_stderr(cmd))) + Command('heroku {}'.format(cmd), stderr=suggest_stderr)) @pytest.mark.parametrize('script, stderr', [ - ('cat log', suggest_stderr('log')), - ('heroku aaa', no_suggest_stderr)]) + ('cat log', suggest_stderr)]) def test_not_match(script, stderr): assert not match(Command(script, stderr=stderr)) @pytest.mark.parametrize('cmd, result', [ - ('log', ['heroku logs', 'heroku pg']), - ('pge', ['heroku pg', 'heroku logs'])]) + ('log', 'heroku logs')]) def test_get_new_command(cmd, result): - command = Command('heroku {}'.format(cmd), stderr=suggest_stderr(cmd)) + command = Command('heroku {}'.format(cmd), stderr=suggest_stderr) assert get_new_command(command) == result diff --git a/thefuck/rules/heroku_not_command.py b/thefuck/rules/heroku_not_command.py index 48c322a0..8ace1f76 100644 --- a/thefuck/rules/heroku_not_command.py +++ b/thefuck/rules/heroku_not_command.py @@ -1,19 +1,11 @@ import re -from thefuck.utils import replace_command, for_app +from thefuck.utils import for_app @for_app('heroku') def match(command): - return 'is not a heroku command' in command.stderr and \ - 'Perhaps you meant' in command.stderr - - -def _get_suggests(stderr): - for line in stderr.split('\n'): - if 'Perhaps you meant' in line: - return re.findall(r'`([^`]+)`', line) + return 'Run heroku _ to run' in command.stderr def get_new_command(command): - wrong = re.findall(r'`(\w+)` is not a heroku command', command.stderr)[0] - return replace_command(command, wrong, _get_suggests(command.stderr)) + return re.findall('Run heroku _ to run ([^.]*)', command.stderr)[0] From 900e83e0280fd7d90f989608713a1a21a12853b9 Mon Sep 17 00:00:00 2001 From: Russ Panula Date: Sat, 25 Mar 2017 23:12:01 -0700 Subject: [PATCH 2/3] add rule for: yarn install [pkg] --- `install` has been replaced with `add` to add new dependencies. Run $0 instead. https://github.com/yarnpkg/yarn/blob/6e9a9a6596ca8f177f68f6672a1ef4ff16705336/src/reporters/lang/en.js#L18 --- README.md | 1 + tests/rules/test_yarn_command_replaced.py | 32 +++++++++++++++++++++++ thefuck/rules/yarn_command_replaced.py | 13 +++++++++ 3 files changed, 46 insertions(+) create mode 100644 tests/rules/test_yarn_command_replaced.py create mode 100644 thefuck/rules/yarn_command_replaced.py diff --git a/README.md b/README.md index 5d9a15c9..969344ba 100644 --- a/README.md +++ b/README.md @@ -259,6 +259,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `workon_doesnt_exists` – fixes `virtualenvwrapper` env name os suggests to create new. * `yarn_alias` – fixes aliased `yarn` commands like `yarn ls`; * `yarn_command_not_found` – fixes misspelled `yarn` commands; +* `yarn_command_replaced` – fixes replaced `yarn` commands; * `yarn_help` – makes it easier to open `yarn` documentation; Enabled by default only on specific platforms: diff --git a/tests/rules/test_yarn_command_replaced.py b/tests/rules/test_yarn_command_replaced.py new file mode 100644 index 00000000..cb91a412 --- /dev/null +++ b/tests/rules/test_yarn_command_replaced.py @@ -0,0 +1,32 @@ +# -*- encoding: utf-8 -*- + +import pytest +from tests.utils import Command +from thefuck.rules.yarn_command_replaced import match, get_new_command + + +stderr = ''' +error `install` has been replaced with `add` to add new dependencies. Run "yarn add {}" instead. +'''.format + + +@pytest.mark.parametrize('command', [ + Command(script='yarn install asdklj', stderr=stderr('asdklj')), + Command(script='yarn install liuqowe', stderr=stderr('liuqowe')), + Command(script='yarn install zxmnc', stderr=stderr('zxmnc'))]) +def test_match(command): + assert match(command) + + +@pytest.mark.parametrize('command, new_command', [ + (Command('yarn install asdklj', stderr=stderr('asdklj')), 'yarn add asdklj'), + (Command('yarn install iiuqowe', stderr=stderr('iiuqowe')), 'yarn add iiuqowe'), + (Command('yarn install zxmnc', stderr=stderr('zxmnc')), 'yarn add zxmnc')]) +def test_get_new_command(command, new_command): + assert get_new_command(command) == new_command + + +@pytest.mark.parametrize('command', [ + Command('yarn install')]) +def test_not_match(command): + assert not match(command) diff --git a/thefuck/rules/yarn_command_replaced.py b/thefuck/rules/yarn_command_replaced.py new file mode 100644 index 00000000..1594d1d0 --- /dev/null +++ b/thefuck/rules/yarn_command_replaced.py @@ -0,0 +1,13 @@ +import re +from thefuck.utils import for_app + +regex = re.compile(r'Run "(.*)" instead') + + +@for_app('yarn', at_least=1) +def match(command): + return regex.findall(command.stderr) + + +def get_new_command(command): + return regex.findall(command.stderr)[0] From 802fcd96fdb328205fb28658afca6b814c24355f Mon Sep 17 00:00:00 2001 From: Vladimir Iakovlev Date: Tue, 28 Mar 2017 18:35:40 +0200 Subject: [PATCH 3/3] #621: Refine `yarn_command_replaced` rule tests --- tests/rules/test_yarn_command_replaced.py | 32 +++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/rules/test_yarn_command_replaced.py b/tests/rules/test_yarn_command_replaced.py index cb91a412..57c5021f 100644 --- a/tests/rules/test_yarn_command_replaced.py +++ b/tests/rules/test_yarn_command_replaced.py @@ -1,32 +1,32 @@ -# -*- encoding: utf-8 -*- - import pytest from tests.utils import Command from thefuck.rules.yarn_command_replaced import match, get_new_command -stderr = ''' -error `install` has been replaced with `add` to add new dependencies. Run "yarn add {}" instead. -'''.format +stderr = ('error `install` has been replaced with `add` to add new ' + 'dependencies. Run "yarn add {}" instead.').format @pytest.mark.parametrize('command', [ - Command(script='yarn install asdklj', stderr=stderr('asdklj')), - Command(script='yarn install liuqowe', stderr=stderr('liuqowe')), - Command(script='yarn install zxmnc', stderr=stderr('zxmnc'))]) + Command(script='yarn install redux', stderr=stderr('redux')), + Command(script='yarn install moment', stderr=stderr('moment')), + Command(script='yarn install lodash', stderr=stderr('lodash'))]) def test_match(command): assert match(command) -@pytest.mark.parametrize('command, new_command', [ - (Command('yarn install asdklj', stderr=stderr('asdklj')), 'yarn add asdklj'), - (Command('yarn install iiuqowe', stderr=stderr('iiuqowe')), 'yarn add iiuqowe'), - (Command('yarn install zxmnc', stderr=stderr('zxmnc')), 'yarn add zxmnc')]) -def test_get_new_command(command, new_command): - assert get_new_command(command) == new_command - - @pytest.mark.parametrize('command', [ Command('yarn install')]) def test_not_match(command): assert not match(command) + + +@pytest.mark.parametrize('command, new_command', [ + (Command('yarn install redux', stderr=stderr('redux')), + 'yarn add redux'), + (Command('yarn install moment', stderr=stderr('moment')), + 'yarn add moment'), + (Command('yarn install lodash', stderr=stderr('lodash')), + 'yarn add lodash')]) +def test_get_new_command(command, new_command): + assert get_new_command(command) == new_command