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

serde macro lint #48

Open
Kriskras99 opened this issue Nov 21, 2023 · 1 comment
Open

serde macro lint #48

Kriskras99 opened this issue Nov 21, 2023 · 1 comment
Labels
A-user-story Area: A user story or a related issue

Comments

@Kriskras99
Copy link

Lint explanation

It would be nice to lint Serde macros for unnecessary duplication.
For example:

  • Specifying default on an Option (Option is automatically default)
  • rename = "SomeThing" that matches the rename_all = "PascalCase" on the struct
  • Suggest adding or removing rename_all = "x" if that would result in less rename = "y" lines

Example code

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct BadExample {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub default_option: Option<String>,
    #[serde(rename = "SomeThing")]
    pub some_thing: String,
}

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct GoodExample {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub default_option: Option<String>,
    pub some_thing: String,
}

Notes

The output/expansion of the macro is not relevent for these lints.

@Kriskras99 Kriskras99 added the A-user-story Area: A user story or a related issue label Nov 21, 2023
@xFrednet
Copy link
Member

That's a cool suggestion, thank you for the issue! Marker is currently sadly lacking a representation for attributes (rust-marker/marker#51), but I want to definitely support such lints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-user-story Area: A user story or a related issue
Projects
None yet
Development

No branches or pull requests

2 participants