Skip to content

Commit

Permalink
Add rule
Browse files Browse the repository at this point in the history
  • Loading branch information
luizvbo committed Apr 29, 2024
1 parent 6117054 commit 72596e3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
41 changes: 20 additions & 21 deletions src/rules/git_two_dashes.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
use crate::{
cli::command::CrabCommand,
rules::{match_rule_with_git_support, utils::git::get_new_command_with_git_support},
Rule,
rules::{
utils::git::{get_new_command_with_git_support, match_rule_with_git_support},
Rule,
},
shell::Shell,
utils::replace_argument,
};
use shell::Shell;

fn auxiliary_match_rule(command: &CrabCommand) -> bool {
command.output.as_ref().map_or(false, |o| {
o.contains("error: did you mean `") && o.contains("` (with two dashes ?)")
})
if let Some(stdout) = &command.output {
stdout.contains("error: did you mean `") && stdout.contains("` (with two dashes ?)")
} else {
false
}
}

pub fn match_rule(command: &mut CrabCommand, _system_shell: Option<&dyn Shell>) -> bool {
pub fn match_rule(command: &mut CrabCommand, system_shell: Option<&dyn Shell>) -> bool {
match_rule_with_git_support(auxiliary_match_rule, command)
}

fn auxiliary_get_new_command(
command: &CrabCommand,
_system_shell: Option<&dyn Shell>,
system_shell: Option<&dyn Shell>,
) -> Vec<String> {
if let Some(captured) = command.output.split('`').nth(1) {
let corrected_argument = format!("--{}", &captured[1..]);
let new_script = command
.script
.replacen(&captured[1..], &corrected_argument, 1);
vec![new_script]
} else {
vec![command.script.clone()]
if let Some(stdout) = &command.output {
if let Some(to) = &stdout.split('`').nth(1) {
return vec![replace_argument(&command.script, &to[1..], to)];
}
}
return vec![];

Check failure on line 32 in src/rules/git_two_dashes.rs

View workflow job for this annotation

GitHub Actions / Lint

unneeded `return` statement
}

pub fn get_new_command(
command: &mut CrabCommand,
_system_shell: Option<&dyn Shell>,
) -> Vec<String> {
get_new_command_with_git_support(auxiliary_get_new_command, command, _system_shell)
pub fn get_new_command(command: &mut CrabCommand, system_shell: Option<&dyn Shell>) -> Vec<String> {
get_new_command_with_git_support(auxiliary_get_new_command, command, system_shell)
}

pub fn get_rule() -> Rule {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ mod git_push_without_commits;
mod git_rebase_merge_dir;
mod git_rebase_no_changes;
mod git_remote_delete;
mod git_two_dashes;
mod git_remote_seturl_add;
mod git_rm_local_modifications;
mod git_rm_recursive;
mod git_stash;
mod git_stash_pop;
mod git_two_dashes;
mod go_run;
mod gradle_wrapper;
mod grep_arguments_order;
Expand Down

0 comments on commit 72596e3

Please sign in to comment.