Skip to content

Commit ee02f55

Browse files
authored
feat(cli)!: make documenting struct members optional (#32)
The default behavior has changed. Whereas before, struct members had to be documented with `@param`, this is now optional and controlled with the new `--struct-params` argument.
1 parent 9297293 commit ee02f55

File tree

7 files changed

+50
-19
lines changed

7 files changed

+50
-19
lines changed

.env.example

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
LINTSPEC_PATHS=[path/to/file.sol,path/to/dir] # paths to files and folders to analyze
22
LINTSPEC_EXCLUDE=[path/to/ignore] # paths to files or folders to exclude, see also `.nsignore`
3-
LINTSPEC_INHERITDOC=true # enforce that all overridden, public and external items have `@inheritdoc`
4-
LINTSPEC_CONSTRUCTOR=false # enforce that constructors have natspec
5-
LINTSPEC_ENUM_PARAMS=false # enforce that enums have `@param` for each variant
6-
LINTSPEC_JSON=false # output diagnostics as JSON
7-
LINTSPEC_COMPACT=false # compact output (minified JSON or compact text)
3+
LINTSPEC_INHERITDOC=true # enforce that all overridden, public and external items have `@inheritdoc`
4+
LINTSPEC_CONSTRUCTOR=false # enforce that constructors have natspec
5+
LINTSPEC_STRUCT_PARAMS=false # enforce that structs have `@param` for each member
6+
LINTSPEC_ENUM_PARAMS=false # enforce that enums have `@param` for each variant
7+
LINTSPEC_JSON=false # output diagnostics as JSON
8+
LINTSPEC_COMPACT=false # compact output (minified JSON or compact text)

.lintspec.toml

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
paths = [] # paths to files and folders to analyze
2-
exclude = [] # paths to files or folders to exclude, see also `.nsignore`
3-
out = "" # if provided, redirects output to this file
4-
inheritdoc = true # enforce that all overridden, public and external items have `@inheritdoc`
5-
constructor = false # enforce that constructors have natspec
6-
enum_params = false # enforce that enums have `@param` for each variant
7-
json = false # output diagnostics as JSON
8-
compact = false # compact output (minified JSON or compact text)
1+
paths = [] # paths to files and folders to analyze
2+
exclude = [] # paths to files or folders to exclude, see also `.nsignore`
3+
out = "" # if provided, redirects output to this file
4+
inheritdoc = true # enforce that all overridden, public and external items have `@inheritdoc`
5+
constructor = false # enforce that constructors have natspec
6+
struct_params = false # enforce that structs have `@param` for each member
7+
enum_params = false # enforce that enums have `@param` for each variant
8+
json = false # output diagnostics as JSON
9+
compact = false # compact output (minified JSON or compact text)

README.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Options:
7272
-o, --out <OUT> Write output to a file instead of stderr
7373
--inheritdoc Enforce that all public and external items have `@inheritdoc`
7474
--constructor Enforce that constructors have NatSpec
75+
--struct-params Enforce that structs have `@param` for each member
7576
--enum-params Enforce that enums have `@param` for each variant
7677
--json Output diagnostics in JSON format
7778
--compact Compact output
@@ -121,7 +122,12 @@ jobs:
121122
steps:
122123
- uses: actions/checkout@v2
123124
- uses: beeb/lintspec@main
125+
# all the lines below are optional
124126
with:
127+
working-directory: "./"
128+
paths: "[]"
129+
exclude: "[]"
130+
extra-args: ""
125131
version: "latest"
126132
fail-on-problem: "true"
127133
```
@@ -168,11 +174,11 @@ Summary
168174
| Enforce usage of `@inheritdoc` | ✅ | ✅ |
169175
| Enforce NatSpec on constructors | ✅ | ✅ |
170176
| Configure via config file | ✅ | ✅ |
171-
| Enforce NatSpec on enums | ✅ | ❌ |
177+
| Configure via env variables | ✅ | ❌ |
172178
| Respects gitignore files | ✅ | ❌ |
173-
| JSON output | ✅ | ❌ |
179+
| Enforce NatSpec on enums | ✅ | ❌ |
174180
| Pretty output with code excerpt | ✅ | ❌ |
181+
| JSON output | ✅ | ❌ |
175182
| Output to file | ✅ | ❌ |
176-
| Configure via env variables | ✅ | ❌ |
177183
| Multithreaded | ✅ | ❌ |
178-
| No pre-requisites (npm) | ✅ | ❌ |
184+
| No pre-requisites (node/npm) | ✅ | ❌ |

src/config.rs

+12
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ pub struct Args {
4242
#[arg(long, num_args = 0..=1, default_missing_value = "true")]
4343
pub constructor: Option<bool>,
4444

45+
/// Enforce that structs have `@param` for each member
46+
///
47+
/// Can be set with `--struct_params` (means true), `--struct_params true` or `--struct_params false`.
48+
#[arg(long, num_args = 0..=1, default_missing_value = "true")]
49+
pub struct_params: Option<bool>,
50+
4551
/// Enforce that enums have `@param` for each variant
4652
///
4753
/// Can be set with `--enum_params` (means true), `--enum_params true` or `--enum_params false`.
@@ -72,6 +78,7 @@ pub struct Config {
7278
pub out: Option<PathBuf>,
7379
pub inheritdoc: bool,
7480
pub constructor: bool,
81+
pub struct_params: bool,
7582
pub enum_params: bool,
7683
pub json: bool,
7784
pub compact: bool,
@@ -85,6 +92,7 @@ impl From<Args> for Config {
8592
out: value.out,
8693
inheritdoc: value.inheritdoc.unwrap_or(true),
8794
constructor: value.constructor.unwrap_or_default(),
95+
struct_params: value.enum_params.unwrap_or_default(),
8896
enum_params: value.enum_params.unwrap_or_default(),
8997
json: value.json.unwrap_or_default(),
9098
compact: value.compact.unwrap_or_default(),
@@ -101,6 +109,7 @@ pub fn read_config() -> Result<Config> {
101109
out: None,
102110
inheritdoc: None,
103111
constructor: None,
112+
struct_params: None,
104113
enum_params: None,
105114
json: None,
106115
compact: None,
@@ -117,6 +126,9 @@ pub fn read_config() -> Result<Config> {
117126
if let Some(constructor) = args.constructor {
118127
temp.constructor = Some(constructor);
119128
}
129+
if let Some(struct_params) = args.struct_params {
130+
temp.struct_params = Some(struct_params);
131+
}
120132
if let Some(enum_params) = args.enum_params {
121133
temp.enum_params = Some(enum_params);
122134
}

src/definitions/constructor.rs

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ mod tests {
106106
static OPTIONS: ValidationOptions = ValidationOptions {
107107
inheritdoc: false,
108108
constructor: true,
109+
struct_params: false,
109110
enum_params: false,
110111
};
111112

src/definitions/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ pub struct ValidationOptions {
5454
/// Whether to check that constructors have documented params
5555
pub constructor: bool,
5656

57+
/// Whether to check that each member of structs is documented with `@param`
58+
///
59+
/// Not standard practice, the Solidity spec does not consider `@param` for structs or provide any other way to
60+
/// document each member.
61+
pub struct_params: bool,
62+
5763
/// Whether to check that each variant of enums is documented with `@param`
5864
///
5965
/// Not standard practice, the Solidity spec does not consider `@param` for enums or provide any other way to
@@ -67,6 +73,7 @@ impl Default for ValidationOptions {
6773
Self {
6874
inheritdoc: true,
6975
constructor: false,
76+
struct_params: false,
7077
enum_params: false,
7178
}
7279
}
@@ -77,6 +84,7 @@ impl From<&Config> for ValidationOptions {
7784
Self {
7885
inheritdoc: value.inheritdoc,
7986
constructor: value.constructor,
87+
struct_params: value.struct_params,
8088
enum_params: value.enum_params,
8189
}
8290
}

src/definitions/structure.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl Validate for StructDefinition {
6767
.into())
6868
}
6969

70-
fn validate(&self, _: &ValidationOptions) -> ItemDiagnostics {
70+
fn validate(&self, options: &ValidationOptions) -> ItemDiagnostics {
7171
let mut out = ItemDiagnostics {
7272
parent: self.parent(),
7373
item_type: ItemType::Struct,
@@ -83,7 +83,9 @@ impl Validate for StructDefinition {
8383
});
8484
return out;
8585
};
86-
out.diags.append(&mut check_params(natspec, &self.members));
86+
if options.struct_params {
87+
out.diags = check_params(natspec, &self.members);
88+
}
8789
out
8890
}
8991
}

0 commit comments

Comments
 (0)