1
0
mirror of https://github.com/nvbn/thefuck.git synced 2024-10-05 18:31:10 +01:00

#N/A: Add react_native_command_unrecognized rule

This commit is contained in:
Vladimir Iakovlev 2016-08-13 19:14:55 +03:00
parent 5f79217e97
commit efcf7da7db
4 changed files with 62 additions and 1 deletions

View File

@ -210,6 +210,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
* `python_command` – prepends `python` when you trying to run not executable/without `./` python script; * `python_command` – prepends `python` when you trying to run not executable/without `./` python script;
* `python_execute` – appends missing `.py` when executing Python files; * `python_execute` – appends missing `.py` when executing Python files;
* `quotation_marks` – fixes uneven usage of `'` and `"` when containing args'; * `quotation_marks` – fixes uneven usage of `'` and `"` when containing args';
* `react_native_command_unrecognized` – fixes unrecognized `react-native` commands;
* `rm_dir` – adds `-rf` when you trying to remove directory; * `rm_dir` – adds `-rf` when you trying to remove directory;
* `sed_unterminated_s` – adds missing '/' to `sed`'s `s` commands; * `sed_unterminated_s` – adds missing '/' to `sed`'s `s` commands;
* `sl_ls` – changes `sl` to `ls`; * `sl_ls` – changes `sl` to `ls`;

View File

@ -0,0 +1,46 @@
import pytest
from thefuck.rules.react_native_command_unrecognized import match, \
get_new_command
from tests.utils import Command
stderr = 'Command `{}` unrecognized'.format
stdout = '''
Usage: react-native <command>
Commands:
- start: starts the webserver
- bundle: builds the javascript bundle for offline use
- unbundle: builds javascript as "unbundle" for offline use
- new-library: generates a native library bridge
- android: generates an Android project for your app
- run-android: builds your app and starts it on a connected Android emulator or device
- log-android: print Android logs
- run-ios: builds your app and starts it on iOS simulator
- log-ios: print iOS logs
- upgrade: upgrade your app's template files to the latest version; run this after updating the react-native version in your package.json and running npm install
- link: link a library
'''
@pytest.mark.parametrize('command', [
Command('react-native star', stderr=stderr('star')),
Command('react-native android-logs', stderr=stderr('android-logs'))])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('gradle star', stderr=stderr('star')),
Command('react-native start')])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('command, result', [
(Command('react-native star', stdout, stderr('star')),
'react-native start'),
(Command('react-native logsandroid -f', stdout, stderr('logsandroid')),
'react-native log-android -f')])
def test_get_new_command(command, result):
assert get_new_command(command)[0] == result

View File

@ -32,7 +32,7 @@ DEFAULT_SETTINGS = {'rules': DEFAULT_RULES,
'history_limit': None, 'history_limit': None,
'alter_history': True, 'alter_history': True,
'wait_slow_command': 15, 'wait_slow_command': 15,
'slow_commands': ['lein'], 'slow_commands': ['lein', 'react-native'],
'env': {'LC_ALL': 'C', 'LANG': 'C', 'GIT_TRACE': '1'}} 'env': {'LC_ALL': 'C', 'LANG': 'C', 'GIT_TRACE': '1'}}
ENV_TO_ATTR = {'THEFUCK_RULES': 'rules', ENV_TO_ATTR = {'THEFUCK_RULES': 'rules',

View File

@ -0,0 +1,14 @@
import re
from thefuck.utils import for_app, replace_command
@for_app('react-native')
def match(command):
return re.match(r'Command `.*` unrecognized', command.stderr)
def get_new_command(command):
misspelled_command = re.findall(r'Command `(.*)` unrecognized',
command.stderr)[0]
commands = re.findall(r' - (.*): .*\n', command.stdout)
return replace_command(command, misspelled_command, commands)