From 99bdafa7b98e478b5375db2d606409aa29150bcd Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 5 Feb 2022 11:14:48 +0530 Subject: new subcommand: statix-list produces a list of lints with their error codes, handy for statix-explain or configuring the `disabled` array in .statix.toml --- bin/src/config.rs | 5 +++++ bin/src/lib.rs | 1 + bin/src/list.rs | 14 ++++++++++++++ bin/src/main.rs | 6 ++++-- 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 bin/src/list.rs diff --git a/bin/src/config.rs b/bin/src/config.rs index 29b6c9e..0f09618 100644 --- a/bin/src/config.rs +++ b/bin/src/config.rs @@ -31,6 +31,8 @@ pub enum SubCommand { Explain(Explain), /// Dump a sample config to stdout Dump(Dump), + /// List all available lints + List(List), } #[derive(Parser, Debug)] @@ -205,6 +207,9 @@ pub struct Explain { #[derive(Parser, Debug)] pub struct Dump {} +#[derive(Parser, Debug)] +pub struct List {} + #[derive(Debug, Copy, Clone)] pub enum OutFormat { #[cfg(feature = "json")] diff --git a/bin/src/lib.rs b/bin/src/lib.rs index 8200347..e814667 100644 --- a/bin/src/lib.rs +++ b/bin/src/lib.rs @@ -5,6 +5,7 @@ pub mod err; pub mod explain; pub mod fix; pub mod lint; +pub mod list; pub mod session; pub mod traits; diff --git a/bin/src/list.rs b/bin/src/list.rs new file mode 100644 index 0000000..4fe3039 --- /dev/null +++ b/bin/src/list.rs @@ -0,0 +1,14 @@ +pub mod main { + use crate::err::StatixErr; + + use lib::LINTS; + + pub fn main() -> Result<(), StatixErr> { + let mut lints = (&*LINTS).clone(); + lints.as_mut_slice().sort_by(|a, b| a.code().cmp(&b.code())); + for l in lints { + println!("W{:02} {}", l.code(), l.name()); + } + Ok(()) + } +} diff --git a/bin/src/main.rs b/bin/src/main.rs index be79bb8..ebd230e 100644 --- a/bin/src/main.rs +++ b/bin/src/main.rs @@ -1,9 +1,10 @@ use clap::Parser; + +#[rustfmt::skip] use statix::{ config::{Opts, SubCommand}, - dump, err::StatixErr, - explain, fix, lint, + lint, fix, explain, dump, list, }; fn _main() -> Result<(), StatixErr> { @@ -14,6 +15,7 @@ fn _main() -> Result<(), StatixErr> { SubCommand::Single(config) => fix::main::single(config), SubCommand::Explain(config) => explain::main::main(config), SubCommand::Dump(_) => dump::main::main(), + SubCommand::List(_) => list::main::main(), } } -- cgit v1.2.3