Skip to content

serde macro lint #48

Description

@Kriskras99

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-user-storyArea: A user story or a related issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions