forked from realm/SwiftLint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NumberSeparatorRuleExamples.swift
70 lines (58 loc) · 2.57 KB
/
NumberSeparatorRuleExamples.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// NumberSeparatorRuleExamples.swift
// SwiftLint
//
// Created by Marcelo Fabri on 12/29/16.
// Copyright © 2016 Realm. All rights reserved.
//
import Foundation
internal struct NumberSeparatorRuleExamples {
static let nonTriggeringExamples: [String] = {
return ["-", "+", ""].flatMap { (sign: String) -> [String] in
[
"let foo = \(sign)100",
"let foo = \(sign)1_000",
"let foo = \(sign)1_000_000",
"let foo = \(sign)1.000_1",
"let foo = \(sign)1_000_000.000_000_1",
"let binary = \(sign)0b10000",
"let binary = \(sign)0b1000_0001",
"let hex = \(sign)0xA",
"let hex = \(sign)0xAA_BB",
"let octal = \(sign)0o21",
"let octal = \(sign)0o21_1",
"let exp = \(sign)1_000_000.000_000e2"
]
}
}()
static let swift3TriggeringExamples = triggeringExamples(signs: ["↓-", "+↓", "↓"])
static let swift2TriggeringExamples = triggeringExamples(signs: ["-↓", "+↓", "↓"])
static let swift3Corrections = corrections(signs: [("↓-", "-"), ("+↓", "+"), ("↓", "")])
static let swift2Corrections = corrections(signs: [("-↓", "-"), ("+↓", "+"), ("↓", "")])
private static func triggeringExamples(signs: [String]) -> [String] {
return signs.flatMap { (sign: String) -> [String] in
[
"let foo = \(sign)10_0",
"let foo = \(sign)1000",
"let foo = \(sign)1000e2",
"let foo = \(sign)1__000",
"let foo = \(sign)1.0001",
"let foo = \(sign)1_000_000.000000_1",
"let foo = \(sign)1000000.000000_1"
]
}
}
private static func corrections(signs: [(String, String)]) -> [String: String] {
var result = [String: String]()
for (violation, sign) in signs {
result["let foo = \(violation)10_0"] = "let foo = \(sign)100"
result["let foo = \(violation)1000"] = "let foo = \(sign)1_000"
result["let foo = \(violation)1000e2"] = "let foo = \(sign)1_000e2"
result["let foo = \(violation)1__000"] = "let foo = \(sign)1_000"
result["let foo = \(violation)1.0001"] = "let foo = \(sign)1.000_1"
result["let foo = \(violation)1_000_000.000000_1"] = "let foo = \(sign)1_000_000.000_000_1"
result["let foo = \(violation)1000000.000000_1"] = "let foo = \(sign)1_000_000.000_000_1"
}
return result
}
}