Skip to content

Commit 3ca29cc

Browse files
authored
feat: add option to sort results by file path (#41)
* feat: add option to sort results by file path * chore: add example configs
1 parent 861f472 commit 3ca29cc

File tree

6 files changed

+24
-2
lines changed

6 files changed

+24
-2
lines changed

.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LINTSPEC_STRUCT_PARAMS=false # enforce that structs have `@param` for each membe
66
LINTSPEC_ENUM_PARAMS=false # enforce that enums have `@param` for each variant
77
LINTSPEC_JSON=false # output diagnostics as JSON
88
LINTSPEC_COMPACT=false # compact output (minified JSON or compact text)
9+
LINTSPEC_SORT=false # sort results by file path

.lintspec.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ struct_params = false # enforce that structs have `@param` for each member
77
enum_params = false # enforce that enums have `@param` for each variant
88
json = false # output diagnostics as JSON
99
compact = false # compact output (minified JSON or compact text)
10+
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
--json Output diagnostics in JSON format
7878
--compact Compact output
79+
--sort Sort the results by file path
7980
-h, --help Print help (see more with '--help')
8081
-V, --version Print version
8182
```

src/config.rs

+12
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ pub struct Args {
6767
/// Can be set with `--compact` (means true), `--compact true` or `--compact false`.
6868
#[arg(long, num_args = 0..=1, default_missing_value = "true")]
6969
pub compact: Option<bool>,
70+
71+
/// Sort the results by file path
72+
///
73+
/// Can be set with `--sort` (means true), `--sort true` or `--sort false`.
74+
#[arg(long, num_args = 0..=1, default_missing_value = "true")]
75+
pub sort: Option<bool>,
7076
}
7177

7278
#[derive(Debug, Clone, Serialize, Deserialize, bon::Builder)]
@@ -82,6 +88,7 @@ pub struct Config {
8288
pub enum_params: bool,
8389
pub json: bool,
8490
pub compact: bool,
91+
pub sort: bool,
8592
}
8693

8794
impl From<Args> for Config {
@@ -96,6 +103,7 @@ impl From<Args> for Config {
96103
enum_params: value.enum_params.unwrap_or_default(),
97104
json: value.json.unwrap_or_default(),
98105
compact: value.compact.unwrap_or_default(),
106+
sort: value.sort.unwrap_or_default(),
99107
}
100108
}
101109
}
@@ -113,6 +121,7 @@ pub fn read_config() -> Result<Config> {
113121
enum_params: None,
114122
json: None,
115123
compact: None,
124+
sort: None,
116125
}))
117126
.admerge(Toml::file(".lintspec.toml"))
118127
.admerge(Env::prefixed("LINTSPEC_"))
@@ -138,5 +147,8 @@ pub fn read_config() -> Result<Config> {
138147
if let Some(compact) = args.compact {
139148
temp.compact = Some(compact);
140149
}
150+
if let Some(sort) = args.sort {
151+
temp.sort = Some(sort);
152+
}
141153
Ok(temp.into())
142154
}

src/files.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ use crate::error::{Error, Result};
1414
/// Global git ignore configurations as well as parent folder gitignores are not taken into account.
1515
/// Hidden files are included.
1616
/// Returned paths are canonicalized.
17-
pub fn find_sol_files<T: AsRef<Path>>(paths: &[T], exclude: &[T]) -> Result<Vec<PathBuf>> {
17+
pub fn find_sol_files<T: AsRef<Path>>(
18+
paths: &[T],
19+
exclude: &[T],
20+
sort: bool,
21+
) -> Result<Vec<PathBuf>> {
1822
// canonicalize exclude paths
1923
let exclude = exclude
2024
.iter()
@@ -97,5 +101,8 @@ pub fn find_sol_files<T: AsRef<Path>>(paths: &[T], exclude: &[T]) -> Result<Vec<
97101
while let Ok(path) = rx.recv() {
98102
files.push(path);
99103
}
104+
if sort {
105+
files.sort_unstable();
106+
}
100107
Ok(files)
101108
}

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn main() -> Result<()> {
1414
let config = read_config()?;
1515

1616
// identify Solidity files to parse
17-
let paths = find_sol_files(&config.paths, &config.exclude)?;
17+
let paths = find_sol_files(&config.paths, &config.exclude, config.sort)?;
1818
if paths.is_empty() {
1919
bail!("no Solidity file found, nothing to analyze");
2020
}

0 commit comments

Comments
 (0)