SwiftLint: False positive `implicit_getter` violation when mentioning word "set" in a comment in custom getter of a read-write var
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
Describe the bug
Mentioning word “set” (without parentheses) in a comment in a get of a read-write var with both get and set defined triggers SwiftLint to think that this is a read-only property.
Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint --path Test.swift --no-cache --enable-all-rules
Loading configuration from '.swiftlint.yml'
Linting Swift files at paths Test.swift
Linting 'Test.swift' (1/1)
/Users/yas/code/caremobile/Test.swift:3:9: warning: Implicit Getter Violation: Computed read-only properties should avoid using the get keyword. (implicit_getter)
Done linting! Found 1 violation, 0 serious in 1 file.
Environment
- SwiftLint 0.39.1
- Installation method used: Homebrew
- Paste your configuration file:
excluded:
- Pods
opt_in_rules:
- array_init
- contains_over_first_not_nil
- collection_alignment
- contains_over_filter_count
- empty_count
- empty_collection_literal
- overridden_super_call
- sorted_first_last
- yoda_condition
disabled_rules:
- cyclomatic_complexity
- file_length
- force_cast
- force_try
- function_body_length
- function_parameter_count
- identifier_name
- large_tuple
- line_length
- multiple_closures_with_trailing_closure
- nesting # consider
- notification_center_detachment
- operator_whitespace
- todo # fix
- type_body_length
- type_name # consider
- weak_delegate # fix
statement_position:
statement_mode: uncuddled_else
-
Are you using nested configurations?No
-
Which Xcode version are you using (check
xcodebuild -version)? Xcode 11.4 Build version 11E146 -
Do you have a sample that shows the issue? Yes:
Test.swift
extension Test {
var foo: Bool {
get {
bar?.boolValue ?? true // Comment mentioning word set which triggers violation
}
set {
bar = NSNumber(value: newValue as Bool)
}
}
}
If I don’t mention word “set” in the comment then it seem to work fine. I don’t recall seeing this issues prior to updating to Xcode 11.4.
Hope it helps.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17
Commits related to this issue
- Fix false positives on implicit_getter with Swift 5.2+ Fixes #3149 — committed to realm/SwiftLint by marcelofabri 4 years ago
- Fix false positives on implicit_getter with Swift 5.2+ (#3151) Fixes #3149 — committed to realm/SwiftLint by marcelofabri 4 years ago
- Fix false positives on implicit_getter with Swift 5.2+ (#3151) Fixes #3149 — committed to scope-demo/SwiftLint by marcelofabri 4 years ago
thanks for everyone reporting different minimal examples! this has been very helpful to fix the issue quickly
I found another false-positive. When the
setis before thegetyou get warning. If it is the other way round then everything is all right. I believe another rule could be created to formalize the order of get-set.Command:
Output:
@jpsim my issues are fixed on the last
masterLooking forward to the fixing release. My code below still triggers this false positive on 0.39.1:
Update: it resolves if I move the getter above the setter: