Can SwiftLint ignore classes (not files) by suffix? Namely SwiftUI _Preview classes?

362 views Asked by At

Most of my SwiftUI classes have an auto generated (from template) ClassName_Previews class at the bottom of the file.

I'd like SwiftLint to ignore anything ending in _Previews for ALL rules. Or anything that extends PreviewProvider.

I know how to exclude files and directories, but not classes.

Is this even possible? Any help would be appreciated!

Edit: Since I have so many preview classes, I'd prefer not to manually have to add // swiftlint:disable all and it's enable counterpart. I realize going forward I can add those lines into my template!

1

There are 1 answers

1
Asperi On

Here is possible variant

// swiftlint:disable all
struct Demo_Previews: PreviewProvider {
    static var previews: some View {
        DemoView()
    }
}
// swiftlint:enable all