Skip to content
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

isEmpty triggers false-positive when using with XCUIElementQuery #5182

Closed
2 tasks done
christiankm opened this issue Aug 17, 2023 · 1 comment
Closed
2 tasks done
Labels
acceptable-false-positive False positives caused by rules that are unavoidable due to missing type information.

Comments

@christiankm
Copy link
Contributor

New Issue Checklist

Describe the bug

When trying to compare the cell count in a table from XCUITests, the isEmpty rule triggers, when we're using code like .cells.count > 0.

Problem is, that XCUIElementQuery.cells is not an array and has no isEmpty property, hence the false positive.

I would consider this a bug in SwiftFormat for now, though it would be more appropriate to add an isEmpty property so we can use that, to the XCTest framework.

Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint

Environment

  • SwiftLint version (run swiftlint version to be sure)? 0.52.2
  • Installation method used (Homebrew, CocoaPods, building from source, etc)? Homebrew
  • Paste your configuration file:
# insert yaml contents here
  • Are you using nested configurations?
    If so, paste their relative paths and respective contents.
  • Which Xcode version are you using (check xcodebuild -version)?
  • 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 use swiftlint lint --path [file here] --no-cache --enable-all-rules.
// This triggers a violation:
XCTAssertTrue(app.tables["table"].cells.count > 0)
Skærmbillede 2023-08-15 kl  18 19 09
@marcelofabri
Copy link
Collaborator

SwiftLint doesn't have enough information to tell if the underlying object has an isEmpty method - that's the reason why this rule isn't enabled by default.

See #827 for more discussion.

@marcelofabri marcelofabri added the acceptable-false-positive False positives caused by rules that are unavoidable due to missing type information. label Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
acceptable-false-positive False positives caused by rules that are unavoidable due to missing type information.
Projects
None yet
Development

No branches or pull requests

2 participants