struct Email {
struct Constraints {
static let top = 20.asConstraint()
}
static let placeholder = "login_email"
}
How to fix that issue?
This particular rule of SwiftLint, nesting
, has priorly been discussed in the following Q&A:
With somewhat of an consensus that this rule is not based on a technical reason, but rather seem to be an opinion-based "best practice" rule, noticeably not one followed e.g. by the Swift standard libs (which use nested type frequently). Moreover, the Swift language guide, specifically the Nested Types Section, contains no warning for/recommendation against nesting type deeper than depth 1.
... Types can be nested to as many levels as are required.
One motivation for this (opinion-based rule) can be found in SwiftLint issue 1450:
jpsim:
The nesting rule exists for two reasons:
- to avoid overly-nested types in an API
- to avoid overly-indented statements (aka pyramid of doom)
...
Based on the above, unless you find your code turning into unreadable pyramid of doom spaghetti (which I don't believe to be the case in your example), you could simply considering disabling the nesting
rule:
// swiftlint:disable nesting
You can create another struct:
struct Email {
let constraints = EmailConstraints()
let placeholder = "login_email"
}
struct EmailConstraints {
let top = 20.asConstraint()
}
As you mentioned later on in comments, since this is only a linter error, you can disable this rule in swiftlint.yml file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With