-
Notifications
You must be signed in to change notification settings - Fork 909
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
fn_width config option #6046
base: master
Are you sure you want to change the base?
fn_width config option #6046
Conversation
So the checks were spotty there. Then I started to get failed tests half the time on my machine as well after spam rerunning I switched the configs for the test files to toml rather than comment headers and it seems to work consistently now. I was getting "cant exceed max_width" errors when those test failed. I assume waiting to extract the |
@Sjael could you provide a motivating example for why you'd want to wrap before the |
The flakey tests around |
Right now I'm working in Bevy and the functions can have many parameters often with small length, which can make them harder to read when all on one line. I would use What it looks like now: fn setup_arena(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>, icons: Res<Icons>, models: Res<Models>) { What I'd rather have it look like: fn setup_arena(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
icons: Res<Icons>,
models: Res<Models>,
) { Also, I make my guards a little longer than the default |
Definitely not a use case I was thinking of, but it seems reasonable to me. Just a fair warning, I'm trying to go through and review outstanding PRs in the backlog so it might be a while before I can get to this one |
Not a problem at all! Thank you for the quick replies and concise requests for the other PR. It was fun working on it with you. |
Yeah, it's been fun, and I appreciate you applying all the feedback. I know I still owe you a follow up review on the other PR. I'm hoping to get around to that next week |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Sjael thanks for proposing this new option and working on this. Overall this is something the team will need to discuss and consider, but the implementation was relatively straightforward so I went ahead with my initial review.
If you continue to work on this I want to make sure that we're being as thorough as possible with the testing. I've left comments outlining the additional test cases that I want to see. Also, we need to add independent tests, separate from the ones you've already added that show how this option interacts with the various fn_param_layout
configurations.
Additional note:
I want to be clear and say that I'm not suggesting we need to create test cases to show how all of these options interact, but I wanted to bring it up for awareness. There's also the space_before_colon
, space_after_colon
, and type_punctuation_density
configuration options that might impact the function declaration width. There may be others, but this is what I found after a quick look over all our configs.
tests/source/fn_width/100.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's move these tests to tests/source/config/{config_name}/{value}.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume you meant the configs
folder, but it throws errors when I put the test files in there so I made a new config
folder which is somewhat confusing but no errors.
I'm thinking about changing this to being a So fn lorem(mut commands: Commands, icons: Res<Icons>, mut meshes: ResMut<Assets<Mesh>>) {
// block
} would turn into fn lorem(
mut commands: Commands,
icons: Res<Icons>,
mut meshes: ResMut<Assets<Mesh>>,
) {
// block
} when The thinking here is that it's not really the length of the line that makes it harder to read, it's when there are too many parameters on one line. |
I'll need some time to think about that idea. My gut reaction is to stick with the line length wrapping. To the best of my knowledge rustfmts wrapping configurations all revolve around line length so choosing a number of items seems inconsistent. For now I'd like to keep this focused on length as apposed to the number of items. |
Okay I'll change it back to length. I understand that this makes sense from the standpoint of staying consistent with 'length' being the primary limit for wrapping to a new line. I am wondering though, do you agree/disagree with this part of my previous comment?
Perhaps the solution isn't what is needed, but would you agree that the number of arguments is what can lead to an illegible line, rather than specifically the length? |
Yes, and no. I can definitely see why in some cases having too many arguments on one line might make it more difficult, and I can also see how keeping function signature length tied to the max_width would only exacerbate the issue, but I don't think number of arguments alone is what causes poor readability. The complexity of the types and whether or not you're pattern matching on any of the arguments could be another source of poor readability for some users. |
Thought it'd be nice to be able to choose how long you want function declarations to be before going vertical. This is basically the gate before
fn_params_layout
kicks in. It used to just bemax_width
, but now it takes themin
betweenmax_width
andfn_width
.The default is 100, which is what
max_width
defaults to so this should not break anything.