One Declaration per File

Only a single declaration is allowed in a file

  • Identifier: one_declaration_per_file
  • Enabled by default: No
  • Supports autocorrection: No
  • Kind: idiomatic
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity warning

Non Triggering Examples

actor Foo {}
class Foo {}
extension Foo {}
struct S {
    struct N {}
}

Triggering Examples

class Foo {}
class Bar {}
protocol Foo {}
enum Bar {}
struct Foo {}
struct Bar {}