Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip parsing attributes from rustfmt or clippy #2473

Merged
merged 1 commit into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions command_attr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ pub fn command(attr: TokenStream, input: TokenStream) -> TokenStream {
let mut options = Options::new();

for attribute in &fun.attributes {
if is_rustfmt_or_clippy_attr(&attribute.path) {
continue;
}

let span = attribute.span();
let values = propagate_err!(parse_values(attribute));

Expand Down Expand Up @@ -311,6 +315,10 @@ pub fn help(attr: TokenStream, input: TokenStream) -> TokenStream {
let mut options = HelpOptions::default();

for attribute in &fun.attributes {
if is_rustfmt_or_clippy_attr(&attribute.path) {
continue;
}

let span = attribute.span();
let values = propagate_err!(parse_values(attribute));

Expand Down Expand Up @@ -615,6 +623,10 @@ pub fn group(attr: TokenStream, input: TokenStream) -> TokenStream {
let mut options = GroupOptions::new();

for attribute in &group.attributes {
if is_rustfmt_or_clippy_attr(&attribute.path) {
continue;
}

let span = attribute.span();
let values = propagate_err!(parse_values(attribute));

Expand Down Expand Up @@ -741,6 +753,10 @@ pub fn check(_attr: TokenStream, input: TokenStream) -> TokenStream {
let mut check_in_help = true;

for attribute in &fun.attributes {
if is_rustfmt_or_clippy_attr(&attribute.path) {
continue;
}

let span = attribute.span();
let values = propagate_err!(parse_values(attribute));

Expand Down
7 changes: 6 additions & 1 deletion command_attr/src/structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use syn::{
FnArg,
Ident,
Pat,
Path,
ReturnType,
Stmt,
Token,
Expand Down Expand Up @@ -99,6 +100,10 @@ fn is_cooked(attr: &Attribute) -> bool {
COOKED_ATTRIBUTE_NAMES.iter().any(|n| attr.path.is_ident(n))
}

pub fn is_rustfmt_or_clippy_attr(path: &Path) -> bool {
path.segments.first().map_or(false, |s| s.ident == "rustfmt" || s.ident == "clippy")
}

/// Removes cooked attributes from a vector of attributes. Uncooked attributes are left in the
/// vector.
///
Expand All @@ -111,7 +116,7 @@ fn remove_cooked(attrs: &mut Vec<Attribute>) -> Vec<Attribute> {
// FIXME: Replace with `Vec::drain_filter` once it is stable.
let mut i = 0;
while i < attrs.len() {
if !is_cooked(&attrs[i]) {
if !is_cooked(&attrs[i]) && !is_rustfmt_or_clippy_attr(&attrs[i].path) {
i += 1;
continue;
}
Expand Down