Skip to content

Commit a10a697

Browse files
Add clippy-features config option
Allows configuring which features to use for clippy checks in pre-push: - clippy-features = false: run with no extra features - clippy-features = ["feat1", "feat2"]: run with --features feat1,feat2 - (default): run with --all-features This is useful when a workspace has testing-only features (like loom) that change struct layouts and are incompatible with --all-features.
1 parent 5a9496e commit a10a697

1 file changed

Lines changed: 76 additions & 4 deletions

File tree

src/main.rs

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,17 @@ struct FacetDevConfig {
372372

373373
// Pre-push checks
374374
clippy: bool,
375+
/// Features to use for clippy. If None, uses --all-features.
376+
/// If Some(vec), uses --features with the specified features.
377+
/// Use Some(vec![]) to run with no extra features.
378+
clippy_features: Option<Vec<String>>,
375379
nextest: bool,
376380
doc_tests: bool,
381+
/// Features to use for doc tests. If None, uses --all-features.
382+
doc_test_features: Option<Vec<String>>,
377383
docs: bool,
384+
/// Features to use for docs. If None, uses --all-features.
385+
docs_features: Option<Vec<String>>,
378386
cargo_shear: bool,
379387
}
380388

@@ -401,6 +409,28 @@ fn load_facet_dev_config() -> FacetDevConfig {
401409

402410
let get_bool = |key: &str| -> Option<bool> { facet_dev.get(key).and_then(|v| v.as_bool()) };
403411

412+
// Helper to parse feature config: array of strings, or false for no features
413+
let parse_features = |key: &str| -> Option<Vec<String>> {
414+
facet_dev.get(key).and_then(|v| {
415+
if let Some(arr) = v.as_array() {
416+
Some(
417+
arr.iter()
418+
.filter_map(|item| item.as_str().map(String::from))
419+
.collect(),
420+
)
421+
} else if v.as_bool() == Some(false) {
422+
// features = false means use no extra features (empty vec)
423+
Some(vec![])
424+
} else {
425+
None
426+
}
427+
})
428+
};
429+
430+
let clippy_features = parse_features("clippy-features");
431+
let doc_test_features = parse_features("doc-test-features");
432+
let docs_features = parse_features("docs-features");
433+
404434
FacetDevConfig {
405435
// Pre-commit jobs
406436
generate_readmes: get_bool("generate-readmes").unwrap_or(true),
@@ -412,9 +442,12 @@ fn load_facet_dev_config() -> FacetDevConfig {
412442

413443
// Pre-push checks
414444
clippy: get_bool("clippy").unwrap_or(true),
445+
clippy_features,
415446
nextest: get_bool("nextest").unwrap_or(true),
416447
doc_tests: get_bool("doc-tests").unwrap_or(true),
448+
doc_test_features,
417449
docs: get_bool("docs").unwrap_or(true),
450+
docs_features,
418451
cargo_shear: get_bool("cargo-shear").unwrap_or(true),
419452
}
420453
}
@@ -432,9 +465,12 @@ impl Default for FacetDevConfig {
432465

433466
// Pre-push checks
434467
clippy: true,
468+
clippy_features: None, // None means use --all-features
435469
nextest: true,
436470
doc_tests: true,
471+
doc_test_features: None,
437472
docs: true,
473+
docs_features: None,
438474
cargo_shear: true,
439475
}
440476
}
@@ -1754,9 +1790,21 @@ fn run_pre_push() {
17541790
clippy_command.push("-p".to_string());
17551791
clippy_command.push(crate_name.to_string());
17561792
}
1793+
clippy_command.push("--all-targets".to_string());
1794+
// Use configured features, or --all-features if not specified
1795+
match &config.clippy_features {
1796+
None => {
1797+
clippy_command.push("--all-features".to_string());
1798+
}
1799+
Some(features) if !features.is_empty() => {
1800+
clippy_command.push("--features".to_string());
1801+
clippy_command.push(features.join(","));
1802+
}
1803+
Some(_) => {
1804+
// Empty features list means no extra features
1805+
}
1806+
}
17571807
clippy_command.extend(vec![
1758-
"--all-targets".to_string(),
1759-
"--all-features".to_string(),
17601808
"--".to_string(),
17611809
"-D".to_string(),
17621810
"warnings".to_string(),
@@ -1853,7 +1901,19 @@ fn run_pre_push() {
18531901
doctest_command.push("-p".to_string());
18541902
doctest_command.push(crate_name.to_string());
18551903
}
1856-
doctest_command.push("--all-features".to_string());
1904+
// Use configured features, or --all-features if not specified
1905+
match &config.doc_test_features {
1906+
None => {
1907+
doctest_command.push("--all-features".to_string());
1908+
}
1909+
Some(features) if !features.is_empty() => {
1910+
doctest_command.push("--features".to_string());
1911+
doctest_command.push(features.join(","));
1912+
}
1913+
Some(_) => {
1914+
// Empty features list means no extra features
1915+
}
1916+
}
18571917
let doctest_output = run_command_with_streaming(&doctest_command, &[]);
18581918
let elapsed = start.elapsed();
18591919

@@ -1894,7 +1954,19 @@ fn run_pre_push() {
18941954
doc_command.push("-p".to_string());
18951955
doc_command.push(crate_name.to_string());
18961956
}
1897-
doc_command.push("--all-features".to_string());
1957+
// Use configured features, or --all-features if not specified
1958+
match &config.docs_features {
1959+
None => {
1960+
doc_command.push("--all-features".to_string());
1961+
}
1962+
Some(features) if !features.is_empty() => {
1963+
doc_command.push("--features".to_string());
1964+
doc_command.push(features.join(","));
1965+
}
1966+
Some(_) => {
1967+
// Empty features list means no extra features
1968+
}
1969+
}
18981970
let doc_env = [("RUSTDOCFLAGS", "-D warnings")];
18991971
let mut doc_cmd = command_with_color(&doc_command[0]);
19001972
for arg in &doc_command[1..] {

0 commit comments

Comments
 (0)