-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Cleanup: reduce the number of warnings during a build #4547
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
base: develop
Are you sure you want to change the base?
Conversation
047a527 to
2c2bb7c
Compare
|
Any advice on how to review this? E.g. which parts were not the obvious fix for a warning? |
|
The majority of changed lines follow one of several patterns, so it's enough to understand an edit once, and then the rest of the instances become clear as well. Examples:
There are a few non-trivial fixes, but most changes are just boilerplate. |
|
Could you describe the process for these two? The process itself is partly proof of correctness (and the other part is the clean compilation). E.g. which
|
|
Sure. For
Steps 2 and 3 can be replaced with just looking at the code or preliminary knowledge or assumptions, so some For removing type annotations: when I was fixing some warnings in a file, I also went through the suggestion provided by the IDE, considered if applying them is proper, and then I either did that or reported a broken suggestion to the IDE team. |
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.
Thank you for taking this cleanup on! I was pretty annoyed with all the warnings.
? in my comments mean please provide context/reference/proof for the correctness of the change.
I'd also like a prove of completeness of certain replacements. E.g. as if with the publc modifier in test, the proof is empty grep in Idea. The proof can come just as a confirmation statement, "grep for xxx in directory yyy is empty", then I can check it in O(1).
For now I'm not sure when you did or didn't aim for completeness.
I also not sure how you discovered the warnings. Did you use compilation warnings only? If I run "inspect project" in Idea, I see many more warnings, some of them similar to the ones fixed here.
Just FYI: here's a context to which changes are easier to check during review
Easy to check
Removals
@Suppress- inferable type parameters
- not-null assertions (!!)
publicmodifiers from tests- imports
These removals are easy because if the CI passes after the change, then the change is valid. Hence, I don't need to think about it.
And other things
- Rename the unused parameter in the catch clause to
_
Harder to check
- Adding suppresses (since we don't have a check "this suppress doesn't suppress anything")
- Loosening the type to nullable (adding ?)
- Adding not-null assertion (!!)
- Changes not triggered by inspections (If I undo the change, I don't see any static warning that triggers me)
| val mutex = Mutex(true) // locked mutex | ||
| val job = launch(start = CoroutineStart.UNDISPATCHED) { | ||
| expect(2) | ||
| select<String> { // suspends |
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.
select<String> - <String> can also be removed
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.
Not sure how you discovered the other entries for the "Remove explicit type arguments" inspection, by hand or by following warnings. If the latter, not sure why this and other few cases were missed. Possibly also clean them up?
| finish(4) | ||
| } | ||
| } | ||
| } |
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.
Newline
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.
There's a checkbox in Idea, "ensure every saved file ends with a line break"
| finish(4) | ||
| } | ||
|
|
||
| @Suppress("DEPRECATION") |
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.
Could you add // Mutex.onLock, since there's no hint neither on github, nor in Idea after the suppress has been added
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.
Here and in other entries of @Suppress("DEPRECATION")
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.
Such comments can become outdated when additional APIs used in the test get deprecated. I'd rather not risk misleading the reader. The more reliable method to learn which particular API needs the suppression is to temporarily remove the annotation.
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 see, but without the comment, there's no way to know which suppress the author meant when they wrote that suppress.
(Either way, would be nice to have all suppresses in the codebase either commented, or un-commented. Not necessarily by your PR, of course.)
| */ | ||
| class JobStatesTest : TestBase() { | ||
| @Test | ||
| public fun testNormalCompletion() = runTest { |
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.
There's another 15 entries for public fun in common/test, and most of them don't need the public modifier. Could you get rid of them as well?
Command was: git grep -l '^ *public ' | grep /test/ | xargs sed -i 's/^\( *\)public /\1/g'
Upgrading to Kotlin 2.2.20 brought new warnings, which this commit fixes.
2c2bb7c to
b450ca9
Compare
| .lines().joinToString("\n") // normalize line separators | ||
|
|
||
| public fun String.count(substring: String): Int = split(substring).size - 1 | ||
| fun String.count(substring: String): Int = split(substring).size - 1 |
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.
Newline
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.
Approved subject to explicitly accepting/rejecting unresolved comments.
No description provided.