Skip to content

Add lint long_variable_names #14818

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JurrianFahner
Copy link

@JurrianFahner JurrianFahner commented May 15, 2025

The lint is configurable by using max-variable-name-length.

Related #644 this PR only concerns the variable length

changelog: [long_variable_names]: enable variable length check in clippy

@rustbot
Copy link
Collaborator

rustbot commented May 15, 2025

r? @Jarcho

rustbot has assigned @Jarcho.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 15, 2025
@JurrianFahner
Copy link
Author

JurrianFahner commented May 15, 2025

r? @llogiq thanks for your clippy workshop today! Looking forward for your feedback.

@JurrianFahner
Copy link
Author

JurrianFahner commented May 15, 2025

I doubt whether the default value is well chosen. 30 seems ok for most of the use cases. But for the clippy source it was needed to create some different configurations too.

@rustbot rustbot assigned llogiq and unassigned Jarcho May 15, 2025
Copy link
Contributor

@llogiq llogiq left a comment

Choose a reason for hiding this comment

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

Yeah, so I'd like to make sure that we have some benefit if we actually have that lint warn. I figure we either make it a pedantic lint or we set a far higher default threshold. When in doubt, you can run lintcheck.

Otherwise this looks good to merge.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels May 16, 2025
@JurrianFahner JurrianFahner requested a review from llogiq May 17, 2025 17:51
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels May 17, 2025
Copy link
Contributor

@llogiq llogiq left a comment

Choose a reason for hiding this comment

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

Looks good to me. Can you squash your commits please?

@JurrianFahner JurrianFahner force-pushed the master branch 4 times, most recently from c7c54a6 to 99a3a2e Compare May 17, 2025 22:19
@llogiq
Copy link
Contributor

llogiq commented May 18, 2025

I will start the FCP for this lint later today.

Copy link
Contributor

@samueltardieu samueltardieu left a comment

Choose a reason for hiding this comment

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

Thanks for incorporating the feedback. Here is another round of how to make things more efficient, with even simpler code.

Comment on lines 64 to 67
format!(
"use of a long variable name, it is longer than the configured `max-variable-name-length` of {} characters",
self.max_variable_name_length
),
None,
format!("reduce the length of the long variable name with at least {length_diff} characters"),
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer something like that, but it is mostly nitpicking:

Suggested change
format!(
"use of a long variable name, it is longer than the configured `max-variable-name-length` of {} characters",
self.max_variable_name_length
),
None,
format!("reduce the length of the long variable name with at least {length_diff} characters"),
format!(
"variable name is longer than the configured `max-variable-name-length` ({} characters)",
self.max_variable_name_length
),
None,
format!("rename the variable to not exceed the maximum length"),

Copy link
Author

Choose a reason for hiding this comment

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

I agree with the changes in line 65. However line 69 contains information that a developer can use to make decisions in what to do, for example to remove one word from the variable.

@Centri3
Copy link
Member

Centri3 commented May 18, 2025

Updated your description to prevent fully closing #644, which I assume is undesired 😅

@JurrianFahner JurrianFahner force-pushed the master branch 3 times, most recently from a087635 to e34ef64 Compare May 18, 2025 20:06
The lint is configurable by using `max-variable-name-length` and it is set to 100 by default.
Copy link
Contributor

@samueltardieu samueltardieu left a comment

Choose a reason for hiding this comment

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

That's much improved, thanks!

@samueltardieu samueltardieu dismissed their stale review May 18, 2025 20:55

Changes made

@JurrianFahner
Copy link
Author

That's much improved, thanks!

You're welcome! Thanks for the quick feedback loop, so we were able to finish it fast. It was a nice learning experience on how to build a first lint.
I lost quite some time on building on windows, but when I switched to linux in WSL the iterations became more quick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants