diff --git a/.cargo/config.toml b/.cargo/config.toml index 5b27f3b6a..70299ad43 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -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", + +] diff --git a/.vscode/settings.json b/.vscode/settings.json index 62c552abe..6fbeec0de 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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 diff --git a/crates/infra/cli/generated/infra.zsh-completions b/crates/infra/cli/generated/infra.zsh-completions index bd1594f6d..a68dae217 100644 --- a/crates/infra/cli/generated/infra.zsh-completions +++ b/crates/infra/cli/generated/infra.zsh-completions @@ -59,7 +59,8 @@ npm\:"Run '\''test'\'' scripts in each NPM package in the repository"))' \ _arguments "${_arguments_options[@]}" \ '-h[Print help (see more with '\''--help'\'')]' \ '--help[Print help (see more with '\''--help'\'')]' \ -'*::commands:((cargo-fmt\:"Format all Rust source files" +'*::commands:((clippy\:"Lints all Rust source files" +cargo-fmt\:"Format all Rust source files" cspell\:"Check for spelling issues in Markdown files" prettier\:"Format all non-Rust source files" markdown-link-check\:"Check for broken links in Markdown files" diff --git a/crates/infra/cli/src/commands/lint/mod.rs b/crates/infra/cli/src/commands/lint/mod.rs index d9fda491f..7d2b998af 100644 --- a/crates/infra/cli/src/commands/lint/mod.rs +++ b/crates/infra/cli/src/commands/lint/mod.rs @@ -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. @@ -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(), @@ -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");