This commit is contained in:
Alan Zhao 2023-07-30 18:17:09 -07:00 committed by GitHub
commit 58cb3522df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 0 deletions

View File

@ -301,6 +301,7 @@ following rules are enabled by default:
* `mkdir_p` – adds `-p` when you try to create a directory without a parent;
* `mvn_no_command` – adds `clean package` to `mvn`;
* `mvn_unknown_lifecycle_phase` – fixes misspelled life cycle phases with `mvn`;
* `ninja` – fixes wrong targest passed to the `ninja` build tool;
* `npm_missing_script` &ndash; fixes `npm` custom script name in `npm run-script <script>`;
* `npm_run_script` &ndash; adds missing `run-script` for custom `npm` scripts;
* `npm_wrong_command` &ndash; fixes wrong npm commands like `npm urgrade`;

14
tests/rules/test_ninja.py Normal file
View File

@ -0,0 +1,14 @@
import pytest
from thefuck.rules.ninja import get_new_command, match
from thefuck.types import Command
match_output = 'ninja: error: unknown target \'clong\', did you mean \'clang\'?'
no_match_output = 'ninja: error: unknown target \'foobar\''
def test_match():
assert match(Command('ninja clong', match_output))
assert not match(Command('ninja foobar', no_match_output))
def test_get_new_command():
new_command = get_new_command(Command('ninja clong', match_output))
assert new_command == 'ninja clang'

8
thefuck/rules/ninja.py Normal file
View File

@ -0,0 +1,8 @@
import re
def match(command):
return 'unknown target' in command.output and 'did you mean' in command.output
def get_new_command(command):
target = re.search(r'did you mean \'(.*)\'\?$', command.output).group(1)
return 'ninja {}'.format(target)