Skip to content

Commit 6adf885

Browse files
author
Paolo Tranquilli
committed
Rust: fix linting script
1 parent 0a8c0f5 commit 6adf885

File tree

2 files changed

+36
-32
lines changed

2 files changed

+36
-32
lines changed

rust/extractor/macros/src/lib.rs

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
11
use proc_macro::TokenStream;
2-
use quote::{quote, format_ident};
3-
use syn;
4-
2+
use quote::{format_ident, quote};
53

64
/// Allow all fields in the extractor config to be also overrideable by extractor CLI flags
75
#[proc_macro_attribute]
86
pub fn extractor_cli_config(_attr: TokenStream, item: TokenStream) -> TokenStream {
97
let ast = syn::parse_macro_input!(item as syn::ItemStruct);
108
let name = &ast.ident;
119
let new_name = format_ident!("Cli{}", name);
12-
let fields: Vec<_> = ast.fields.iter().map(|f| {
13-
let id = f.ident.as_ref().unwrap();
14-
let ty = &f.ty;
15-
if let syn::Type::Path(p) = ty {
16-
if p.path.is_ident(&format_ident!("bool")) {
17-
return quote! {
18-
#[arg(long)]
19-
#id: bool,
20-
};
21-
}
22-
}
23-
if id == &format_ident!("verbose") {
24-
quote! {
25-
#[arg(long, short, action=clap::ArgAction::Count)]
26-
#id: u8,
10+
let fields: Vec<_> = ast
11+
.fields
12+
.iter()
13+
.map(|f| {
14+
let id = f.ident.as_ref().unwrap();
15+
let ty = &f.ty;
16+
if let syn::Type::Path(p) = ty {
17+
if p.path.is_ident(&format_ident!("bool")) {
18+
return quote! {
19+
#[arg(long)]
20+
#id: bool,
21+
};
22+
}
2723
}
28-
} else if id == &format_ident!("inputs") {
29-
quote! {
30-
#id: #ty,
31-
}
32-
} else {
33-
quote! {
34-
#[arg(long)]
35-
#id: Option<#ty>,
24+
if id == &format_ident!("verbose") {
25+
quote! {
26+
#[arg(long, short, action=clap::ArgAction::Count)]
27+
#id: u8,
28+
}
29+
} else if id == &format_ident!("inputs") {
30+
quote! {
31+
#id: #ty,
32+
}
33+
} else {
34+
quote! {
35+
#[arg(long)]
36+
#id: Option<#ty>,
37+
}
3638
}
37-
}
38-
}).collect();
39+
})
40+
.collect();
3941
let gen = quote! {
4042
#[serde_with::apply(_ => #[serde(default)])]
4143
#[derive(Debug, Deserialize, Default)]

rust/lint.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import shutil
66
import sys
77

8-
extractor_dir = pathlib.Path(__file__).resolve().parent / "extractor"
8+
this_dir = pathlib.Path(__file__).resolve().parent
99

1010
cargo = shutil.which("cargo")
1111
assert cargo, "no cargo binary found on `PATH`"
1212

13-
fmt = subprocess.run([cargo, "fmt", "--quiet"], cwd=extractor_dir)
14-
clippy = subprocess.run([cargo, "clippy", "--fix", "--allow-dirty", "--allow-staged", "--quiet"],
15-
cwd=extractor_dir)
13+
fmt = subprocess.run([cargo, "fmt", "--all", "--quiet"], cwd=this_dir)
14+
for manifest in this_dir.rglob("Cargo.toml"):
15+
if not manifest.is_relative_to(this_dir / "ql"):
16+
clippy = subprocess.run([cargo, "clippy", "--fix", "--allow-dirty", "--allow-staged", "--quiet"],
17+
cwd=manifest.parent)
1618
sys.exit(fmt.returncode or clippy.returncode)

0 commit comments

Comments
 (0)