This package provides a unified linting framework that can be easily integrated into any Rust project.
- Multiple Linters: Supports markdown, YAML, TOML, Rust (clippy + rustfmt), and shell script linting
- CLI Ready: Pre-built CLI components for easy binary creation
- Extensible: Easy to add new linters
- Configurable: Uses existing configuration files (.taplo.toml, .yamllint.yml, etc.)
Create a simple binary that uses the complete CLI:
// src/bin/linter.rs
use anyhow::Result;
fn main() -> Result<()> {
torrust_linting::run_cli()
}This gives you a full-featured linter CLI with all commands and help text.
For more control, you can use the individual components:
use anyhow::Result;
use clap::Parser;
use torrust_linting::{Cli, execute_command, init_tracing};
fn main() -> Result<()> {
init_tracing();
let cli = Cli::parse();
execute_command(cli.command)?;
Ok(())
}Use specific linters programmatically:
use anyhow::Result;
use torrust_linting::{run_rustfmt_linter, run_clippy_linter, run_all_linters};
fn main() -> Result<()> {
// Run individual linters
run_rustfmt_linter()?;
run_clippy_linter()?;
// Or run all linters at once
run_all_linters()?;
Ok(())
}Build your own CLI with custom commands:
use anyhow::Result;
use clap::{Parser, Subcommand};
use torrust_linting::{run_rustfmt_linter, run_clippy_linter};
#[derive(Parser)]
struct MyCli {
#[command(subcommand)]
command: MyCommands,
}
#[derive(Subcommand)]
enum MyCommands {
/// Check Rust formatting
Format,
/// Run Rust linting
Lint,
}
fn main() -> Result<()> {
let cli = MyCli::parse();
match cli.command {
MyCommands::Format => run_rustfmt_linter()?,
MyCommands::Lint => run_clippy_linter()?,
}
Ok(())
}Add to your Cargo.toml:
[dependencies]
torrust-linting = { path = "path/to/torrust-linting" }Or if using in a workspace:
[workspace]
members = ["packages/torrust-linting"]
[dependencies]
torrust-linting = { path = "packages/torrust-linting" }- Markdown: Uses markdownlint-cli
- YAML: Uses yamllint
- TOML: Uses taplo
- Rust Clippy: Uses cargo clippy
- Rust Format: Uses cargo fmt
- Shell: Uses shellcheck
The linting package respects existing configuration files:
.taplo.tomlfor TOML formatting.yamllint.ymlfor YAML linting.markdownlint.jsonfor Markdown linting- Standard Rust tooling configuration for clippy and rustfmt