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 Attribute #3665

Closed
la10736 opened this issue Jul 2, 2019 · 5 comments
Closed

Skip Attribute #3665

la10736 opened this issue Jul 2, 2019 · 5 comments

Comments

@la10736
Copy link
Contributor

la10736 commented Jul 2, 2019

Attributes are evolving and now are used also to create DSL. Now, by the rising of procedural macro and the possibility to use arbitrary rust code in attributes syntax formatting attribute by simple rules based on meta and nested meta can produce some formatting that make the procedural macro DSL not clear.

For instance I have a crate of mine la10736/rstest that you can use to write tests like this:

#[rstest_parametrize(foo, bar, baz,
    case(0, "a", "A"),
    case(1, "b", "B")
)]
fn mytest(foo: u32, bar: &str, baz: &str) {}

Now, use rustfmt on this file make it flat and hard to read:

#[rstest_parametrize(foo, bar, baz, case(0, 'a', 'A'), case(1, 'b', 'B'))]
fn mytest(foo: u32, bar: char, baz: char) {}

Or wrost:

#[rstest_parametrize(foo, bar, baz,
    case(0, "a", "Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
    case(1, "b", "B")
)]
fn mytest(foo: u32, bar: &str, baz: &str) {}

in

#[rstest_parametrize(
    foo, 
    bar,
    baz,
    case(0, "a", "Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
    case(1, "b", "B")
)]
fn mytest(foo: u32, bar: &str, baz: &str) {}

We can use rustfmt::skip::macros() or a brand new rustfmt::skip::attributes() to have the ability of skip attributes formatting too.

If you are ok I can work on it.

@topecongiro
Copy link
Contributor

It seems like a good idea given that, like macro calls, attributes can have an arbitral token stream as their arguments.

@topecongiro
Copy link
Contributor

Adding a new rustfmt::skip::attributes() seems better to me.

@la10736
Copy link
Contributor Author

la10736 commented Jul 4, 2019

I'm done with base implementation but is just a cut and paste of rustfmt::skip::macros() implementation. I tempted to refactor all skip's stuff before submit but I should decide if merge just macros and attributes stuffs or encapsulate rustfmt::skip responsibility too.

The second one solution touch lot of files so maybe is better do a separate pull request but merge just sub attributes left things less cohesive.

What do you think?

@scampi
Copy link
Contributor

scampi commented Jul 6, 2019

@la10736 a separate PR would probably be better

@la10736
Copy link
Contributor Author

la10736 commented Jul 7, 2019

I already did the PR with just refactoring macros and attributes. I left rustfmt::skip's stuff untouched.

la10736 added a commit to la10736/rustfmt that referenced this issue Jul 15, 2019
la10736 added a commit to la10736/rustfmt that referenced this issue Jul 15, 2019
la10736 pushed a commit to la10736/rustfmt that referenced this issue Jul 16, 2019
la10736 pushed a commit to la10736/rustfmt that referenced this issue Jul 16, 2019
topecongiro pushed a commit that referenced this issue Jul 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants