clippier 0.3.0

MoosicBox clippier package
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
#[cfg(feature = "cargo-workspace")]
use clippier::{OutputType, handle_features_command};
#[cfg(feature = "cargo-workspace")]
use clippier_test_utilities::test_resources::load_test_workspace;
#[cfg(feature = "cargo-workspace")]
use std::collections::HashSet;

#[cfg(feature = "cargo-workspace")]
#[switchy_async::test]
async fn test_packages_filter_single_package() {
    // Test filtering to a single package
    let (temp_dir, _) = load_test_workspace("complex");
    let result = handle_features_command(
        temp_dir.path().to_str().unwrap(),
        None,                       // os
        None,                       // offset
        None,                       // max
        None,                       // max_parallel
        None,                       // chunked
        false,                      // spread
        false,                      // randomize
        None,                       // seed
        None,                       // features
        None,                       // skip_features
        None,                       // required_features
        Some(&["api".to_string()]), // packages - only select "api"
        None,                       // changed_files
        #[cfg(feature = "git-diff")]
        None, // git_base
        #[cfg(feature = "git-diff")]
        None, // git_head
        false,                      // include_reasoning
        None,
        &[],
        &[],
        #[cfg(feature = "_transforms")]
        &[],
        #[cfg(feature = "_transforms")]
        false,
        #[cfg(feature = "_workspace")]
        None, // workspace_type filter
        OutputType::Json,
    )
    .await;

    assert!(result.is_ok());
    let json: Vec<serde_json::Value> = serde_json::from_str(&result.unwrap()).unwrap();

    // Should only contain configs for the "api" package
    for config in &json {
        assert_eq!(config["name"], "api");
    }
    assert!(
        !json.is_empty(),
        "Should have at least one config for api package"
    );
}

#[cfg(feature = "cargo-workspace")]
#[switchy_async::test]
async fn test_packages_filter_multiple_packages() {
    // Test filtering to multiple packages
    let (temp_dir, _) = load_test_workspace("complex");
    let result = handle_features_command(
        temp_dir.path().to_str().unwrap(),
        None,
        None,
        None,
        None,
        None,
        false,
        false,
        None,
        None,
        None,
        None,
        Some(&["api".to_string(), "web".to_string(), "cli".to_string()]),
        None,
        #[cfg(feature = "git-diff")]
        None,
        #[cfg(feature = "git-diff")]
        None,
        false,
        None,
        &[],
        &[],
        #[cfg(feature = "_transforms")]
        &[],
        #[cfg(feature = "_transforms")]
        false,
        #[cfg(feature = "_workspace")]
        None, // workspace_type filter
        OutputType::Json,
    )
    .await;

    assert!(result.is_ok());
    let json: Vec<serde_json::Value> = serde_json::from_str(&result.unwrap()).unwrap();

    // Collect unique package names - web has multiple configs (frontend-build, ssr-build)
    let package_names: HashSet<String> = json
        .iter()
        .map(|config| config["name"].as_str().unwrap().to_string())
        .collect();

    assert_eq!(package_names.len(), 4); // api, cli, frontend-build, ssr-build
    assert!(package_names.contains("api"));
    assert!(package_names.contains("frontend-build") || package_names.contains("ssr-build"));
    assert!(package_names.contains("cli"));

    // Should NOT contain other packages
    assert!(!package_names.contains("core"));
    assert!(!package_names.contains("models"));
    assert!(!package_names.contains("shared-utils"));
}

#[cfg(feature = "cargo-workspace")]
#[switchy_async::test]
async fn test_packages_filter_empty_list() {
    // Test with empty packages list (should process all packages)
    let (temp_dir, _) = load_test_workspace("complex");
    let result_empty = handle_features_command(
        temp_dir.path().to_str().unwrap(),
        None,
        None,
        None,
        None,
        None,
        false,
        false,
        None,
        None,
        None,
        None,
        Some(&[]), // Empty list
        None,
        #[cfg(feature = "git-diff")]
        None,
        #[cfg(feature = "git-diff")]
        None,
        false,
        None,
        &[],
        &[],
        #[cfg(feature = "_transforms")]
        &[],
        #[cfg(feature = "_transforms")]
        false,
        #[cfg(feature = "_workspace")]
        None, // workspace_type filter
        OutputType::Json,
    )
    .await;

    let result_none = handle_features_command(
        temp_dir.path().to_str().unwrap(),
        None,
        None,
        None,
        None,
        None,
        false,
        false,
        None,
        None,
        None,
        None,
        None, // No packages specified
        None,
        #[cfg(feature = "git-diff")]
        None,
        #[cfg(feature = "git-diff")]
        None,
        false,
        None,
        &[],
        &[],
        #[cfg(feature = "_transforms")]
        &[],
        #[cfg(feature = "_transforms")]
        false,
        #[cfg(feature = "_workspace")]
        None, // workspace_type filter
        OutputType::Json,
    )
    .await;

    // Both should process all packages
    assert!(result_empty.is_ok());
    assert!(result_none.is_ok());

    let json_empty: Vec<serde_json::Value> = serde_json::from_str(&result_empty.unwrap()).unwrap();
    let json_none: Vec<serde_json::Value> = serde_json::from_str(&result_none.unwrap()).unwrap();

    // Should have processed all packages (6 base packages + web has 2 configs = 7 total configs, but we check unique names)
    let package_names: HashSet<String> = json_none
        .iter()
        .map(|config| config["name"].as_str().unwrap().to_string())
        .collect();
    assert_eq!(package_names.len(), 7); // 6 base packages + frontend-build + ssr-build

    // Empty list and None should produce the same result
    assert_eq!(json_empty.len(), json_none.len());
}

#[cfg(feature = "cargo-workspace")]
#[switchy_async::test]
async fn test_packages_with_os_filter() {
    // Test combining --packages with --os
    let (temp_dir, _) = load_test_workspace("complex");
    let result = handle_features_command(
        temp_dir.path().to_str().unwrap(),
        Some("ubuntu"), // os filter
        None,
        None,
        None,
        None,
        false,
        false,
        None,
        None,
        None,
        None,
        Some(&["api".to_string(), "web".to_string()]),
        None,
        #[cfg(feature = "git-diff")]
        None,
        #[cfg(feature = "git-diff")]
        None,
        false,
        None,
        &[],
        &[],
        #[cfg(feature = "_transforms")]
        &[],
        #[cfg(feature = "_transforms")]
        false,
        #[cfg(feature = "_workspace")]
        None, // workspace_type filter
        OutputType::Json,
    )
    .await;

    assert!(result.is_ok());
    let json: Vec<serde_json::Value> = serde_json::from_str(&result.unwrap()).unwrap();

    // All configs should be for ubuntu and only for api/web packages
    for config in &json {
        assert_eq!(config["os"], "ubuntu");
        let name = config["name"].as_str().unwrap();
        assert!(name == "api" || name == "web" || name == "frontend-build" || name == "ssr-build");
    }
}

#[cfg(feature = "cargo-workspace")]
#[switchy_async::test]
async fn test_packages_with_chunking() {
    // Test combining --packages with --chunked
    let (temp_dir, _) = load_test_workspace("complex");
    let result = handle_features_command(
        temp_dir.path().to_str().unwrap(),
        None,
        None,
        None,
        None,
        Some(2), // chunked
        false,
        false,
        None,
        None,
        None,
        None,
        Some(&["web".to_string()]), // Package with multiple features
        None,
        #[cfg(feature = "git-diff")]
        None,
        #[cfg(feature = "git-diff")]
        None,
        false,
        None,
        &[],
        &[],
        #[cfg(feature = "_transforms")]
        &[],
        #[cfg(feature = "_transforms")]
        false,
        #[cfg(feature = "_workspace")]
        None, // workspace_type filter
        OutputType::Json,
    )
    .await;

    assert!(result.is_ok());
    let json: Vec<serde_json::Value> = serde_json::from_str(&result.unwrap()).unwrap();

    // Web package should be processed (it has chunked=2 in clippier.toml)
    for config in &json {
        let name = config["name"].as_str().unwrap();
        assert!(
            name == "frontend-build" || name == "ssr-build",
            "Should only have web package configs"
        );
        let features = config["features"].as_array();
        if let Some(features) = features {
            assert!(
                !features.is_empty(),
                "Each config should have at least one feature"
            );
        }
    }
}

#[cfg(feature = "cargo-workspace")]
#[switchy_async::test]
async fn test_packages_with_features_filter() {
    // Test combining --packages with --features and --skip-features
    let (temp_dir, _) = load_test_workspace("complex");
    let result = handle_features_command(
        temp_dir.path().to_str().unwrap(),
        None,
        None,
        None,
        None,
        None,
        false,
        false,
        None,
        Some("default"),  // specific feature
        Some("advanced"), // skip feature
        None,
        Some(&["web".to_string()]),
        None,
        #[cfg(feature = "git-diff")]
        None,
        #[cfg(feature = "git-diff")]
        None,
        false,
        None,
        &[],
        &[],
        #[cfg(feature = "_transforms")]
        &[],
        #[cfg(feature = "_transforms")]
        false,
        #[cfg(feature = "_workspace")]
        None, // workspace_type filter
        OutputType::Json,
    )
    .await;

    assert!(result.is_ok());
    let json: Vec<serde_json::Value> = serde_json::from_str(&result.unwrap()).unwrap();

    for config in &json {
        let name = config["name"].as_str().unwrap();
        assert!(
            name == "frontend-build" || name == "ssr-build",
            "Should only have web package configs"
        );
        let features = config["features"].as_array();
        // Features might be empty depending on the config
        if let Some(_features) = features {
            // Just verify it's an array - feature filtering might result in different features
        }
    }
}

#[cfg(feature = "cargo-workspace")]
#[switchy_async::test]
async fn test_packages_nonexistent_package() {
    // Test with package name that doesn't exist
    let (temp_dir, _) = load_test_workspace("complex");
    let result = handle_features_command(
        temp_dir.path().to_str().unwrap(),
        None,
        None,
        None,
        None,
        None,
        false,
        false,
        None,
        None,
        None,
        None,
        Some(&["nonexistent_package".to_string()]),
        None,
        #[cfg(feature = "git-diff")]
        None,
        #[cfg(feature = "git-diff")]
        None,
        false,
        None,
        &[],
        &[],
        #[cfg(feature = "_transforms")]
        &[],
        #[cfg(feature = "_transforms")]
        false,
        #[cfg(feature = "_workspace")]
        None, // workspace_type filter
        OutputType::Json,
    )
    .await;

    assert!(result.is_ok());
    let json: Vec<serde_json::Value> = serde_json::from_str(&result.unwrap()).unwrap();

    // Should return empty array since package doesn't exist
    assert_eq!(json.len(), 0);
}

#[cfg(feature = "cargo-workspace")]
#[switchy_async::test]
async fn test_packages_mixed_valid_invalid() {
    // Test with mix of valid and invalid package names
    let (temp_dir, _) = load_test_workspace("complex");
    let result = handle_features_command(
        temp_dir.path().to_str().unwrap(),
        None,
        None,
        None,
        None,
        None,
        false,
        false,
        None,
        None,
        None,
        None,
        Some(&[
            "api".to_string(),
            "nonexistent".to_string(),
            "web".to_string(),
            "fake_package".to_string(),
        ]),
        None,
        #[cfg(feature = "git-diff")]
        None,
        #[cfg(feature = "git-diff")]
        None,
        false,
        None,
        &[],
        &[],
        #[cfg(feature = "_transforms")]
        &[],
        #[cfg(feature = "_transforms")]
        false,
        #[cfg(feature = "_workspace")]
        None, // workspace_type filter
        OutputType::Json,
    )
    .await;

    assert!(result.is_ok());
    let json: Vec<serde_json::Value> = serde_json::from_str(&result.unwrap()).unwrap();

    // Should only contain configs for valid packages
    let package_names: HashSet<String> = json
        .iter()
        .map(|config| config["name"].as_str().unwrap().to_string())
        .collect();

    assert!(package_names.contains("api"));
    assert!(package_names.contains("frontend-build") || package_names.contains("ssr-build"));
    assert!(!package_names.contains("nonexistent"));
    assert!(!package_names.contains("fake_package"));
    assert!(package_names.len() >= 2); // At least api + web configs
}

#[cfg(feature = "cargo-workspace")]
#[switchy_async::test]
async fn test_packages_case_sensitivity() {
    // Test that package names are case-sensitive
    let (temp_dir, _) = load_test_workspace("complex");
    let result = handle_features_command(
        temp_dir.path().to_str().unwrap(),
        None,
        None,
        None,
        None,
        None,
        false,
        false,
        None,
        None,
        None,
        None,
        Some(&["API".to_string(), "Web".to_string()]), // Wrong case
        None,
        #[cfg(feature = "git-diff")]
        None,
        #[cfg(feature = "git-diff")]
        None,
        false,
        None,
        &[],
        &[],
        #[cfg(feature = "_transforms")]
        &[],
        #[cfg(feature = "_transforms")]
        false,
        #[cfg(feature = "_workspace")]
        None, // workspace_type filter
        OutputType::Json,
    )
    .await;

    assert!(result.is_ok());
    let json: Vec<serde_json::Value> = serde_json::from_str(&result.unwrap()).unwrap();

    // Should not find packages with wrong case
    assert_eq!(json.len(), 0);
}

#[cfg(feature = "cargo-workspace")]
#[switchy_async::test]
async fn test_packages_raw_output_format() {
    // Test that --packages works with Raw output format
    let (temp_dir, _) = load_test_workspace("complex");
    let result = handle_features_command(
        temp_dir.path().to_str().unwrap(),
        None,
        None,
        None,
        None,
        None,
        false,
        false,
        None,
        None,
        None,
        None,
        Some(&["api".to_string()]),
        None,
        #[cfg(feature = "git-diff")]
        None,
        #[cfg(feature = "git-diff")]
        None,
        false,
        None,
        &[],
        &[],
        #[cfg(feature = "_transforms")]
        &[],
        #[cfg(feature = "_transforms")]
        false,
        #[cfg(feature = "_workspace")]
        None, // workspace_type filter
        OutputType::Raw,
    )
    .await;

    assert!(result.is_ok());
    let output = result.unwrap();

    // Should have raw output (feature combinations separated by newlines)
    assert!(!output.is_empty());
    // Each line should be a feature combination
    for line in output.lines() {
        assert!(!line.is_empty());
    }
}