forked from AlphaWallet/alpha-wallet-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dangerfile.js
90 lines (79 loc) · 3.08 KB
/
dangerfile.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const {danger, warn} = require('danger')
if (danger.github) {
} else {
warnHTMLLocalizationMissing()
warnStringLocalizationMissing()
warnClosureStronglyCapturesSelf()
failUsingNSLocalizedStringWithoutR()
failIfRemoveAnyRealmSchemaMigrationBlock()
failIfUseDecimalExactlyInit()
checkForSpacesInOtherwiseEmptyLines()
}
function warnHTMLLocalizationMissing() {
const changedHtmlFiles = danger.git.modified_files.filter(f => f.includes("/en.lproj/") && f.includes(".html"))
changedHtmlFiles.forEach(each =>
warn("HTML changed. Double check that you have changed it for all languages, or will do so in another PR: " + each)
)
}
function warnStringLocalizationMissing() {
const includesLocalizationChanges = danger.git.modified_files.filter(f => f == "AlphaWallet/Localization/en.lproj/Localizable.strings").length > 0
if (includesLocalizationChanges) {
warn("Localization file changed. Double check that you have changed it for all languages, or will do so in another PR")
}
}
function warnClosureStronglyCapturesSelf() {
modifiedSwiftFiles().forEach(each => {
danger.git.diffForFile(each).then(diff => {
if (diff.added.includes("self.")) {
warn(each + ": added `self.`. Double check if closure strongly captures `self`.")
}
})
})
}
function failUsingNSLocalizedStringWithoutR() {
modifiedSwiftFiles().forEach(each => {
danger.git.diffForFile(each).then(diff => {
if (diff.added.includes("NSLocalizedString")) {
fail(each + ": added `NSLocalizedString`. Should use `R.string.localizable` instead.")
}
})
})
}
function failIfRemoveAnyRealmSchemaMigrationBlock() {
modifiedSwiftFiles().forEach(each => {
danger.git.diffForFile(each).then(diff => {
if (diff.removed.includes("if oldSchemaVersion <")) {
fail(each + ": removed `if oldSchemaVersion <`. Migration blocks for previous versions should never be removed.")
}
})
})
}
//Can't use Decimal(exactly: aBigUint). It compiles but crashes at runtime
function failIfUseDecimalExactlyInit() {
modifiedSwiftFiles().forEach(each => {
danger.git.diffForFile(each).then(diff => {
if (diff.added.includes("Decimal(exactly:")) {
fail(each + ": Must not use Decimal(exactly:), especially on BigUInt. Use Decimal(string: aBigUint.description) instead")
}
})
})
}
function checkForSpacesInOtherwiseEmptyLines() {
modifiedSwiftFiles().forEach(each => {
danger.git.diffForFile(each).then(diff => {
if (diff.added.includes(" \n")) {
fail(each + ": leading spaces for otherwise empty lines should be removed.")
}
})
})
}
function modifiedSwiftFiles() {
return danger.git.modified_files.filter(f => f.includes(".swift"))
}
function intersect(a, b) {
var t;
if (b.length > a.length) t = b, b = a, a = t; // indexOf to loop over shorter
return a.filter(function (e) {
return b.indexOf(e) > -1;
});
}