Skip to content

Commit

Permalink
move lints outside infra check (#1219)
Browse files Browse the repository at this point in the history
`infra check` was doing so much that isn't directly related to updating
generated files. Moved to linting instead. Local REPL is much faster
now.
  • Loading branch information
OmarTawfik authored Jan 16, 2025
1 parent 6389361 commit 6763527
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
26 changes: 1 addition & 25 deletions crates/infra/cli/src/commands/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use infra_utils::terminal::Terminal;
use rayon::iter::{ParallelBridge, ParallelIterator};
use strum::IntoEnumIterator;

use crate::toolchains::mkdocs::Mkdocs;
use crate::toolchains::wasm::WasmPackage;
use crate::utils::{ClapExtensions, OrderedCommand};

Expand All @@ -26,12 +25,8 @@ impl CheckController {
enum CheckCommand {
/// Run 'cargo check' for all crates, features, and targets.
Cargo,
/// Run `cargo doc` to generate Rustdoc documentation and check for any broken links.
Rustdoc,
/// Check NPM packages for any outdated codegen steps.
Npm,
/// Check mkdocs documentation for any build issues or broken links.
Mkdocs,
}

impl OrderedCommand for CheckCommand {
Expand All @@ -40,34 +35,19 @@ impl OrderedCommand for CheckCommand {

match self {
CheckCommand::Cargo => check_cargo(),
CheckCommand::Rustdoc => check_rustdoc(),
CheckCommand::Npm => check_npm(),
CheckCommand::Mkdocs => check_mkdocs(),
};

Ok(())
}
}

fn check_cargo() {
// 'cargo clippy' will run both 'cargo check', and 'clippy' lints:
Command::new("cargo")
.arg("clippy")
.arg("check")
.flag("--workspace")
.flag("--all-features")
.flag("--all-targets")
.flag("--no-deps")
.add_build_rustflags()
.run();
}

fn check_rustdoc() {
Command::new("cargo")
.arg("doc")
.flag("--workspace")
.flag("--all-features")
.flag("--no-deps")
.flag("--document-private-items")
.add_build_rustflags()
.run();
}
Expand All @@ -77,7 +57,3 @@ fn check_npm() {
.par_bridge()
.for_each(|package| package.build().unwrap());
}

fn check_mkdocs() {
Mkdocs::check();
}
37 changes: 37 additions & 0 deletions crates/infra/cli/src/commands/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ use std::path::Path;

use anyhow::Result;
use clap::{Parser, ValueEnum};
use infra_utils::cargo::CargoWorkspaceCommands;
use infra_utils::commands::Command;
use infra_utils::github::GitHub;
use infra_utils::paths::{FileWalker, PathExtensions};
use infra_utils::terminal::Terminal;

use crate::toolchains::mkdocs::Mkdocs;
use crate::toolchains::pipenv::PipEnv;
use crate::utils::{ClapExtensions, OrderedCommand};

Expand All @@ -24,6 +26,12 @@ impl LintController {

#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, ValueEnum)]
enum LintCommand {
/// Run `cargo clippy` to check for any Rust lints.
Clippy,
/// Run `cargo doc` to generate Rustdoc documentation and check for any broken links.
Rustdoc,
/// Check mkdocs documentation for any build issues or broken links.
Mkdocs,
/// Check for spelling issues in Markdown files.
Cspell,
/// Format all non-Rust source files.
Expand All @@ -49,6 +57,9 @@ impl OrderedCommand for LintCommand {
Terminal::step(format!("lint {name}", name = self.clap_name()));

match self {
LintCommand::Clippy => run_clippy(),
LintCommand::Rustdoc => run_rustdoc(),
LintCommand::Mkdocs => run_mkdocs(),
LintCommand::Cspell => run_cspell(),
LintCommand::Prettier => run_prettier(),
LintCommand::MarkdownLinkCheck => run_markdown_link_check()?,
Expand All @@ -64,6 +75,32 @@ impl OrderedCommand for LintCommand {
}
}

fn run_clippy() {
Command::new("cargo")
.arg("clippy")
.flag("--workspace")
.flag("--all-features")
.flag("--all-targets")
.flag("--no-deps")
.add_build_rustflags()
.run();
}

fn run_rustdoc() {
Command::new("cargo")
.arg("doc")
.flag("--workspace")
.flag("--all-features")
.flag("--no-deps")
.flag("--document-private-items")
.add_build_rustflags()
.run();
}

fn run_mkdocs() {
Mkdocs::check();
}

fn run_cspell() {
Command::new("cspell")
.arg("lint")
Expand Down

0 comments on commit 6763527

Please sign in to comment.