Skip to content

Commit 624e775

Browse files
committed
added support for plural/singular detection by default
1 parent edd3668 commit 624e775

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+614
-105
lines changed

renamify-cli/src/cli/args.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ pub struct StyleArgs {
6767
/// Ignore mixed-case/ambiguous identifiers that don't match standard patterns
6868
#[arg(long)]
6969
pub ignore_ambiguous: bool,
70+
71+
/// Disable automatic singular/plural variants for matching identifiers
72+
#[arg(long = "no-plural-variants")]
73+
pub no_plural_variants: bool,
7074
}
7175

7276
/// Common path filtering arguments
@@ -344,6 +348,10 @@ pub enum Commands {
344348
#[arg(long)]
345349
dry_run: bool,
346350

351+
/// Disable automatic singular/plural variants
352+
#[arg(long = "no-plural-variants")]
353+
no_plural_variants: bool,
354+
347355
/// Skip confirmation prompt and apply immediately
348356
#[arg(short = 'y', long = "yes")]
349357
yes: bool,

renamify-cli/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ fn main() {
135135
output,
136136
quiet,
137137
styles.ignore_ambiguous,
138+
!styles.no_plural_variants,
138139
false, // regex flag - not used in Plan command
139140
)
140141
},
@@ -206,6 +207,7 @@ fn main() {
206207
output,
207208
quiet,
208209
styles.ignore_ambiguous,
210+
!styles.no_plural_variants,
209211
false, // regex flag - not used in Search command
210212
)
211213
},
@@ -278,6 +280,7 @@ fn main() {
278280
styles.exclude_styles,
279281
styles.include_styles,
280282
styles.only_styles,
283+
!styles.no_plural_variants,
281284
styles.ignore_ambiguous,
282285
exclude_match,
283286
exclude_matching_lines,
@@ -313,6 +316,7 @@ fn main() {
313316
commit,
314317
large,
315318
force_with_conflicts,
319+
no_plural_variants,
316320
dry_run,
317321
yes,
318322
output,
@@ -336,6 +340,7 @@ fn main() {
336340
commit,
337341
large,
338342
force_with_conflicts,
343+
!no_plural_variants,
339344
dry_run,
340345
yes || cli.yes,
341346
use_color,

renamify-cli/src/plan.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub fn handle_plan(
3434
output: OutputFormat,
3535
quiet: bool,
3636
ignore_ambiguous: bool,
37+
enable_plural_variants: bool,
3738
_regex: bool, // TODO: Implement regex mode
3839
) -> Result<()> {
3940
// Error if both preview and JSON output are specified
@@ -110,6 +111,7 @@ pub fn handle_plan(
110111
include_acronyms,
111112
exclude_acronyms,
112113
only_acronyms,
114+
enable_plural_variants,
113115
ignore_ambiguous,
114116
None, // working_dir
115117
Some(&atomic_config),

renamify-cli/src/rename.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub fn handle_rename(
1717
exclude_styles: Vec<StyleArg>,
1818
include_styles: Vec<StyleArg>,
1919
only_styles: Vec<StyleArg>,
20+
enable_plural_variants: bool,
2021
ignore_ambiguous: bool,
2122
exclude_match: Vec<String>,
2223
exclude_matching_lines: Option<String>,
@@ -87,6 +88,7 @@ pub fn handle_rename(
8788
&exclude_styles,
8889
&include_styles,
8990
&only_styles,
91+
enable_plural_variants,
9092
ignore_ambiguous,
9193
&exclude_match,
9294
exclude_matching_lines.as_ref(),

renamify-cli/src/replace.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub fn handle_replace(
2222
commit: bool,
2323
large: bool,
2424
force_with_conflicts: bool,
25+
enable_plural_variants: bool,
2526
dry_run: bool,
2627
yes: bool,
2728
use_color: bool,
@@ -48,6 +49,7 @@ pub fn handle_replace(
4849
plan_out: PathBuf::from(".renamify/plan.json"),
4950
coerce_separators: renamify_core::scanner::CoercionMode::Off,
5051
atomic_config: None, // Replace doesn't use atomic mode
52+
enable_plural_variants,
5153
};
5254

5355
// Create the plan using simple regex/literal replacement

renamify-cli/src/search.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub fn handle_search(
2929
output: OutputFormat,
3030
quiet: bool,
3131
ignore_ambiguous: bool,
32+
enable_plural_variants: bool,
3233
) -> Result<()> {
3334
// Convert CLI style args to core Style enum
3435
let exclude_styles: Vec<Style> = exclude_styles.into_iter().map(Into::into).collect();
@@ -80,6 +81,7 @@ pub fn handle_search(
8081
include_acronyms,
8182
exclude_acronyms,
8283
only_acronyms,
84+
enable_plural_variants,
8385
ignore_ambiguous,
8486
None, // working_dir
8587
None, // atomic_config

renamify-cli/tests/cli_tests.rs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ fn test_plan_command_basic() {
9595
vec![], // include_acronyms
9696
vec![], // exclude_acronyms
9797
vec![], // only_acronyms
98+
true, // enable_plural_variants
9899
false, // ignore_ambiguous
99100
Some(temp_dir.path()), // working_dir
100101
None, // atomic_config
@@ -143,6 +144,7 @@ fn test_plan_command_with_styles() {
143144
vec![], // include_acronyms
144145
vec![], // exclude_acronyms
145146
vec![], // only_acronyms
147+
true, // enable_plural_variants
146148
false, // ignore_ambiguous
147149
Some(temp_dir.path()), // working_dir
148150
None, // atomic_config
@@ -187,6 +189,7 @@ fn test_plan_command_with_styles() {
187189
vec![], // include_acronyms
188190
vec![], // exclude_acronyms
189191
vec![], // only_acronyms
192+
true, // enable_plural_variants
190193
false, // ignore_ambiguous
191194
Some(temp_dir.path()), // working_dir
192195
None, // atomic_config
@@ -201,6 +204,97 @@ fn test_plan_command_with_styles() {
201204
);
202205
}
203206

207+
#[test]
208+
fn test_plan_command_plural_variant_toggle() {
209+
let temp_dir = TempDir::new().unwrap();
210+
let test_file = temp_dir.child("sample.ts");
211+
test_file
212+
.write_str(
213+
"type DeployRequest = {}\n\
214+
type DeployRequestList = DeployRequest[];\n\
215+
export const load = (): Promise<DeployRequestList> => Promise.resolve([]);\n",
216+
)
217+
.unwrap();
218+
219+
let (enabled_result, _) = plan_operation(
220+
"DeployRequests",
221+
"DeployApprovalRequests",
222+
vec![PathBuf::from(".")], // paths
223+
vec![], // include
224+
vec![], // exclude
225+
true, // respect_gitignore
226+
0, // unrestricted_level
227+
true, // rename_files
228+
true, // rename_dirs
229+
&[], // exclude_styles
230+
&[], // include_styles
231+
&[], // only_styles
232+
vec![], // exclude_match
233+
None, // exclude_matching_lines
234+
None, // plan_out
235+
None, // preview_format
236+
true, // dry_run
237+
true, // fixed_table_width
238+
false, // use_color
239+
false, // no_acronyms
240+
vec![], // include_acronyms
241+
vec![], // exclude_acronyms
242+
vec![], // only_acronyms
243+
true, // enable_plural_variants
244+
false, // ignore_ambiguous
245+
Some(temp_dir.path()), // working_dir
246+
None, // atomic_config
247+
)
248+
.unwrap();
249+
250+
let plan_enabled = enabled_result
251+
.plan
252+
.expect("plan result should include plan");
253+
assert!(plan_enabled.matches.iter().any(|m| m
254+
.line_after
255+
.as_deref()
256+
.is_some_and(|line| line.contains("DeployApprovalRequestList"))));
257+
258+
let (disabled_result, _) = plan_operation(
259+
"DeployRequests",
260+
"DeployApprovalRequests",
261+
vec![PathBuf::from(".")],
262+
vec![],
263+
vec![],
264+
true,
265+
0,
266+
true,
267+
true,
268+
&[],
269+
&[],
270+
&[],
271+
vec![],
272+
None,
273+
None,
274+
None,
275+
true,
276+
true,
277+
false,
278+
false,
279+
vec![],
280+
vec![],
281+
vec![],
282+
false, // enable_plural_variants
283+
false,
284+
Some(temp_dir.path()),
285+
None,
286+
)
287+
.unwrap();
288+
289+
let plan_disabled = disabled_result
290+
.plan
291+
.expect("plan result should include plan");
292+
assert!(plan_disabled.matches.iter().all(|m| m
293+
.line_after
294+
.as_deref()
295+
.is_none_or(|line| !line.contains("DeployApprovalRequestList"))));
296+
}
297+
204298
#[test]
205299
fn test_plan_command_with_includes() {
206300
let temp_dir = TempDir::new().unwrap();

renamify-cli/tests/train_case_e2e_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ The Rename-Tool-Based-Solution is working.
235235
&[], // exclude_styles
236236
&[], // include_styles
237237
&[], // only_styles
238+
true, // enable_plural_variants
238239
false, // ignore_ambiguous
239240
&[], // exclude_match
240241
None, // exclude_matching_lines

renamify-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ aho-corasick = "1.1"
3131
chrono = { version = "0.4", features = ["serde"] }
3232
toml = "0.9"
3333
diffy = "0.4.2"
34+
pluralizer = "0.5"
3435

3536
[target.'cfg(unix)'.dependencies]
3637
libc = "0.2"

0 commit comments

Comments
 (0)