diff --git a/tests/rules/test_yarn_command_not_found.py b/tests/rules/test_yarn_command_not_found.py index d8a11618..dd6ca5ae 100644 --- a/tests/rules/test_yarn_command_not_found.py +++ b/tests/rules/test_yarn_command_not_found.py @@ -106,6 +106,13 @@ def test_not_match(command): @pytest.mark.parametrize('command, result', [ - (Command('yarn whyy webpack', stderr=stderr('whyy')), 'yarn why webpack')]) + (Command('yarn whyy webpack', stderr=stderr('whyy')), + 'yarn why webpack'), + (Command('yarn require lodash', stderr=stderr('require')), + 'yarn add lodash')]) def test_get_new_command(command, result): - assert get_new_command(command)[0] == result + fixed_command = get_new_command(command) + if isinstance(fixed_command, list): + fixed_command = fixed_command[0] + + assert fixed_command == result diff --git a/thefuck/rules/yarn_command_not_found.py b/thefuck/rules/yarn_command_not_found.py index 6d51ff84..82a7a2a8 100644 --- a/thefuck/rules/yarn_command_not_found.py +++ b/thefuck/rules/yarn_command_not_found.py @@ -1,6 +1,6 @@ import re from subprocess import Popen, PIPE -from thefuck.utils import for_app, eager, replace_command +from thefuck.utils import for_app, eager, replace_command, replace_argument regex = re.compile(r'error Command "(.*)" not found.') @@ -10,6 +10,9 @@ def match(command): return regex.findall(command.stderr) +npm_commands = {'require': 'add'} + + @eager def _get_all_tasks(): proc = Popen(['yarn', '--help'], stdout=PIPE) @@ -27,5 +30,9 @@ def _get_all_tasks(): def get_new_command(command): misspelled_task = regex.findall(command.stderr)[0] - tasks = _get_all_tasks() - return replace_command(command, misspelled_task, tasks) + if misspelled_task in npm_commands: + yarn_command = npm_commands[misspelled_task] + return replace_argument(command.script, misspelled_task, yarn_command) + else: + tasks = _get_all_tasks() + return replace_command(command, misspelled_task, tasks)