Add redundant internal and fileprivate analysis to go alongside redundant public analysis. #976
Conversation
ileitch
left a comment
There was a problem hiding this comment.
Thanks for reworking this. Let's give it a shot, and see if people find it useful.
|
Just noticed that this got looked at. I'll clean stuff up so we can try again! |
Co-authored-by: Ian Leitch <ian@leitch.io>
|
ok @ileitch I dealt with your comments; also made some big improvements to the tests which I realized I hadn't quite finished up yet. I think we're good to go now. |
|
@danwood Can you please take a look at the failures? They indicate that there aren't any tests using |
|
@ileitch I am working on updating my pull request to address your issue of missing tests. Yes, I see now that the assertions like "assertRedundantInternalAccessibility" were not actually invoked, so I need to build some new testing code. The problem is that the warnings you indicated have disappeared from this pull request, and I don't know how to regenerate those warnings so I can confirm that I've implemented everything I need to implement. All the tests pass when I use |
This reverts commit 882e58d.
It was the |
|
@ileitch I will try to dig into these errors, which have appeared again. Not sure if I can address the linux errors, though - I don't have a linux installation. I'm not famiilar with |
|
@ileitch from the output here, it looks like all but one of the "mise" complaints were about the same one item in my codebase that I have since fixed; the remaining one was about the formatting of the Sources/BUILD.bazel file, which just had a couple of additions for my files, but I can't really figure out what it is complaining about. I'm not using Bazel, just |
|
OK, I took a guess that |
ileitch
left a comment
There was a problem hiding this comment.
The issue with the 'path' property is that 'fileprivate' was incorrectly identified as redundant, but it is actually the most appropriate accessibility level. I don't think simply removing the accessibility is the right thing to do, because it represents a real bug in your PR.
Fix the scanning logic for that, and update the tests to reflect that.
|
OK I think we are good to go. Note: I see "1 requested change" here on github but no indication of what the actual request is. Maybe it's something I already resolved, like fixing the access back to fileprivate? BTW, I am also working on an enhancement that will flag redundant access declarations; e.g. it would point out redundant private declarations found in FilePath+Glob.swift, TypeSyntaxInspectorTest.swift, and SwiftIndexer.swift. (That's where you have a private class or struct, with private properties and functions declared inside). But that's probably best to put that in a separate PR once we figure this one out. |
It's useful to make your swift types be as private as possible, to encourage encapsulation. This improvement adds new checks for types that are fileprivate or (implicitly/explicitly) internal, and lets you know if they could be made more private then they are currently.
(This is a reworking of a branch and pull request I did a year or so ago. I'm trying again.)