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

Draft: Add #[rustfmt::sort] and implement for enum variants and struct structs #6313

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Code0x58
Copy link

@Code0x58 Code0x58 commented Sep 4, 2024

#3422: add explicit rustfmt::sort attribute which causes case sensitive sorting

  • enum variants
  • struct structs

This does not raise if rustfmt::sort is applied in an unhandled place (e.g. struct, member, etc.), although that might be reasonable to pursue; at a glance, rustfmt::skip does not appear to do that, which may be more reasonable given how it can reasonably apply to anything.

TODO:

  • implement #[rustfmt::skip::sort]

@Code0x58 Code0x58 changed the title Add #[rustfmt::sort] for enum variants WIP: Add #[rustfmt::sort] for enum variants Sep 4, 2024
@Code0x58 Code0x58 force-pushed the issue/3422 branch 3 times, most recently from 7130bf7 to 9cd28ab Compare September 4, 2024 22:43
@Code0x58 Code0x58 changed the title WIP: Add #[rustfmt::sort] for enum variants Add #[rustfmt::sort] and implement for enum variants and struct structs Sep 4, 2024
@Code0x58
Copy link
Author

Code0x58 commented Sep 5, 2024

I've found this useful as is, for formatting a large enumeration with attributes on the members. One issue I've bumped into was that this enumeration in particular uses Serde's untagged feature e.g.

use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub enum StringyThingy {
    Zoo,
    #[serde(untagged)]
    Other(String)
}

where Other must be at the end. That makes me think that it would be best to try working out some way of maintaining this. The most practical solution I can think of right now is to have some a way to stop the index from being changed, e.g. rustfmt::skip::sort

pub enum StringyThingy {
    Zoo,
    #[rustfmt::skip::sort]
    #[serde(untagged)]
    Other(String)
}

@Code0x58 Code0x58 changed the title Add #[rustfmt::sort] and implement for enum variants and struct structs Draft: Add #[rustfmt::sort] and implement for enum variants and struct structs Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants