mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
fcf848608e
* Add Example wrapper in order to display test failures inline when running in Xcode. * Stop using Swift 5.1-only features so we can compile on Xcode 10.2. * Wrap strings in Example. * Add Changelog entry. * Wrap all examples in Example struct. * Better and more complete capturing of line numbers. * Fix broken test. * Better test traceability. * Address or disable linting warnings. * Add documentation comments. * Disable linter for a few cases. * Limit mutability and add copy-and-mutate utility functions. * Limit scope of mutability.
72 lines
3.4 KiB
Swift
72 lines
3.4 KiB
Swift
internal struct NumberSeparatorRuleExamples {
|
|
static let nonTriggeringExamples: [Example] = {
|
|
return ["-", "+", ""].flatMap { (sign: String) -> [Example] in
|
|
[
|
|
Example("let foo = \(sign)100"),
|
|
Example("let foo = \(sign)1_000"),
|
|
Example("let foo = \(sign)1_000_000"),
|
|
Example("let foo = \(sign)1.000_1"),
|
|
Example("let foo = \(sign)1_000_000.000_000_1"),
|
|
Example("let binary = \(sign)0b10000"),
|
|
Example("let binary = \(sign)0b1000_0001"),
|
|
Example("let hex = \(sign)0xA"),
|
|
Example("let hex = \(sign)0xAA_BB"),
|
|
Example("let octal = \(sign)0o21"),
|
|
Example("let octal = \(sign)0o21_1"),
|
|
Example("let exp = \(sign)1_000_000.000_000e2"),
|
|
Example("let foo: Double = \(sign)(200)"),
|
|
Example("let foo: Double = \(sign)(200 / 447.214)")
|
|
]
|
|
}
|
|
}()
|
|
|
|
static let triggeringExamples = makeTriggeringExamples(signs: ["↓-", "+↓", "↓"]) +
|
|
makeTriggeringExamplesWithParentheses()
|
|
|
|
static let corrections = makeCorrections(signs: [("↓-", "-"), ("+↓", "+"), ("↓", "")])
|
|
|
|
private static func makeTriggeringExamples(signs: [String]) -> [Example] {
|
|
return signs.flatMap { (sign: String) -> [Example] in
|
|
[
|
|
Example("let foo = \(sign)10_0"),
|
|
Example("let foo = \(sign)1000"),
|
|
Example("let foo = \(sign)1000e2"),
|
|
Example("let foo = \(sign)1000E2"),
|
|
Example("let foo = \(sign)1__000"),
|
|
Example("let foo = \(sign)1.0001"),
|
|
Example("let foo = \(sign)1_000_000.000000_1"),
|
|
Example("let foo = \(sign)1000000.000000_1")
|
|
]
|
|
}
|
|
}
|
|
|
|
private static func makeTriggeringExamplesWithParentheses() -> [Example] {
|
|
let signsWithParenthesisAndViolation = ["↓-(", "+(↓", "(↓"]
|
|
return signsWithParenthesisAndViolation.flatMap { (sign: String) -> [Example] in
|
|
[
|
|
Example("let foo: Double = \(sign)100000)"),
|
|
Example("let foo: Double = \(sign)10.000000_1)"),
|
|
Example("let foo: Double = \(sign)123456 / ↓447.214214)")
|
|
]
|
|
}
|
|
}
|
|
|
|
private static func makeCorrections(signs: [(String, String)]) -> [Example: Example] {
|
|
var result = [Example: Example]()
|
|
|
|
for (violation, sign) in signs {
|
|
result[Example("let foo = \(violation)10_0")] = Example("let foo = \(sign)100")
|
|
result[Example("let foo = \(violation)1000")] = Example("let foo = \(sign)1_000")
|
|
result[Example("let foo = \(violation)1000e2")] = Example("let foo = \(sign)1_000e2")
|
|
result[Example("let foo = \(violation)1000E2")] = Example("let foo = \(sign)1_000E2")
|
|
result[Example("let foo = \(violation)1__000")] = Example("let foo = \(sign)1_000")
|
|
result[Example("let foo = \(violation)1.0001")] = Example("let foo = \(sign)1.000_1")
|
|
// swiftlint:disable:next line_length
|
|
result[Example("let foo = \(violation)1_000_000.000000_1")] = Example("let foo = \(sign)1_000_000.000_000_1")
|
|
result[Example("let foo = \(violation)1000000.000000_1")] = Example("let foo = \(sign)1_000_000.000_000_1")
|
|
}
|
|
|
|
return result
|
|
}
|
|
}
|