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

Adding lint test for excessive LOC. #2857

Merged
merged 22 commits into from
Feb 2, 2019
Merged

Adding lint test for excessive LOC. #2857

merged 22 commits into from
Feb 2, 2019

Conversation

avborhanian
Copy link
Contributor

This is a WIP for #2377. Just wanted to pull in because I had a few questions:

  1. Is it okay that I'm approaching this via counting by looking at each line in the snippet instead of looking at the AST tree? If there's another way to do it, I want to make sure I'm doing the correct way, but I wasn't sure since the output AST JSON doesn't seem to contain whitespace.

  2. My function is definitely going to trigger the lint, so also wanted to see if there was something obvious I could do to reduce it.

  3. Are the two tests fine, or is there something obvious I'm missing?

  4. Obviously bigger question - am I approaching the line count correctly. Current strategy is count a line if it contains some code, so skip if it's just comments or empty.

@oli-obk
Copy link
Contributor

oli-obk commented Jun 20, 2018

  1. yes
  2. I'll comment inline
  3. please add them to their own file. We're trying to have many small tests files instead of few large ones
  4. makes sense

clippy_lints/src/functions.rs Outdated Show resolved Hide resolved
clippy_lints/src/functions.rs Outdated Show resolved Hide resolved
clippy_lints/src/functions.rs Outdated Show resolved Hide resolved
clippy_lints/src/functions.rs Outdated Show resolved Hide resolved
@avborhanian
Copy link
Contributor Author

Are there any more changes I should consider making?

@oli-obk
Copy link
Contributor

oli-obk commented Jun 26, 2018

Let's retrigger CI

@oli-obk oli-obk closed this Jun 26, 2018
@oli-obk oli-obk reopened this Jun 26, 2018
@mati865
Copy link
Contributor

mati865 commented Jun 26, 2018

Triggered itself in matches.rs test, you will have to allow it there:

+error: This function has a large number of lines.
+   --> $DIR/matches.rs:126:1
+    |
+126 | / fn match_wild_err_arm() {
+127 | |     let x: Result<i32, &str> = Ok(3);
+128 | |
+129 | |     match x {
+...   |
+207 | |     }
+208 | | }
+    | |_^
+    |
+    = note: `-D too-many-lines` implied by `-D warnings`

Your test doesn't work, maybe you have to add two prints so function body exceeds 51?

diff of stderr:
-error: This function has a large number of lines.
-   --> $DIR/functions_maxlines.rs:57:1
-    |
-57  | / fn bad_lines() {
-58  | |     println!("This is bad.");
-59  | |     println!("This is bad.");
-60  | |     println!("This is bad.");
-...   |
-107 | |     println!("This is bad.");
-108 | | }
-    | |_^
-    |
-    = note: `-D too-many-lines` implied by `-D warnings`
-
-error: aborting due to previous error

@oli-obk
Copy link
Contributor

oli-obk commented Jun 27, 2018

Dogfood tests die on this :D Clippy itself violates that rule so many times... https://travis-ci.org/rust-lang-nursery/rust-clippy/jobs/397138977#L1006

Not sure if we should increase the limit, allow the lint inside clippy_lints, make it a restriction lint, or any combination of the above.

@mati865
Copy link
Contributor

mati865 commented Jun 27, 2018

@oli-obk I just noticed restriction group is not mentioned in README.md, guess it should be there.

@avborhanian
Copy link
Contributor Author

So for those tests, the line counts were on average 101 lines. Median was 68 lines. Mode was 71 lines. If I increased the limit to trigger on line counts greater than or equal to 101 lines, it dropped the number of failures from 72 to 17, in 14 different files instead of 45 different files.

I think it would make sense to make it allowed inside clippy_lints. I'm not sure what the restriction limit does though, not as familiar with that.

@oli-obk
Copy link
Contributor

oli-obk commented Jun 28, 2018

The restriction group means it's a lint that you have to enable explicitly.

Even with the guidelines from the clippy RFC I'm not sure in which group to place it though ;) It has no false positives, but it can be inactionable (imagine a function exhaustively matching on a 50 variant enum with a few lines of actions per variant).

The 17 functions that you found, did they look like they should be split up?

@fabric-and-ink
Copy link

Is it possible to deactivate a lint for a specific block? Then we could silence the lint for those 17 functions and postpone a refactoring.

@oli-obk
Copy link
Contributor

oli-obk commented Aug 2, 2018

Sure, just allow it. Or just make it a restriction lint so it needs explicit warn attributes to get turned on.

@phansch phansch added the S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) label Aug 29, 2018
@phansch
Copy link
Member

phansch commented Dec 8, 2018

@avborhanian would you like to finish up this PR? It would need a rebase and the 17 functions would have to be annotated with #[allow(clippy::too_many_lines)] to get started.

@flip1995
Copy link
Member

Ping from triage @avborhanian: It looks like this PR hasn't received any updates in a while, so I'm closing it per our new guidelines. Thank you for your contributions and please feel free to re-open in the future.

@flip1995 flip1995 closed this Dec 27, 2018
@flip1995 flip1995 added S-inactive-closed Status: Closed due to inactivity and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Dec 27, 2018
@avborhanian
Copy link
Contributor Author

Hey! Sorry I didn't respond earlier @phansch. I did the rebase, and it looks like it expanded to include 3 more functions, so I added the lint to those as well. Also had to move the lint from the clippy::all list to the clippy::pedantic list. What do I need to do to reopen the PR?

@flip1995 flip1995 reopened this Jan 13, 2019
@flip1995 flip1995 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-inactive-closed Status: Closed due to inactivity labels Jan 13, 2019
@flip1995
Copy link
Member

Thanks for the update @avborhanian! It seems that the rebase somehow failed. Could you try to fix this? After that we're happy to make another review.

@flip1995 flip1995 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 Jan 13, 2019
@avborhanian
Copy link
Contributor Author

Just curious, is there a way to adjust a configuration variable at the individual test level? Feel like it could be useful for either decreasing the lines I'm testing/making sure different values work as expected.

@flip1995
Copy link
Member

Yes there is! You can look at tests/ui-toml for examples.

clippy_lints/src/types.rs Outdated Show resolved Hide resolved
clippy_lints/src/types.rs Outdated Show resolved Hide resolved
phansch and others added 2 commits February 1, 2019 14:52
Co-Authored-By: avborhanian <avborhanian@gmail.com>
Co-Authored-By: avborhanian <avborhanian@gmail.com>
@phansch
Copy link
Member

phansch commented Feb 1, 2019

Thanks for your patience! Everything LGTM now.

@bors r+

@bors
Copy link
Contributor

bors commented Feb 1, 2019

📋 Looks like this PR is still in progress, ignoring approval.

Hint: Remove WIP from this PR's title when it is ready for review.

@avborhanian avborhanian changed the title WIP: Adding lint test for excessive LOC. Adding lint test for excessive LOC. Feb 2, 2019
@avborhanian
Copy link
Contributor Author

I was about to say the same thing - 7 month long pull request, thanks for the patience. :D

@phansch
Copy link
Member

phansch commented Feb 2, 2019

@bors r+ 🎊

@bors
Copy link
Contributor

bors commented Feb 2, 2019

📌 Commit ac9472d has been approved by phansch

@bors
Copy link
Contributor

bors commented Feb 2, 2019

⌛ Testing commit ac9472d with merge 27b5dd8...

bors added a commit that referenced this pull request Feb 2, 2019
Adding lint test for excessive LOC.

This is a WIP for #2377. Just wanted to pull in because I had a few questions:

1. Is it okay that I'm approaching this via counting by looking at each line in the snippet instead of looking at the AST tree? If there's another way to do it, I want to make sure I'm doing the correct way, but I wasn't sure since the output AST JSON doesn't seem to contain whitespace.

2. My function is definitely going to trigger the lint, so also wanted to see if there was something obvious I could do to reduce it.

3. Are the two tests fine, or is there something obvious I'm missing?

4. Obviously bigger question - am I approaching the line count correctly. Current strategy is count a line if it contains some code, so skip if it's just comments or empty.
@bors
Copy link
Contributor

bors commented Feb 2, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: phansch
Pushing 27b5dd8 to master...

@bors bors merged commit ac9472d into rust-lang:master Feb 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants