Skip to content

Commit

Permalink
Allow running Clippy lints via infra (#626)
Browse files Browse the repository at this point in the history
...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.
  • Loading branch information
Xanewok authored Oct 31, 2023
1 parent 18f590f commit de7285a
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 2 deletions.
82 changes: 81 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,84 @@ incremental = true
lto = true

[build]
rustflags = ["--warn", "unused_crate_dependencies"]
rustflags = [
"--warn",
"unused_crate_dependencies",
# This is a list of allowed Clippy rules for the purposes of gradual migration.
# See https://github.com/NomicFoundation/slang/pull/626
"-A",
"clippy::bool_assert_comparison",
"-A",
"clippy::borrow_interior_mutable_const",
"-A",
"clippy::cmp_owned",
"-A",
"clippy::collapsible_if",
"-A",
"clippy::comparison_chain",
"-A",
"clippy::declare_interior_mutable_const",
"-A",
"clippy::enum_variant_names",
"-A",
"clippy::expect_fun_call",
"-A",
"clippy::explicit_auto_deref",
"-A",
"clippy::from_over_into",
"-A",
"clippy::inherent_to_string",
"-A",
"clippy::into_iter_on_ref",
"-A",
"clippy::len_without_is_empty",
"-A",
"clippy::len_zero",
"-A",
"clippy::manual_range_contains",
"-A",
"clippy::match_like_matches_macro",
"-A",
"clippy::needless_borrow",
"-A",
"clippy::needless_range_loop",
"-A",
"clippy::needless_return",
"-A",
"clippy::new_without_default",
"-A",
"clippy::println_empty_string",
"-A",
"clippy::ptr_arg",
"-A",
"clippy::redundant_closure",
"-A",
"clippy::redundant_pattern",
"-A",
"clippy::redundant_pattern_matching",
"-A",
"clippy::redundant_static_lifetimes",
"-A",
"clippy::should_implement_trait",
"-A",
"clippy::single_char_add_str",
"-A",
"clippy::single_char_pattern",
"-A",
"clippy::to_string_in_format_args",
"-A",
"clippy::upper_case_acronyms",
"-A",
"clippy::useless_asref",
"-A",
"clippy::useless_conversion",
"-A",
"clippy::useless_format",
"-A",
"clippy::write_literal",
"-A",
"clippy::writeln_empty_string",
"-A",
"clippy::wrong_self_convention",

]
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"**/generated/**": true
},
"rust-analyzer.check.allTargets": true,
"rust-analyzer.check.command": "clippy",
"rust-analyzer.check.features": "all",
"rust-analyzer.checkOnSave": true,
"rust-analyzer.server.path": "${workspaceFolder}/bin/rust-analyzer",
"search.exclude": {
// Packages and Dependencies
Expand Down
3 changes: 2 additions & 1 deletion crates/infra/cli/generated/infra.zsh-completions

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions crates/infra/cli/src/commands/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ impl LintController {

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

return match self {
LintCommand::Clippy => run_clippy(),
LintCommand::CargoFmt => run_cargo_fmt(),
LintCommand::Cspell => run_cspell(),
LintCommand::Prettier => run_prettier(),
Expand All @@ -60,6 +64,16 @@ impl OrderedCommand for LintCommand {
}
}

fn run_clippy() -> Result<()> {
let mut clippy = Command::new("cargo").flag("clippy").flag("--");

if GitHub::is_running_in_ci() {
clippy = clippy.property("-D", "warnings");
}

clippy.run()
}

fn run_cargo_fmt() -> Result<()> {
let mut command = Command::new("cargo-fmt").flag("--all").flag("--verbose");

Expand Down

0 comments on commit de7285a

Please sign in to comment.