Skip to content

Commit de7285a

Browse files
authored
Allow running Clippy lints via infra (#626)
...but don't error when it fails. This should help us prepare to gradually adopt the linter and fix the relevant reported lints. Part of #155 EDIT: This runs the lint command as usual and we control which lints we warn against, so that we can gradually migrate.
1 parent 18f590f commit de7285a

File tree

4 files changed

+99
-2
lines changed

4 files changed

+99
-2
lines changed

.cargo/config.toml

+81-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,84 @@ incremental = true
66
lto = true
77

88
[build]
9-
rustflags = ["--warn", "unused_crate_dependencies"]
9+
rustflags = [
10+
"--warn",
11+
"unused_crate_dependencies",
12+
# This is a list of allowed Clippy rules for the purposes of gradual migration.
13+
# See https://github.com/NomicFoundation/slang/pull/626
14+
"-A",
15+
"clippy::bool_assert_comparison",
16+
"-A",
17+
"clippy::borrow_interior_mutable_const",
18+
"-A",
19+
"clippy::cmp_owned",
20+
"-A",
21+
"clippy::collapsible_if",
22+
"-A",
23+
"clippy::comparison_chain",
24+
"-A",
25+
"clippy::declare_interior_mutable_const",
26+
"-A",
27+
"clippy::enum_variant_names",
28+
"-A",
29+
"clippy::expect_fun_call",
30+
"-A",
31+
"clippy::explicit_auto_deref",
32+
"-A",
33+
"clippy::from_over_into",
34+
"-A",
35+
"clippy::inherent_to_string",
36+
"-A",
37+
"clippy::into_iter_on_ref",
38+
"-A",
39+
"clippy::len_without_is_empty",
40+
"-A",
41+
"clippy::len_zero",
42+
"-A",
43+
"clippy::manual_range_contains",
44+
"-A",
45+
"clippy::match_like_matches_macro",
46+
"-A",
47+
"clippy::needless_borrow",
48+
"-A",
49+
"clippy::needless_range_loop",
50+
"-A",
51+
"clippy::needless_return",
52+
"-A",
53+
"clippy::new_without_default",
54+
"-A",
55+
"clippy::println_empty_string",
56+
"-A",
57+
"clippy::ptr_arg",
58+
"-A",
59+
"clippy::redundant_closure",
60+
"-A",
61+
"clippy::redundant_pattern",
62+
"-A",
63+
"clippy::redundant_pattern_matching",
64+
"-A",
65+
"clippy::redundant_static_lifetimes",
66+
"-A",
67+
"clippy::should_implement_trait",
68+
"-A",
69+
"clippy::single_char_add_str",
70+
"-A",
71+
"clippy::single_char_pattern",
72+
"-A",
73+
"clippy::to_string_in_format_args",
74+
"-A",
75+
"clippy::upper_case_acronyms",
76+
"-A",
77+
"clippy::useless_asref",
78+
"-A",
79+
"clippy::useless_conversion",
80+
"-A",
81+
"clippy::useless_format",
82+
"-A",
83+
"clippy::write_literal",
84+
"-A",
85+
"clippy::writeln_empty_string",
86+
"-A",
87+
"clippy::wrong_self_convention",
88+
89+
]

.vscode/settings.json

+2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"**/generated/**": true
88
},
99
"rust-analyzer.check.allTargets": true,
10+
"rust-analyzer.check.command": "clippy",
1011
"rust-analyzer.check.features": "all",
12+
"rust-analyzer.checkOnSave": true,
1113
"rust-analyzer.server.path": "${workspaceFolder}/bin/rust-analyzer",
1214
"search.exclude": {
1315
// Packages and Dependencies

crates/infra/cli/generated/infra.zsh-completions

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/infra/cli/src/commands/lint/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ impl LintController {
2525

2626
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, ValueEnum)]
2727
enum LintCommand {
28+
/// Lints all Rust source files.
29+
// Automatically applied lints may need to be formatted again, so we run this before formatting.
30+
Clippy,
2831
/// Format all Rust source files.
2932
CargoFmt,
3033
/// Check for spelling issues in Markdown files.
@@ -48,6 +51,7 @@ impl OrderedCommand for LintCommand {
4851
Terminal::step(format!("lint {name}", name = self.clap_name()));
4952

5053
return match self {
54+
LintCommand::Clippy => run_clippy(),
5155
LintCommand::CargoFmt => run_cargo_fmt(),
5256
LintCommand::Cspell => run_cspell(),
5357
LintCommand::Prettier => run_prettier(),
@@ -60,6 +64,16 @@ impl OrderedCommand for LintCommand {
6064
}
6165
}
6266

67+
fn run_clippy() -> Result<()> {
68+
let mut clippy = Command::new("cargo").flag("clippy").flag("--");
69+
70+
if GitHub::is_running_in_ci() {
71+
clippy = clippy.property("-D", "warnings");
72+
}
73+
74+
clippy.run()
75+
}
76+
6377
fn run_cargo_fmt() -> Result<()> {
6478
let mut command = Command::new("cargo-fmt").flag("--all").flag("--verbose");
6579

0 commit comments

Comments
 (0)