-
-
Notifications
You must be signed in to change notification settings - Fork 83
/
lint-json.js
56 lines (48 loc) · 1.7 KB
/
lint-json.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
const osmBoundarySources = require('./osmBoundarySources.json')
const zoneCfg = require('./timezones.json')
const expectedZoneOverlaps = require('./expectedZoneOverlaps.json')
let numErrors = 0
const sourcesUsage = {}
Object.keys(osmBoundarySources).forEach(source => {
sourcesUsage[source] = false
})
Object.keys(zoneCfg).forEach(zone => {
zoneCfg[zone].forEach((operation, idx) => {
if (operation.source === 'overpass') {
// check if source is defined
if (!osmBoundarySources[operation.id]) {
numErrors++
console.error(`No osmBoundarySources config found for entry: ${operation.id}`)
} else {
sourcesUsage[operation.id] = true
}
} else if (operation.source.indexOf('manual') > -1 &&
(!operation.description ||
operation.description.length < 3)) {
numErrors++
console.error(`No description of ${operation.source} for operation ${idx} of zone: ${zone}`)
}
})
})
// check for sources not used in timezone building
Object.keys(sourcesUsage).forEach(source => {
if (!sourcesUsage[source]) {
numErrors++
console.error(`osmBoundarySources config "${source}" is never used in timezone boundary building`)
}
})
// Make sure all expected zone overlaps have a description
Object.keys(expectedZoneOverlaps).forEach(zoneOverlap => {
expectedZoneOverlaps[zoneOverlap].forEach((overlapBounds, idx) => {
if (!overlapBounds.description || overlapBounds.description.length < 3) {
numErrors++
console.error(`Expected overlap #${idx} of zones ${zoneOverlap} missing description`)
}
})
})
if (numErrors > 0) {
console.error(`${numErrors} errors found`)
process.exit(1)
} else {
console.log('No linting errors!')
}