Skip to content

noGuardInTests rule removes array bounds checks #2193

@nicklockwood

Description

@nicklockwood

@calda I was testing out the new noGuardInTests rule in one of my projects. It works great for cases like this:

guard let intersection = plane1.intersection(with: plane2) else {
    XCTFail()
    return
}

XCTAssertEqual(intersection, Line(origin: [-1, 0, 1], direction: -.unitY))

However I had to disable it because it was also removing the guard in cases like this:

guard polygons.count > 1 else {
    return
}

let a = Set(polygons[0].vertices.map(\.position))

I wonder if there's a way to make it configurable to only apply in the former and not the latter cases?

It's probably too complex to try to examine the condition itself for bounds checks, but perhaps we could have an option to only remove guard let constructs and not other types of guard?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions