Skip to content

Commit 3d33d57

Browse files
committed
Fix some linting errors
1 parent 66902f0 commit 3d33d57

File tree

4 files changed

+58
-93
lines changed

4 files changed

+58
-93
lines changed

index.js

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ let zoneCfg1970 = {}
3232
let zoneCfgNow = {}
3333
const expectedZoneOverlaps = require('./expectedZoneOverlaps.json')
3434

35-
const fiveYearsAgo = (new Date()).getFullYear()
36-
3735
const argv = yargs
3836
.option('cache_dir', {
3937
description: 'Set the cache location, for caching results',
@@ -114,7 +112,7 @@ function loadJsonCacheSync (filename) {
114112
)
115113
} catch (err) {
116114
// cache not found, return empty obj
117-
return {}
115+
return {}
118116
}
119117
}
120118

@@ -142,7 +140,7 @@ function getZoneCfgSinceTime (cutoffTime, cacheFilename) {
142140
tzdbInitialized = true
143141
}
144142

145-
let newZoneCfg = {}
143+
const newZoneCfg = {}
146144

147145
// Iterate through all zones to determine which share same timekeeping method since cutoff time
148146
const timekeepingPatternZones = {}
@@ -165,7 +163,7 @@ function getZoneCfgSinceTime (cutoffTime, cacheFilename) {
165163
timekeepingPatternZones[timekeepingKey].push(zone)
166164
})
167165

168-
// iterate through each set of zones with the same future timekeeping method to determine
166+
// iterate through each set of zones with the same future timekeeping method to determine
169167
// which has the largest population
170168
Object.keys(timekeepingPatternZones).forEach(k => {
171169
timekeepingPatternZones[k].sort((a, b) => getTimezonePopulation(b) - getTimezonePopulation(a))
@@ -180,15 +178,15 @@ function getZoneCfgSinceTime (cutoffTime, cacheFilename) {
180178
if (!argv.skip_now_zones) {
181179
console.log('Generating zone config for zones with the same timekeeping method since now')
182180
zoneCfgNow = getZoneCfgSinceTime(
183-
(new Date()).getTime(),
181+
(new Date()).getTime(),
184182
path.join(cacheDir, 'zone-config-now.json')
185183
)
186184
}
187185

188186
if (!argv.skip_1970_zones) {
189187
console.log('Generating zone config for zones with the same timekeeping method since 1970')
190188
zoneCfg1970 = getZoneCfgSinceTime(
191-
0,
189+
0,
192190
path.join(cacheDir, 'zone-config-1970.json')
193191
)
194192
}
@@ -204,7 +202,7 @@ if (argv.included_zones || argv.excluded_zones) {
204202
includedZones = argv.included_zones
205203
includedZones.forEach((zoneName) => {
206204
if (
207-
!zoneCfg[zoneName] ||
205+
!zoneCfg[zoneName] ||
208206
(!argv.skip_1970_zones && !zoneCfg1970[zoneName]) ||
209207
(!argv.skip_now_zones && !zoneCfgNow[zoneName])
210208
) {
@@ -226,7 +224,7 @@ if (argv.included_zones || argv.excluded_zones) {
226224
excludedZones = argv.excluded_zones
227225
Object.keys(zoneCfg).forEach((zoneName) => {
228226
if (
229-
!zoneCfg[zoneName] ||
227+
!zoneCfg[zoneName] ||
230228
(!argv.skip_1970_zones && !zoneCfg1970[zoneName]) ||
231229
(!argv.skip_now_zones && !zoneCfgNow[zoneName])
232230
) {
@@ -559,14 +557,14 @@ function downloadOsmTimezoneBoundary (tzId, boundaryCallback) {
559557
// the downloads directory is cleared of all timezone boundaries not downloaded from OSM (there
560558
// are still a few in here with manual definitions). Therefore, keep a copy of all OSM downloads
561559
// so they aren't redownloaded during multiple reruns of the script
562-
560+
563561
function copyToOsmDownloadFolder (err) {
564562
if (err) return boundaryCallback(err)
565563
fs.copyFile(boundaryFilename, workingBoundaryFilename, boundaryCallback)
566564
}
567565

568-
// Before downloading from Overpass, check if there's a copy in the working folder. Since osm
569-
// downloads are always after production zones, it is safe to copy an osm boundary because a
566+
// Before downloading from Overpass, check if there's a copy in the working folder. Since osm
567+
// downloads are always after production zones, it is safe to copy an osm boundary because a
570568
// production one would've already been downloaded in the event it were deleted in order to force
571569
// the retrieval of a new zone.
572570
fs.stat(
@@ -771,7 +769,7 @@ function makeTimezoneBoundaries (callback) {
771769
calculateFn: calculateCb => {
772770
console.log(`makeTimezoneBoundary for ${tzid}`)
773771
asynclib.eachSeries(
774-
ops,
772+
ops,
775773
(task, taskCb) => {
776774
const taskData = getDataSource(task)
777775
console.log('-', task.op, task.id)
@@ -812,23 +810,23 @@ function makeTimezoneBoundaries (callback) {
812810

813811
function makeDerivedTimezoneBoundaries (strategy, callback) {
814812
const cfg = (
815-
strategy === '1970' ?
816-
{
817-
cacheFilename: path.join(cacheDir, 'derived-1970-cache.json'),
818-
derivedZoneConfig: zoneCfg1970,
819-
getFinalTzFilenameFn: getFinal1970TzOutputFilename,
820-
loadZonesInMemoryFn: loadFinal1970ZonesIntoMemory,
821-
progressStatsName: 'Building 1970 zones',
822-
progressStatsUpdatePrefix: 'make1970TimezoneBoundary for',
823-
} :
824-
{
825-
cacheFilename: path.join(cacheDir, 'derived-now-cache.json'),
826-
derivedZoneConfig: zoneCfgNow,
827-
getFinalTzFilenameFn: getFinalNowTzOutputFilename,
828-
loadZonesInMemoryFn: loadFinalNowZonesIntoMemory,
829-
progressStatsName: 'Building Now zones',
830-
progressStatsUpdatePrefix: 'makeNowTimezoneBoundary for',
831-
}
813+
strategy === '1970'
814+
? {
815+
cacheFilename: path.join(cacheDir, 'derived-1970-cache.json'),
816+
derivedZoneConfig: zoneCfg1970,
817+
getFinalTzFilenameFn: getFinal1970TzOutputFilename,
818+
loadZonesInMemoryFn: loadFinal1970ZonesIntoMemory,
819+
progressStatsName: 'Building 1970 zones',
820+
progressStatsUpdatePrefix: 'make1970TimezoneBoundary for'
821+
}
822+
: {
823+
cacheFilename: path.join(cacheDir, 'derived-now-cache.json'),
824+
derivedZoneConfig: zoneCfgNow,
825+
getFinalTzFilenameFn: getFinalNowTzOutputFilename,
826+
loadZonesInMemoryFn: loadFinalNowZonesIntoMemory,
827+
progressStatsName: 'Building Now zones',
828+
progressStatsUpdatePrefix: 'makeNowTimezoneBoundary for'
829+
}
832830
)
833831

834832
const buildingProgress = new ProgressStats(
@@ -843,32 +841,32 @@ function makeDerivedTimezoneBoundaries (strategy, callback) {
843841

844842
tzBoundaryCache.init(() => {
845843
asynclib.each(
846-
Object.keys(cfg.derivedZoneConfig),
844+
Object.keys(cfg.derivedZoneConfig),
847845
(tzid, cb) => {
848846
const message = `${cfg.progressStatsUpdatePrefix} ${tzid}`
849847
buildingProgress.beginTask(message, true)
850-
848+
851849
tzBoundaryCache.calculate({
852850
cacheKey: hashMd5(cfg.derivedZoneConfig[tzid].map(getZoneGeomHash)),
853851
outputFilename: cfg.getFinalTzFilenameFn(tzid),
854852
calculateFn: calculateCb => {
855853
console.log(message)
856854
let geom = getDataSource({ source: 'final', id: tzid })
857-
855+
858856
cfg.derivedZoneConfig[tzid].forEach(zone => {
859857
console.log('-', zone)
860858
if (zone === tzid) return
861859
const zoneData = getDataSource({ source: 'final', id: zone })
862860
geom = debugGeo('union', geom, zoneData)
863861
})
864-
862+
865863
calculateCb(null, postProcessZone(geom))
866864
},
867865
callback: cb
868866
})
869-
},
867+
},
870868
err => {
871-
if (err) return cb(err)
869+
if (err) return callback(err)
872870
cfg.loadZonesInMemoryFn()
873871
tzBoundaryCache.end(callback)
874872
}
@@ -919,7 +917,7 @@ const getZoneGeomHash = memoize((tzid) => {
919917
try {
920918
fs.statSync(zoneFilename)
921919
} catch (err) {
922-
return `${tzid}-filenotfound`
920+
return `${tzid}-filenotfound`
923921
}
924922
return `${tzid}-${hasha.fromFileSync(zoneFilename, { algorithm: 'md5' })}`
925923
})
@@ -1079,7 +1077,7 @@ function validateTimezoneBoundaries (callback) {
10791077
}
10801078
validationCache.end((err) => callback(err || error))
10811079
}
1082-
)
1080+
)
10831081
})
10841082
}
10851083

@@ -1144,26 +1142,26 @@ function addOceans (callback) {
11441142
[oceanZone.right, 90],
11451143
[oceanZone.left, 90]
11461144
]]).geometry
1147-
1145+
11481146
let oceanGeom = geoJsonToGeom(geoJson)
1149-
1147+
11501148
// filter zones to those that have bounds that apply
11511149
const tzsInBounds = zones.filter(tzid => {
1152-
zoneEnvelope = finalZones[tzid].getEnvelopeInternal()
1150+
const zoneEnvelope = finalZones[tzid].getEnvelopeInternal()
11531151
return !(
1154-
zoneEnvelope.getMaxX() < oceanZone.left ||
1152+
zoneEnvelope.getMaxX() < oceanZone.left ||
11551153
zoneEnvelope.getMinX() > oceanZone.right
11561154
)
11571155
})
1158-
1156+
11591157
oceanBoundaryCache.calculate({
11601158
cacheKey: `${oceanZone.tzid}-${hashMd5(tzsInBounds.map(getZoneGeomHash))}`,
11611159
calculateFn: calculateCb => {
11621160
// diff against applicable zones
11631161
tzsInBounds.forEach(finalZone => {
11641162
oceanGeom = debugGeo('diff', oceanGeom, finalZones[finalZone])
11651163
})
1166-
1164+
11671165
calculateCb(null, {
11681166
geom: postProcessZone(oceanGeom, true),
11691167
tzid: oceanZone.tzid
@@ -1187,15 +1185,15 @@ function combineAndWriteZones (callback) {
11871185
let ocean1970Writer
11881186
let regularNowWriter
11891187
let oceanNowWriter
1190-
1188+
11911189
if (!argv.skip_1970_zones) {
11921190
regular1970Writer = new FeatureWriterStream(workingDir + '/combined-1970.json')
1193-
ocean1970Writer = new FeatureWriterStream(workingDir + '/combined-with-oceans-1970.json')
1191+
ocean1970Writer = new FeatureWriterStream(workingDir + '/combined-with-oceans-1970.json')
11941192
}
1195-
1193+
11961194
if (!argv.skip_now_zones) {
11971195
regularNowWriter = new FeatureWriterStream(workingDir + '/combined-now.json')
1198-
oceanNowWriter = new FeatureWriterStream(workingDir + '/combined-with-oceans-now.json')
1196+
oceanNowWriter = new FeatureWriterStream(workingDir + '/combined-with-oceans-now.json')
11991197
}
12001198

12011199
Object.keys(zoneCfg).forEach(zoneName => {
@@ -1350,7 +1348,7 @@ function zipGeoJsonFiles (cb) {
13501348
)
13511349
}
13521350

1353-
function makeShapefile(config, cb) {
1351+
function makeShapefile (config, cb) {
13541352
rimraf(config.shapeFileGlob, rimrafErr => {
13551353
if (rimrafErr) { return cb(rimrafErr) }
13561354
exec(
@@ -1461,7 +1459,7 @@ function analyzeChangesFromLastRelease (cb) {
14611459
lastReleaseZone.geometry
14621460
).buffer(bufferDistance)
14631461
const curDataGeom = finalZone.buffer(bufferDistance)
1464-
1462+
14651463
// don't diff equal geometries
14661464
if (!curDataGeom.equals(lastReleaseGeom)) {
14671465
// diff current - last = additions
@@ -1475,7 +1473,7 @@ function analyzeChangesFromLastRelease (cb) {
14751473
if (addition.getArea() > 0.0001) {
14761474
results.addition = geomToGeoJson(addition)
14771475
}
1478-
1476+
14791477
// diff last - current = removals
14801478
const removal = debugGeo(
14811479
'diff',
@@ -1531,7 +1529,7 @@ function analyzeChangesFromLastRelease (cb) {
15311529
}
15321530

15331531
const autoScript = {
1534-
makeCacheDirAndFns: function(cb) {
1532+
makeCacheDirAndFns: function (cb) {
15351533
overallProgress.beginTask(`Creating downloads dir (${downloadsDir})`)
15361534
asynclib.series([
15371535
mcb => safeMkdir(cacheDir, mcb),
@@ -1650,7 +1648,7 @@ const autoScript = {
16501648
jsonFile: path.join(workingDir, 'combined-osm-zones.json'),
16511649
shapeFile: path.join(workingDir, 'combined-osm-zone-shapefile.shp'),
16521650
shapeFileGlob: path.join(workingDir, 'combined-osm-zone-shapefile.*')
1653-
},
1651+
},
16541652
cb
16551653
)
16561654
}],

lint-json.js

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const osmBoundarySources = require('./osmBoundarySources.json')
22
const zoneCfg = require('./timezones.json')
33
const expectedZoneOverlaps = require('./expectedZoneOverlaps.json')
4-
const zoneCfg1970 = require('./timezones-1970.json')
54

65
let numErrors = 0
76

@@ -49,35 +48,6 @@ Object.keys(expectedZoneOverlaps).forEach(zoneOverlap => {
4948
})
5049
})
5150

52-
// Check 1970 zones for:
53-
// 1. All full timezone names being included in 1970 components
54-
// 2. Component timezones are only ever used once
55-
// 3. No zones being in 1970 that aren't in the full timezone set
56-
const zonesFoundToMake1970 = new Set()
57-
Object.keys(zoneCfg1970).forEach(zone => {
58-
zoneCfg1970[zone].forEach(zoneComponent => {
59-
// check if 1970 zone is used twice
60-
if (zonesFoundToMake1970.has(zoneComponent)) {
61-
numErrors++
62-
console.error(`${zoneComponent} used twice to make a 1970 zone`)
63-
}
64-
zonesFoundToMake1970.add(zoneComponent)
65-
66-
// check if 1970 zone is present in zone config
67-
if (!zoneCfg[zoneComponent]) {
68-
numErrors++
69-
console.error(`${zoneComponent} not used in full timezone set`)
70-
}
71-
})
72-
})
73-
74-
Object.keys(zoneCfg).forEach(zone => {
75-
if (!zonesFoundToMake1970.has(zone)) {
76-
numErrors++
77-
console.error(`${zone} not used as a component to make a 1970 zone`)
78-
}
79-
})
80-
8151
if (numErrors > 0) {
8252
console.error(`${numErrors} errors found`)
8353
process.exit(1)

osmBoundarySources.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,6 @@
479479
"America-Ojinaga-tz": {
480480
"timezone": "America/Ojinaga"
481481
},
482-
"America-Panama-tz": {
483-
"timezone": "America/Panama"
484-
},
485482
"America-Paramaribo-tz": {
486483
"timezone": "America/Paramaribo"
487484
},

util/cache.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ class BaseFileCache {
1919
return cb()
2020
} else {
2121
try {
22-
this.oldCache = JSON.parse(data)
22+
this.oldCache = JSON.parse(data)
2323
} catch (error) {}
2424
cb()
2525
}
2626
}
27-
)
27+
)
2828
}
2929

3030
end (cb) {
3131
fs.writeFile(
32-
this.filename,
32+
this.filename,
3333
JSON.stringify(this.newCache),
3434
cb
3535
)
@@ -57,7 +57,7 @@ class FileCache extends BaseFileCache {
5757
}
5858
}
5959

60-
class FileLookupCache extends BaseFileCache{
60+
class FileLookupCache extends BaseFileCache {
6161
calculate ({
6262
cacheKey,
6363
outputFilename,
@@ -72,8 +72,8 @@ class FileLookupCache extends BaseFileCache{
7272
calculateFn((err, data) => {
7373
if (err) return callback(err)
7474
fs.writeFile(
75-
outputFilename,
76-
data,
75+
outputFilename,
76+
data,
7777
error => {
7878
if (error) return callback(error)
7979
hasha.fromFile(outputFilename, hashaOpts)
@@ -116,4 +116,4 @@ class FileLookupCache extends BaseFileCache{
116116
module.exports = {
117117
FileCache,
118118
FileLookupCache
119-
}
119+
}

0 commit comments

Comments
 (0)