From 900e83e0280fd7d90f989608713a1a21a12853b9 Mon Sep 17 00:00:00 2001 From: Russ Panula Date: Sat, 25 Mar 2017 23:12:01 -0700 Subject: [PATCH] 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]