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

chore: use rustfmt imports_granularity option #17421

Merged
merged 2 commits into from
Jan 15, 2023

Conversation

littledivy
Copy link
Member

@littledivy littledivy commented Jan 14, 2023

Closes #2699
Closes #2347

Uses unstable rustfmt features. Since dprint invokes rustfmt we do not need to switch the cargo toolchain to nightly. Do we care about formatting stability of our codebase across Rust versions? (I don't)

@littledivy littledivy marked this pull request as ready for review January 14, 2023 16:22
use std::io::{self, Error, Write};
use std::io::Error;
use std::io::Write;
use std::io::{self};
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
use std::io::{self};
use std::io;

Maybe this should be reported to rustfmt 👀

Copy link
Member Author

@littledivy littledivy Jan 15, 2023

Choose a reason for hiding this comment

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

From rust-lang/rustfmt#4681

Note that use crate::lexer; and use crate::lexer::{self}; are not actually equivalent: The latter only imports the lexer module, while the former looks in all namespaces, so it can import up to 3 items at once, e.g. a function, a module and a macro of the same name.


Also rust-lang/rustfmt#5398

Copy link
Member

Choose a reason for hiding this comment

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

I think just use std::io; works in this case though?

Copy link
Member

Choose a reason for hiding this comment

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

I missed that this was auto merging, but we can “fix” these as we see them in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@@ -5,7 +5,8 @@ use std::future::Future;
use std::io;
use std::os::unix::io::RawFd;
use std::pin::Pin;
use std::task::{self, Poll};
use std::task::Poll;
use std::task::{self};
Copy link
Member

Choose a reason for hiding this comment

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

ditto

core/lib.rs Outdated
pub use serde_v8::ByteString;
pub use serde_v8::DetachedBuffer;
pub use serde_v8::StringOrBuffer;
pub use serde_v8::U16String;
pub use serde_v8::ZeroCopyBuf;
pub use serde_v8::{self};
Copy link
Member

Choose a reason for hiding this comment

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

hmmm.. this looks really unnatural. I wonder if there's a way to avoid {self}

use serde::de::{self, SeqAccess as _, Visitor};
use serde::de::SeqAccess as _;
use serde::de::Visitor;
use serde::de::{self};
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@@ -1,7 +1,9 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use std::fmt::{self, Display};
use std::fmt::Display;
use std::fmt::{self};
Copy link
Member

Choose a reason for hiding this comment

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

ditto

.dprint.json Outdated
@@ -11,7 +11,7 @@
},
"exec": {
"associations": "**/*.rs",
"rustfmt": "rustfmt"
"rustfmt": "rustfmt --config imports_granularity=item,wrap_comments=true"
Copy link
Member

Choose a reason for hiding this comment

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

I'm surprised this works.

Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

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

I like imports_granularity=item and have wanted that on our code base for a while, but I'm not a fan of wrap_comments=true (just my preference, not sure how other people feel).

cli/lsp/capabilities.rs Outdated Show resolved Hide resolved
cli/lsp/documents.rs Outdated Show resolved Hide resolved
cli/napi/mod.rs Outdated Show resolved Hide resolved
cli/npm/resolution/graph.rs Outdated Show resolved Hide resolved
cli/npm/resolution/graph.rs Outdated Show resolved Hide resolved
ext/node/resolution.rs Outdated Show resolved Hide resolved
ops/README.md Outdated Show resolved Hide resolved
ops/lib.rs Outdated Show resolved Hide resolved
runtime/permissions/mod.rs Outdated Show resolved Hide resolved
serde_v8/benches/ser.rs Outdated Show resolved Hide resolved
@littledivy
Copy link
Member Author

@dsherret Removed wrap_comments=true. As you pointed out in CR, it seems to be broken anyways

@littledivy littledivy changed the title chore: use rustfmt imports_granularity and wrap_comments config options chore: use rustfmt imports_granularity option Jan 15, 2023
@littledivy littledivy enabled auto-merge (squash) January 15, 2023 04:08
Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

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

LGTM with just imports_granularity.

@littledivy littledivy merged commit d563416 into denoland:main Jan 15, 2023
bartlomieju pushed a commit that referenced this pull request Jan 16, 2023
Closes #2699
Closes #2347

Uses unstable rustfmt features. Since dprint invokes `rustfmt` we do not
need to switch the cargo toolchain to nightly. Do we care about
formatting stability of our codebase across Rust versions? (I don't)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rustfmt is not correctly wrapping at 80 columns use imports_layout in rustfmt once it becomes stable.
3 participants