False-positive for `xct_specific_matcher ` rule with optional boolean
Open
Nobody has claimed this yet.
acceptable-false-positive
bug
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
Describe the bug
The xct_specific_matcher rule should not trigger when one of its arguments is an optional boolean.
Complete output when running SwiftLint, including the stack trace and command used
$ Pods/SwiftLint/swiftlint lint TestTests/TestTests.swift
Linting Swift files at paths TestTests/TestTests.swift
Linting 'TestTests.swift' (1/1)
/Users/gif/Desktop/Test/TestTests/TestTests.swift:17:5: warning: XCTest Specific Matcher Violation: Prefer the specific matcher 'XCTAssertTrue' instead. (xct_specific_matcher)
Done linting! Found 1 violation, 0 serious in 1 file.
Environment
- SwiftLint version (run
swiftlint versionto be sure)?
0.43.0 - Installation method used (Homebrew, CocoaPods, building from source, etc)?
CocoaPods - Paste your configuration file:
only_rules:
# Prefer specific XCTest matchers over XCTAssertEqual and XCTAssertNotEqual
- xct_specific_matcher
- Are you using nested configurations?
If so, paste their relative paths and respective contents. - Which Xcode version are you using (check
xcodebuild -version)?
12.3 - Do you have a sample that shows the issue? Run
echo "[string here]" | swiftlint lint --no-cache --use-stdin --enable-all-rules
to quickly test if your example is really demonstrating the issue. If your example is more
complex, you can useswiftlint lint --path [file here] --no-cache --enable-all-rules.
class TestTests: XCTestCase {
var optionalBoolean: Bool? {
return false
}
func testExample() throws {
// This triggers a violation:
XCTAssertEqual(self.optionalBoolean, true)
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported violation with the xct_specific_matcher rule and the optional Bool example in TestTests.swift. Trace the rule's handling of XCTAssertEqual arguments and add coverage showing that an optional boolean does not trigger the violation; the lint command should then report no warning for that case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- testing, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100