mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Rust: fix linting script
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use quote::{quote, format_ident};
|
use quote::{format_ident, quote};
|
||||||
use syn;
|
|
||||||
|
|
||||||
|
|
||||||
/// Allow all fields in the extractor config to be also overrideable by extractor CLI flags
|
/// Allow all fields in the extractor config to be also overrideable by extractor CLI flags
|
||||||
#[proc_macro_attribute]
|
#[proc_macro_attribute]
|
||||||
@@ -9,33 +7,37 @@ pub fn extractor_cli_config(_attr: TokenStream, item: TokenStream) -> TokenStrea
|
|||||||
let ast = syn::parse_macro_input!(item as syn::ItemStruct);
|
let ast = syn::parse_macro_input!(item as syn::ItemStruct);
|
||||||
let name = &ast.ident;
|
let name = &ast.ident;
|
||||||
let new_name = format_ident!("Cli{}", name);
|
let new_name = format_ident!("Cli{}", name);
|
||||||
let fields: Vec<_> = ast.fields.iter().map(|f| {
|
let fields: Vec<_> = ast
|
||||||
let id = f.ident.as_ref().unwrap();
|
.fields
|
||||||
let ty = &f.ty;
|
.iter()
|
||||||
if let syn::Type::Path(p) = ty {
|
.map(|f| {
|
||||||
if p.path.is_ident(&format_ident!("bool")) {
|
let id = f.ident.as_ref().unwrap();
|
||||||
return quote! {
|
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,
|
||||||
|
}
|
||||||
|
} else if id == &format_ident!("inputs") {
|
||||||
|
quote! {
|
||||||
|
#id: #ty,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
quote! {
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
#id: bool,
|
#id: Option<#ty>,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
if id == &format_ident!("verbose") {
|
.collect();
|
||||||
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();
|
|
||||||
let gen = quote! {
|
let gen = quote! {
|
||||||
#[serde_with::apply(_ => #[serde(default)])]
|
#[serde_with::apply(_ => #[serde(default)])]
|
||||||
#[derive(Debug, Deserialize, Default)]
|
#[derive(Debug, Deserialize, Default)]
|
||||||
|
|||||||
10
rust/lint.py
10
rust/lint.py
@@ -5,12 +5,14 @@ import pathlib
|
|||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
extractor_dir = pathlib.Path(__file__).resolve().parent / "extractor"
|
this_dir = pathlib.Path(__file__).resolve().parent
|
||||||
|
|
||||||
cargo = shutil.which("cargo")
|
cargo = shutil.which("cargo")
|
||||||
assert cargo, "no cargo binary found on `PATH`"
|
assert cargo, "no cargo binary found on `PATH`"
|
||||||
|
|
||||||
fmt = subprocess.run([cargo, "fmt", "--quiet"], cwd=extractor_dir)
|
fmt = subprocess.run([cargo, "fmt", "--all", "--quiet"], cwd=this_dir)
|
||||||
clippy = subprocess.run([cargo, "clippy", "--fix", "--allow-dirty", "--allow-staged", "--quiet"],
|
for manifest in this_dir.rglob("Cargo.toml"):
|
||||||
cwd=extractor_dir)
|
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)
|
sys.exit(fmt.returncode or clippy.returncode)
|
||||||
|
|||||||
Reference in New Issue
Block a user