Skip to content

Commit 7373f00

Browse files
authored
feat(config): add enforce-all flag (#44)
1 parent 05a147a commit 7373f00

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LINTSPEC_CONSTRUCTOR=false # enforce that constructors have natspec
55
LINTSPEC_STRUCT_PARAMS=false # enforce that structs have `@param` for each member
66
LINTSPEC_ENUM_PARAMS=false # enforce that enums have `@param` for each variant
77
LINTSPEC_ENFORCE=[variable,struct] # enforce NatSpec on items even if they don't have params/returns/members
8+
LINTSPEC_ENFORCE_ALL=true # same as passing all possible values to `enforce`. Remove if using LINTSPEC_ENFORCE.
89
LINTSPEC_JSON=false # output diagnostics as JSON
910
LINTSPEC_COMPACT=false # compact output (minified JSON or compact text)
1011
LINTSPEC_SORT=false # sort results by file path

.lintspec.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ struct_params = false # enforce that structs have `@param` for each member
77
enum_params = false # enforce that enums have `@param` for each variant
88
# enforce NatSpec on items even if they don't have params/returns/members. Possible values: constructor, enum, error, event, function, modifier, struct, variable
99
enforce = ["variable", "struct"]
10+
enforce_all = true # same as passing all possible values to `enforce`. Remove if using `enforce`.
1011
json = false # output diagnostics as JSON
1112
compact = false # compact output (minified JSON or compact text)
1213
sort = false # sort results by file path

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Options:
7676
--enum-params Enforce that enums have `@param` for each variant
7777
-f, --enforce <TYPE> Enforce NatSpec on items even if they don't have params/returns/members (can be used more than once)
7878
[possible values: constructor, enum, error, event, function, modifier, struct, variable]
79+
--enforce-all Enforce NatSpec for all item types, even if they don't have params/returns/members
7980
--json Output diagnostics in JSON format
8081
--compact Compact output
8182
--sort Sort the results by file path

src/config.rs

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::PathBuf;
22

33
use anyhow::Result;
4-
use clap::Parser;
4+
use clap::{Parser, ValueEnum};
55
use figment::{
66
providers::{Env, Format as _, Serialized, Toml},
77
Figment,
@@ -56,11 +56,20 @@ pub struct Args {
5656
#[arg(long, num_args = 0..=1, default_missing_value = "true")]
5757
pub enum_params: Option<bool>,
5858

59-
/// Enforce NatSpec (@dev, @notice) on items even if they don't have params/returns/members
59+
/// Enforce NatSpec on items even if they don't have params/returns/members
6060
/// (can be used more than once)
61+
///
62+
/// To enforce for all types, you can use `--enforce-all`.
6163
#[arg(short = 'f', long, name = "TYPE")]
6264
pub enforce: Vec<ItemType>,
6365

66+
/// Enforce NatSpec for all item types, even if they don't have params/returns/members
67+
///
68+
/// Setting this option overrides any previously set `--enforce` arguments.
69+
/// Can be set with `--enforce-all` (means true), `--enforce-all true` or `--enforce-all false`.
70+
#[arg(long, num_args = 0..=1, default_missing_value = "true")]
71+
pub enforce_all: Option<bool>,
72+
6473
/// Output diagnostics in JSON format
6574
///
6675
/// Can be set with `--json` (means true), `--json true` or `--json false`.
@@ -129,6 +138,7 @@ pub fn read_config() -> Result<Config> {
129138
struct_params: None,
130139
enum_params: None,
131140
enforce: args.enforce,
141+
enforce_all: None,
132142
json: None,
133143
compact: None,
134144
sort: None,
@@ -151,6 +161,22 @@ pub fn read_config() -> Result<Config> {
151161
if let Some(enum_params) = args.enum_params {
152162
temp.enum_params = Some(enum_params);
153163
}
164+
// first look if enforce_all was set in a config file or env variable
165+
if let Some(enforce_all) = temp.enforce_all {
166+
if enforce_all {
167+
temp.enforce = ItemType::value_variants().into();
168+
} else {
169+
temp.enforce = vec![];
170+
}
171+
}
172+
// then look if it was set in the CLI args
173+
if let Some(enforce_all) = args.enforce_all {
174+
if enforce_all {
175+
temp.enforce = ItemType::value_variants().into();
176+
} else {
177+
temp.enforce = vec![];
178+
}
179+
}
154180
if let Some(json) = args.json {
155181
temp.json = Some(json);
156182
}

0 commit comments

Comments
 (0)