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

Options: Support #[serde(alias = name)] #8031

Closed
wants to merge 2 commits into from
Closed

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Oct 17, 2023

Summary

This PR adds support for serde's #[serde(alias="name")] field-attribute to our options code generator. Simplifying supporting aliases for the same setting.

I'm unsure if we should land this change. I may not end up using it for line-length because I think it's better to actually deprecate these options rather than supporting both (by adding support for Rust's deprecated attribute). However, it is a neat feature and it already works.

Test Plan

I changed line-length to

    /// The line length to use when enforcing long-lines violations (like
    /// `E501`). Must be greater than `0` and less than or equal to `320`.
    #[option(
        default = "88",
        value_type = "int",
        example = r#"
        # Allow lines to be as long as 120 characters.
        line-length = 120
        "#
    )]
    #[serde(alias = "line-width", alias = "max-line-length")]
    pub line_length: Option<LineLength>,

And generated the options markdown

Screenshot 2023-10-18 at 08 51 25

@MichaReiser MichaReiser added the internal An internal refactor or improvement label Oct 17, 2023
@@ -361,6 +361,7 @@ pub struct Options {
line-length = 120
"#
)]
#[serde(alias = "line-width", alias = "max-line-length")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is max-line-length for convenience, or something we once supported?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a test-only change that I accidentally committed... I reverted the change

Signed-off-by: Micha Reiser <micha@reiser.io>
@github-actions
Copy link
Contributor

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

Base automatically changed from formatter-respect-tab-size to main October 18, 2023 23:48
@MichaReiser
Copy link
Member Author

schemars doesn't support aliases. Closing for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal An internal refactor or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants