-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Added fileprivateRule #1489
Added fileprivateRule #1489
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1489 +/- ##
==========================================
+ Coverage 88.08% 88.09% +0.01%
==========================================
Files 196 198 +2
Lines 9791 9844 +53
==========================================
+ Hits 8624 8672 +48
- Misses 1167 1172 +5
Continue to review full report at Codecov.
|
let violationOffsets = toplevel.flatMap { (offSet) -> Int? in | ||
let parts = syntaxTokens.partitioned { offSet <= $0.offset } | ||
guard let lastKind = parts.first.last, | ||
lastKind.length == "fileprivate".bridge().length, |
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.
Full disclosure here: There is another builtin that has the same length as fileprivate
. nonmutating
has the same length of characters but nonmutating
can never be toplevel in the current version of swift AFAIK. We could just file.substring
to find out exactly what the builtin key is but that would slow down this pass.
This doesn't close #1058 because my intention there is broader. For example, this should trigger: class Foo {
fileprivate var bar = ""
func something() {
print(bar)
}
} |
@marcelofabri That case is triggered in the |
My idea was to trigger only if we find out that the variable is only used in the current type scope (i.e. changing to Example1: class Foo {
fileprivate var bar = ""
func something() {
print(bar)
}
} Example2: class Foo {
fileprivate var bar = ""
}
extension Foo {
func printBar() {
print(bar)
}
} I know that there's the strict mode, but that comes with false positives as well. In a perfect scenario, I'd like this rule to always flag cases where I still think this is useful without implementing the full #1058 issue tough. |
I see. I was thinking |
79115ff
to
7c0f637
Compare
@marcelofabri I rebased this. Let me know if there is anything that would be blocking this. |
7c0f637
to
985f9f7
Compare
Added
fileprivateRule
to check for top-level usages offileprivate
and recommendprivate
instead. This is inline with SE-0169's goal "forfileprivate
to be used rarely". There is a also an "strict" option that will mark everyfileprivate
as a violation.closes #1469
benchmark