Skip to content

Commit

Permalink
Rust: fix linting script
Browse files Browse the repository at this point in the history
  • Loading branch information
Paolo Tranquilli committed Sep 12, 2024
1 parent 0a8c0f5 commit 6adf885
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 32 deletions.
58 changes: 30 additions & 28 deletions rust/extractor/macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
use proc_macro::TokenStream;
use quote::{quote, format_ident};
use syn;

use quote::{format_ident, quote};

/// Allow all fields in the extractor config to be also overrideable by extractor CLI flags
#[proc_macro_attribute]
pub fn extractor_cli_config(_attr: TokenStream, item: TokenStream) -> TokenStream {
let ast = syn::parse_macro_input!(item as syn::ItemStruct);
let name = &ast.ident;
let new_name = format_ident!("Cli{}", name);
let fields: Vec<_> = ast.fields.iter().map(|f| {
let id = f.ident.as_ref().unwrap();
let ty = &f.ty;
if let syn::Type::Path(p) = ty {
if p.path.is_ident(&format_ident!("bool")) {
return quote! {
#[arg(long)]
#id: bool,
};
}
}
if id == &format_ident!("verbose") {
quote! {
#[arg(long, short, action=clap::ArgAction::Count)]
#id: u8,
let fields: Vec<_> = ast
.fields
.iter()
.map(|f| {
let id = f.ident.as_ref().unwrap();
let ty = &f.ty;
if let syn::Type::Path(p) = ty {
if p.path.is_ident(&format_ident!("bool")) {
return quote! {
#[arg(long)]
#id: bool,
};
}
}
} else if id == &format_ident!("inputs") {
quote! {
#id: #ty,
}
} else {
quote! {
#[arg(long)]
#id: Option<#ty>,
if id == &format_ident!("verbose") {
quote! {
#[arg(long, short, action=clap::ArgAction::Count)]
#id: u8,
}
} else if id == &format_ident!("inputs") {
quote! {
#id: #ty,
}
} else {
quote! {
#[arg(long)]
#id: Option<#ty>,
}
}
}
}).collect();
})
.collect();
let gen = quote! {
#[serde_with::apply(_ => #[serde(default)])]
#[derive(Debug, Deserialize, Default)]
Expand Down
10 changes: 6 additions & 4 deletions rust/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import shutil
import sys

extractor_dir = pathlib.Path(__file__).resolve().parent / "extractor"
this_dir = pathlib.Path(__file__).resolve().parent

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

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

0 comments on commit 6adf885

Please sign in to comment.