mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-30 06:34:09 +00:00 
			
		
		
		
	Added quotation marks rule
This commit is contained in:
		| @@ -178,6 +178,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: | ||||
| * `open` – prepends `http` to address passed to `open`; | ||||
| * `pip_unknown_command` – fixes wrong pip commands, for example `pip instatl/pip install`; | ||||
| * `python_command` – prepends `python` when you trying to run not executable/without `./` python script; | ||||
| * `quotation_marks` – fixes uneven usage of `'` and `"` when containing args' | ||||
| * `rm_dir` – adds `-rf` when you trying to remove directory; | ||||
| * `sl_ls` – changes `sl` to `ls`; | ||||
| * `ssh_known_hosts` – removes host from `known_hosts` on warning; | ||||
|   | ||||
							
								
								
									
										19
									
								
								tests/rules/test_quotation_marks.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								tests/rules/test_quotation_marks.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| import pytest | ||||
| from thefuck.rules.quotation_marks import match, get_new_command | ||||
| from tests.utils import Command | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('command', [ | ||||
| 	Command(script="git commit -m \'My Message\""), | ||||
|     Command(script="git commit -am \"Mismatched Quotation Marks\'"), | ||||
|     Command(script="echo \"hello\'")]) | ||||
| def test_match(command): | ||||
| 	assert match(command, None) | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('command, new_command', [ | ||||
| 	(Command("git commit -m \'My Message\""), "git commit -m \"My Message\""), | ||||
|     (Command("git commit -am \"Mismatched Quotation Marks\'"), "git commit -am \"Mismatched Quotation Marks\""), | ||||
|     (Command("echo \"hello\'"), "echo \"hello\"")]) | ||||
| def test_get_new_command(command, new_command): | ||||
| 	assert get_new_command(command, None) == new_command | ||||
							
								
								
									
										14
									
								
								thefuck/rules/quotation_marks.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								thefuck/rules/quotation_marks.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| # Fixes careless " and ' usage | ||||
| #  | ||||
| # Example: | ||||
| # > git commit -m 'My Message" | ||||
| #  | ||||
| # | ||||
| #  | ||||
|  | ||||
| def match(command, settings): | ||||
|     return ('\'' in command.script | ||||
|             and '\"' in command.script) | ||||
|  | ||||
| def get_new_command(command, settings): | ||||
|     return command.script.replace ('\'', '\"') | ||||
		Reference in New Issue
	
	Block a user