nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.77k stars 629 forks source link

isEmpty rule gives false positive with XCUIElementQuery.cells #1508

Open christiankm opened 1 year ago

christiankm commented 1 year ago

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.

Skærmbillede 2023-08-15 kl  18 18 56
nicklockwood commented 1 year ago

This is a known issue (mentioned in the README) and it's why the rule is disabled by default.

christiankm commented 1 year ago

This is a known issue (mentioned in the README) and it's why the rule is disabled by default.

Ah, I see that. Would it make sense to add explicit code to check for these known cases, and is that even possible?

nicklockwood commented 1 year ago

@christiankm SwiftFormat sees each file in isolation, so it can't know if a property defined in another file is an Array or something else.

For values defined in the same file, I could do it. I'm just not sure if it's worth the effort given that limitation.