Skip to content

Commit e2be981

Browse files
committed
Fixed all remaining issues
1 parent 1047899 commit e2be981

File tree

8 files changed

+357
-89
lines changed

8 files changed

+357
-89
lines changed

renamify-cli/src/replace.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use anyhow::{anyhow, Context, Result};
22
use regex::Regex;
33
use renamify_core::{apply_plan, create_simple_plan, Plan, PlanOptions, Preview};
4-
use serde_json;
54
use std::io::{self, Write};
65
use std::path::PathBuf;
76

@@ -154,7 +153,7 @@ fn commit_changes(plan: &Plan) -> Result<()> {
154153

155154
// Check if we're in a git repository
156155
let status = Command::new("git")
157-
.args(&["status", "--porcelain"])
156+
.args(["status", "--porcelain"])
158157
.output()
159158
.context("Failed to check git status")?;
160159

@@ -192,7 +191,7 @@ fn commit_changes(plan: &Plan) -> Result<()> {
192191
let message = format!("Replace '{}' with '{}'", plan.search, plan.replace);
193192

194193
let status = Command::new("git")
195-
.args(&["commit", "-m", &message])
194+
.args(["commit", "-m", &message])
196195
.status()
197196
.context("Failed to create git commit")?;
198197

renamify-cli/tests/case_style_filtering.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ CompoundTitle: Title Case Example
3333
fn run_search(dir: &Path, styles: &str) -> String {
3434
let output = std::process::Command::new(env!("CARGO_BIN_EXE_renamify"))
3535
.current_dir(dir)
36-
.args(&[
36+
.args([
3737
"search",
3838
"test case", // Search for "test case" in various forms
3939
"--only-styles",
@@ -178,7 +178,7 @@ mixed_caseCASE
178178
fn run_search(dir: &Path, styles: &str) -> String {
179179
let output = std::process::Command::new(env!("CARGO_BIN_EXE_renamify"))
180180
.current_dir(dir)
181-
.args(&[
181+
.args([
182182
"search",
183183
"case", // Search for single word "case"
184184
"--only-styles",
@@ -287,7 +287,7 @@ TEST_CASE
287287
// Test with multiple styles selected
288288
let output = std::process::Command::new(env!("CARGO_BIN_EXE_renamify"))
289289
.current_dir(temp_dir.path())
290-
.args(&[
290+
.args([
291291
"search",
292292
"test case",
293293
"--only-styles",
@@ -347,8 +347,8 @@ let another-var = 10; // unrelated kebab
347347

348348
// Test 1: Get results for lower style alone (replacing original)
349349
// For now, we'll use snake as the baseline test
350-
let snake_baseline_output = std::process::Command::new(&get_cli_path())
351-
.args(&[
350+
let snake_baseline_output = std::process::Command::new(get_cli_path())
351+
.args([
352352
"search",
353353
"case",
354354
"--only-styles",
@@ -364,8 +364,8 @@ let another-var = 10; // unrelated kebab
364364
count_matches(&String::from_utf8(snake_baseline_output.stdout).unwrap());
365365

366366
// Test 2: Get results for snake style alone
367-
let snake_output = std::process::Command::new(&get_cli_path())
368-
.args(&[
367+
let snake_output = std::process::Command::new(get_cli_path())
368+
.args([
369369
"search",
370370
"case",
371371
"--only-styles",
@@ -380,8 +380,8 @@ let another-var = 10; // unrelated kebab
380380
let snake_matches = count_matches(&String::from_utf8(snake_output.stdout).unwrap());
381381

382382
// Test 3: Get results for kebab style alone
383-
let kebab_output = std::process::Command::new(&get_cli_path())
384-
.args(&[
383+
let kebab_output = std::process::Command::new(get_cli_path())
384+
.args([
385385
"search",
386386
"case",
387387
"--only-styles",
@@ -396,8 +396,8 @@ let another-var = 10; // unrelated kebab
396396
let kebab_matches = count_matches(&String::from_utf8(kebab_output.stdout).unwrap());
397397

398398
// Test 4: Get results for combined styles
399-
let combined_output = std::process::Command::new(&get_cli_path())
400-
.args(&[
399+
let combined_output = std::process::Command::new(get_cli_path())
400+
.args([
401401
"search",
402402
"case",
403403
"--only-styles",
@@ -450,8 +450,8 @@ let unrelated_variable = 6; // should not match any "case" search
450450
}
451451

452452
// Test that lower+snake doesn't find camel/pascal matches
453-
let output = std::process::Command::new(&get_cli_path())
454-
.args(&[
453+
let output = std::process::Command::new(get_cli_path())
454+
.args([
455455
"search",
456456
"case",
457457
"--only-styles",
@@ -471,7 +471,7 @@ let unrelated_variable = 6; // should not match any "case" search
471471
// When searching for single word "case" with lower+snake styles,
472472
// both styles generate "case" as the pattern, so it matches all instances of "case"
473473
// This includes "case" standalone and "case" within compound words
474-
assert!(matches.len() > 0, "Should find matches for lower+snake");
474+
assert!(!matches.is_empty(), "Should find matches for lower+snake");
475475

476476
// Verify that all matches are for the "case" pattern
477477
let all_case_matches = matches
@@ -526,8 +526,8 @@ let Test Case = 8; // title
526526

527527
// Get individual results for each style
528528
for style in &all_styles {
529-
let output = std::process::Command::new(&get_cli_path())
530-
.args(&["search", "case", "--only-styles", style, "--output", "json"])
529+
let output = std::process::Command::new(get_cli_path())
530+
.args(["search", "case", "--only-styles", style, "--output", "json"])
531531
.current_dir(temp_dir.path())
532532
.output()
533533
.expect("Failed to execute command");
@@ -551,8 +551,8 @@ let Test Case = 8; // title
551551
];
552552

553553
for (combo_str, combo_styles) in combinations {
554-
let output = std::process::Command::new(&get_cli_path())
555-
.args(&[
554+
let output = std::process::Command::new(get_cli_path())
555+
.args([
556556
"search",
557557
"case",
558558
"--only-styles",

renamify-core/src/ambiguity/file_context.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ mod tests {
230230
fn test_analyze_camel_case_file() {
231231
let mut analyzer = FileContextAnalyzer::new();
232232
analyzer.min_identifiers_threshold = 5; // Lower threshold for test
233+
#[allow(clippy::needless_raw_string_hashes)]
233234
let content = r#"
234235
function getUserData() {
235236
const userId = getUserId();
@@ -253,6 +254,7 @@ mod tests {
253254
fn test_analyze_snake_case_file() {
254255
let mut analyzer = FileContextAnalyzer::new();
255256
analyzer.min_identifiers_threshold = 5; // Lower threshold for test
257+
#[allow(clippy::needless_raw_string_hashes)]
256258
let content = r#"
257259
def get_user_data():
258260
user_id = get_user_id()
@@ -285,6 +287,7 @@ mod tests {
285287
#[test]
286288
fn test_mixed_styles() {
287289
let analyzer = FileContextAnalyzer::new();
290+
#[allow(clippy::needless_raw_string_hashes)]
288291
let content = r#"
289292
const USER_CONSTANT = 100;
290293
function getUserName() { }

renamify-core/src/ambiguity/resolver.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,12 @@ mod tests {
320320
#[test]
321321
fn test_language_heuristic_ruby() {
322322
let resolver = AmbiguityResolver::new();
323-
let mut context = AmbiguityContext::default();
324-
context.file_path = Some(PathBuf::from("test.rb"));
325-
context.line_content = Some("class API".to_string());
326-
context.match_position = Some(6); // Position after "class "
323+
let context = AmbiguityContext {
324+
file_path: Some(PathBuf::from("test.rb")),
325+
line_content: Some("class API".to_string()),
326+
match_position: Some(6), // Position after "class "
327+
..Default::default()
328+
};
327329

328330
// "API" could be Pascal or SCREAMING_SNAKE
329331
let result = resolver.resolve("API", "Interface", &context);

renamify-core/src/case_model.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,45 @@ pub fn detect_style(s: &str) -> Option<Style> {
102102
if is_train_case(s) {
103103
Some(Style::Train)
104104
} else {
105+
// Mixed case with hyphens but not Train case
106+
// Return None for inconsistent patterns like "hello-World" or "tool-Specific"
107+
// These don't follow any standard naming convention
105108
None
106109
}
107110
},
111+
// Mixed underscore and hyphen - detect based on dominant style
112+
(true, true, false, false, _, _) => {
113+
// For identifiers like "foo_bar_baz_qux-specific" or "Tool-specific-Tool"
114+
// Determine the primary style based on what comes before the first separator change
115+
if let Some(hyphen_pos) = s.find('-') {
116+
if let Some(underscore_pos) = s.find('_') {
117+
// Whichever separator comes first determines the primary style
118+
if underscore_pos < hyphen_pos {
119+
// Starts with underscores, so primarily snake_case
120+
if has_upper && !has_lower {
121+
Some(Style::ScreamingSnake)
122+
} else {
123+
Some(Style::Snake)
124+
}
125+
} else {
126+
// Starts with hyphens, so primarily kebab-case
127+
if has_upper && !has_lower {
128+
Some(Style::ScreamingTrain)
129+
} else if is_train_case(&s[..=hyphen_pos]) {
130+
Some(Style::Train)
131+
} else {
132+
Some(Style::Kebab)
133+
}
134+
}
135+
} else {
136+
// Should not happen since has_underscore is true
137+
Some(Style::Snake)
138+
}
139+
} else {
140+
// Should not happen since has_hyphen is true
141+
Some(Style::Snake)
142+
}
143+
},
108144
(false, false, true, false, _, true) => Some(Style::Dot),
109145
(false, false, false, true, true, true) => {
110146
if is_title_case(s) {

0 commit comments

Comments
 (0)