1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-18 20:11:17 +00:00

Merge pull request #607 from josephfrazier/yarn-alias

Fix aliased `yarn` commands like `yarn ls`
This commit is contained in:
Vladimir Iakovlev 2017-03-03 13:50:58 +01:00 committed by GitHub
commit fbb73f262b
3 changed files with 37 additions and 0 deletions

View File

@ -247,6 +247,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
* `vagrant_up` – starts up the vagrant instance;
* `whois` – fixes `whois` command;
* `workon_doesnt_exists` – fixes `virtualenvwrapper` env name os suggests to create new.
* `yarn_alias` – fixes aliased `yarn` commands like `yarn ls`;
Enabled by default only on specific platforms:

View File

@ -0,0 +1,22 @@
import pytest
from thefuck.rules.yarn_alias import match, get_new_command
from tests.utils import Command
stderr_remove = 'error Did you mean `yarn remove`?'
stderr_list = 'error Did you mean `yarn list`?'
@pytest.mark.parametrize('command', [
Command(script='yarn rm', stderr=stderr_remove),
Command(script='yarn ls', stderr=stderr_list)])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command, new_command', [
(Command('yarn rm', stderr=stderr_remove), 'yarn remove'),
(Command('yarn ls', stderr=stderr_list), 'yarn list')])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command

View File

@ -0,0 +1,14 @@
import re
from thefuck.utils import replace_argument, for_app
@for_app('yarn', at_least=1)
def match(command):
return ('Did you mean' in command.stderr)
def get_new_command(command):
broken = command.script_parts[1]
fix = re.findall(r'Did you mean `yarn ([^`]*)`', command.stderr)[0]
return replace_argument(command.script, broken, fix)