Evan Siroky | 081c8e4 | 2017-05-29 14:53:52 -0700 | [diff] [blame] | 1 | const osmBoundarySources = require('./osmBoundarySources.json') |
| 2 | const zoneCfg = require('./timezones.json') |
evansiroky | 92c15c4 | 2018-11-15 20:58:18 -0800 | [diff] [blame] | 3 | const expectedZoneOverlaps = require('./expectedZoneOverlaps.json') |
Evan Siroky | 081c8e4 | 2017-05-29 14:53:52 -0700 | [diff] [blame] | 4 | |
| 5 | let numErrors = 0 |
| 6 | |
| 7 | const sourcesUsage = {} |
| 8 | Object.keys(osmBoundarySources).forEach(source => { |
| 9 | sourcesUsage[source] = false |
| 10 | }) |
| 11 | |
| 12 | Object.keys(zoneCfg).forEach(zone => { |
Evan Siroky | 628ba25 | 2017-07-04 10:46:14 -0700 | [diff] [blame] | 13 | zoneCfg[zone].forEach((operation, idx) => { |
Evan Siroky | 081c8e4 | 2017-05-29 14:53:52 -0700 | [diff] [blame] | 14 | if (operation.source === 'overpass') { |
| 15 | // check if source is defined |
| 16 | if (!osmBoundarySources[operation.id]) { |
| 17 | numErrors++ |
| 18 | |
| 19 | console.error(`No osmBoundarySources config found for entry: ${operation.id}`) |
| 20 | } else { |
| 21 | sourcesUsage[operation.id] = true |
| 22 | } |
Evan Siroky | 628ba25 | 2017-07-04 10:46:14 -0700 | [diff] [blame] | 23 | } else if (operation.source.indexOf('manual') > -1 && |
| 24 | (!operation.description || |
| 25 | operation.description.length < 3)) { |
| 26 | numErrors++ |
| 27 | |
| 28 | console.error(`No description of ${operation.source} for operation ${idx} of zone: ${zone}`) |
Evan Siroky | 081c8e4 | 2017-05-29 14:53:52 -0700 | [diff] [blame] | 29 | } |
| 30 | }) |
| 31 | }) |
| 32 | |
| 33 | // check for sources not used in timezone building |
| 34 | Object.keys(sourcesUsage).forEach(source => { |
| 35 | if (!sourcesUsage[source]) { |
| 36 | numErrors++ |
| 37 | console.error(`osmBoundarySources config "${source}" is never used in timezone boundary building`) |
| 38 | } |
| 39 | }) |
| 40 | |
evansiroky | 92c15c4 | 2018-11-15 20:58:18 -0800 | [diff] [blame] | 41 | // Make sure all expected zone overlaps have a description |
| 42 | Object.keys(expectedZoneOverlaps).forEach(zoneOverlap => { |
| 43 | expectedZoneOverlaps[zoneOverlap].forEach((overlapBounds, idx) => { |
| 44 | if (!overlapBounds.description || overlapBounds.description.length < 3) { |
| 45 | numErrors++ |
| 46 | console.error(`Expected overlap #${idx} of zones ${zoneOverlap} missing description`) |
| 47 | } |
| 48 | }) |
| 49 | }) |
| 50 | |
Evan Siroky | 081c8e4 | 2017-05-29 14:53:52 -0700 | [diff] [blame] | 51 | if (numErrors > 0) { |
| 52 | console.error(`${numErrors} errors found`) |
| 53 | process.exit(1) |
| 54 | } else { |
| 55 | console.log('No linting errors!') |
| 56 | } |