Skip to content

Commit a129654

Browse files
committed
Configured eslint / cleanup
1 parent 05015d4 commit a129654

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+829
-845
lines changed

.eslintrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "naturalatlas/base",
3+
"rules": {
4+
"no-shadow": 0,
5+
"key-spacing": 0
6+
}
7+
}

Makefile

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: clean clean-test build rebuild release test test-concurrent format-code authors
1+
.PHONY: clean clean-test build rebuild release test test-concurrent test-syntax authors
22

33
MOCHA_ARGS=test -R list -gc --require ./test/_common.js
44

@@ -22,15 +22,6 @@ clean-test:
2222
@rm -rf ./test/**/*.tmp*
2323
@rm -rf ./test/data/**/*.tmp*
2424

25-
format-code:
26-
astyle \
27-
--indent=force-tab=4 \
28-
--indent-namespaces \
29-
--add-brackets \
30-
--style=stroustrup \
31-
./src/*
32-
@rm -rf ./src/*.orig
33-
3425
./node_modules/.bin/node-pre-gyp:
3526
npm install node-pre-gyp
3627

@@ -54,6 +45,9 @@ test-shared: clean-test build-shared
5445
./node_modules/.bin/mocha $(MOCHA_ARGS)
5546
@make clean-test
5647

48+
test-syntax:
49+
npm run test-syntax
50+
5751
test-concurrent: clean-test
5852
node ./node_modules/.bin/_mocha \
5953
& node ./node_modules/.bin/_mocha \

examples/gdalinfo.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ var corners = {
3939
'Upper Right ' : {x: size.x, y: 0},
4040
'Bottom Right' : {x: size.x, y: size.y},
4141
'Bottom Left ' : {x: 0, y: size.y},
42-
'Center ' : {x: size.x/2, y: size.y/2}
42+
'Center ' : {x: size.x / 2, y: size.y / 2}
4343
};
4444

4545
var wgs84 = gdal.SpatialReference.fromEPSG(4326);
4646
var coord_transform = new gdal.CoordinateTransformation(ds.srs, wgs84);
4747

48-
console.log("Corner Coordinates:")
48+
console.log('Corner Coordinates:');
4949
var corner_names = Object.keys(corners);
5050
corner_names.forEach(function(corner_name) {
5151
// convert pixel x,y to the coordinate system of the raster
@@ -54,7 +54,7 @@ corner_names.forEach(function(corner_name) {
5454
var pt_orig = {
5555
x: geotransform[0] + corner.x * geotransform[1] + corner.y * geotransform[2],
5656
y: geotransform[3] + corner.x * geotransform[4] + corner.y * geotransform[5]
57-
}
57+
};
5858
var pt_wgs84 = coord_transform.transformPoint(pt_orig);
5959
var description = util.format('%s (%d, %d) (%s, %s)',
6060
corner_name,
@@ -67,7 +67,7 @@ corner_names.forEach(function(corner_name) {
6767
});
6868

6969
// bands
70-
ds.bands.forEach(function(band){
70+
ds.bands.forEach(function(band) {
7171
var description = util.format('Band %d Block=%dx%d Type=%s, ColorInterp=%s',
7272
band.id,
7373
band.blockSize.x,
@@ -78,21 +78,21 @@ ds.bands.forEach(function(band){
7878
console.log(description);
7979

8080
if (band.description) {
81-
console.log(' Description = '+band.description);
81+
console.log(' Description = ' + band.description);
8282
}
8383
console.log(' Min=' + Math.floor(band.minimum * 1000) / 1000);
8484
console.log(' Max=' + Math.floor(band.maximum * 1000) / 1000);
8585
if (band.noDataValue !== null) {
86-
console.log(' NoData Value='+band.noDataValue);
86+
console.log(' NoData Value=' + band.noDataValue);
8787
}
8888

8989
// band overviews
9090
var overview_info = [];
9191
band.overviews.forEach(function(overview) {
92-
var overview_description = overview.size.x + "x" + overview.size.y;
92+
var overview_description = overview.size.x + 'x' + overview.size.y;
9393

9494
var metadata = overview.getMetadata();
95-
if (metadata['RESAMPLING'] == 'AVERAGE_BIT2') {
95+
if (metadata['RESAMPLING'] === 'AVERAGE_BIT2') {
9696
overview_description += '*';
9797
}
9898

@@ -128,7 +128,7 @@ ds.bands.forEach(function(band){
128128
if (keys.length > 0) {
129129
console.log(' Metadata:');
130130
keys.forEach(function(key) {
131-
console.log(' '+key+'='+metadata[key]);
131+
console.log(' ' + key + '=' + metadata[key]);
132132
});
133133
}
134134

examples/ogrinfo.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ console.log('');
2222
// layers
2323
var i = 0;
2424
console.log('Layers: ');
25-
ds.layers.forEach(function(layer){
26-
console.log((i++)+': '+ layer.name);
25+
ds.layers.forEach(function(layer) {
26+
console.log((i++) + ': ' + layer.name);
2727

28-
console.log(' Geometry Type = '+gdal.Geometry.getName(layer.geomType));
29-
console.log(' Spatial Reference = '+(layer.srs ? layer.srs.toWKT() : 'null'));
28+
console.log(' Geometry Type = ' + gdal.Geometry.getName(layer.geomType));
29+
console.log(' Spatial Reference = ' + (layer.srs ? layer.srs.toWKT() : 'null'));
3030

3131
var extent = layer.getExtent();
3232
console.log(' Extent: ');
33-
console.log(' minX = '+extent.minX);
34-
console.log(' minY = '+extent.minY);
35-
console.log(' maxX = '+extent.maxX);
36-
console.log(' maxY = '+extent.maxY);
37-
38-
console.log(' Fields: ')
39-
layer.fields.forEach(function(field){
40-
console.log(' -'+field.name+' ('+field.type+')');
33+
console.log(' minX = ' + extent.minX);
34+
console.log(' minY = ' + extent.minY);
35+
console.log(' maxX = ' + extent.maxX);
36+
console.log(' maxY = ' + extent.maxY);
37+
38+
console.log(' Fields: ');
39+
layer.fields.forEach(function(field) {
40+
console.log(' -' + field.name + ' (' + field.type + ')');
4141
});
4242

43-
console.log(' Feature Count = '+layer.features.count());
43+
console.log(' Feature Count = ' + layer.features.count());
4444
});

lib/envelope.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
module.exports = function(gdal) {
2-
32
/**
43
* A 2D bounding box. For 3D envelopes, see {{#crossLink "gdal.Envelope3D"}}gdal.Envelope3D{{/crossLink}}.
54
*
@@ -41,7 +40,7 @@ module.exports = function(gdal) {
4140
* @return {void}
4241
*/
4342
Envelope.prototype.merge = function(envelope) {
44-
if (arguments.length == 1) {
43+
if (arguments.length === 1) {
4544
if (this.isEmpty()) {
4645
this.minX = envelope.minX;
4746
this.maxX = envelope.maxX;
@@ -136,5 +135,4 @@ module.exports = function(gdal) {
136135
};
137136

138137
return Envelope;
139-
140-
};
138+
};

lib/envelope_3d.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
module.exports = function(gdal) {
2-
1+
module.exports = function() {
32
/**
43
* A 3D bounding box. For 2D envelopes, see {{#crossLink "gdal.Envelope"}}gdal.Envelope{{/crossLink}}.
54
*
@@ -45,7 +44,7 @@ module.exports = function(gdal) {
4544
* @return {void}
4645
*/
4746
Envelope3D.prototype.merge = function(envelope) {
48-
if (arguments.length == 1) {
47+
if (arguments.length === 1) {
4948
if (this.isEmpty()) {
5049
this.minX = envelope.minX;
5150
this.maxX = envelope.maxX;
@@ -135,5 +134,4 @@ module.exports = function(gdal) {
135134
};
136135

137136
return Envelope3D;
138-
139-
};
137+
};

lib/gdal.js

+39-37
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint no-console: 0 */
12
var path = require('path');
23
var fs = require('fs');
34
var pkg = require('../package.json');
@@ -98,7 +99,7 @@ function defaultMap(callback) {
9899

99100
function defaultToArray() {
100101
var array = [];
101-
this.forEach(function(geom){
102+
this.forEach(function(geom) {
102103
array.push(geom);
103104
});
104105
return array;
@@ -521,61 +522,62 @@ gdal.open = (function() {
521522
var open = gdal.open;
522523

523524
// add 'w' mode to gdal.open() method and also GDAL2-style driver selection
524-
return function(filename, mode, drivers, x_size, y_size, n_bands, datatype, options) {
525+
return function(filename, mode, drivers/* , x_size, y_size, n_bands, datatype, options */) {
525526
if (typeof drivers === 'string') {
526527
drivers = [drivers];
527528
} else if (drivers && !Array.isArray(drivers)) {
528-
throw new Error('driver(s) must be a string or list of strings')
529+
throw new Error('driver(s) must be a string or list of strings');
529530
}
530531

531532
if (mode === 'w') {
532533
// create file with given driver
533534
if (!drivers) {
534-
throw new Error("Driver must be specified");
535+
throw new Error('Driver must be specified');
535536
}
536537
if (drivers.length !== 1) {
537-
throw new Error("Only one driver can be used to create a file");
538+
throw new Error('Only one driver can be used to create a file');
538539
}
539540
var driver = gdal.drivers.get(drivers[0]);
540541
if (!driver) {
541-
throw new Error("Cannot find driver: "+drivers[0]);
542+
throw new Error('Cannot find driver: ' + drivers[0]);
542543
}
543544

544545
var args = Array.prototype.slice.call(arguments, 3); // x_size, y_size, ...
545546
args.unshift(filename);
546-
return driver.create.apply(driver, args);
547-
} else {
548-
if (arguments.length > 2) {
549-
// open file with driver list
550-
// loop through given drivers trying to open file
551-
var ds;
552-
drivers.forEach(function(driver_name, i){
553-
var driver = gdal.drivers.get(driver_name);
554-
if (!driver) {
555-
throw new Error("Cannot find driver: "+driver_name);
556-
}
557-
try {
558-
ds = driver.open(filename, mode);
559-
return false;
560-
} catch (err) { }
561-
});
562-
563-
if (!ds) throw new Error("Error opening dataset");
564-
return ds;
565-
566-
} else {
567-
// call gdal.open() method normally
568-
return open.apply(gdal, arguments);
569-
}
547+
return driver.create.apply(driver, args);
570548
}
571-
}
549+
550+
if (arguments.length > 2) {
551+
// open file with driver list
552+
// loop through given drivers trying to open file
553+
var ds;
554+
drivers.forEach(function(driver_name) {
555+
var driver = gdal.drivers.get(driver_name);
556+
if (!driver) {
557+
throw new Error('Cannot find driver: ' + driver_name);
558+
}
559+
try {
560+
ds = driver.open(filename, mode);
561+
return false;
562+
} catch (err) {
563+
/* skip driver */
564+
}
565+
});
566+
567+
if (!ds) throw new Error('Error opening dataset');
568+
return ds;
569+
}
570+
571+
// call gdal.open() method normally
572+
return open.apply(gdal, arguments);
573+
};
572574
})();
573575

574576
function fieldTypeFromValue(val) {
575577
var type = typeof val;
576578
if (type === 'number') {
577579
if (val % 1 === 0) return gdal.OFTInteger;
578-
else return gdal.OFTReal;
580+
return gdal.OFTReal;
579581
} else if (type === 'string') {
580582
return gdal.OFTString;
581583
} else if (type === 'boolean') {
@@ -588,13 +590,13 @@ function fieldTypeFromValue(val) {
588590
case gdal.OFTString : return gdal.OFTStringList;
589591
case gdal.OFTInteger : return gdal.OFTIntegerList;
590592
case gdal.OFTReal : return gdal.OFTRealList;
591-
default : throw new Error("Array element cannot be converted into OGRFieldType");
593+
default : throw new Error('Array element cannot be converted into OGRFieldType');
592594
}
593595
} else if (val instanceof Buffer) {
594596
return gdal.OFTBinary;
595-
} else {
596-
throw new Error("Value cannot be converted into OGRFieldType");
597597
}
598+
599+
throw new Error('Value cannot be converted into OGRFieldType');
598600
}
599601

600602
/**
@@ -640,7 +642,7 @@ gdal.GeometryCollection.wkbType = gdal.wkbGeometryCollection;
640642
// enable passing geometry constructors as the geometry type
641643
gdal.DatasetLayers.prototype.create = (function() {
642644
var create = gdal.DatasetLayers.prototype.create;
643-
return function(name, srs, geom_type, creation_options) {
645+
return function(name, srs, geom_type/* , creation_options */) {
644646
if (arguments.length > 2 && geom_type instanceof Function) {
645647
if (typeof geom_type.wkbType === 'undefined') {
646648
throw new Error('Function must be a geometry constructor');
@@ -661,7 +663,7 @@ function getTypedArrayType(array) {
661663
if (array instanceof Float32Array) return 6; // gdal.GDT_Float32
662664
if (array instanceof Float64Array) return 7; // gdal.GDT_Float64
663665
return 0; // gdal.GDT_Unknown
664-
};
666+
}
665667

666668
gdal.RasterBandPixels.prototype.read = (function() {
667669
var read = gdal.RasterBandPixels.prototype.read;

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
},
3838
"scripts": {
3939
"test": "mocha test -R tap --timeout 600000 --no-colors -gc --require ./test/_common.js",
40+
"test-syntax": "eslint lib test --fix",
4041
"install": "node-pre-gyp install --fallback-to-build",
4142
"postpublish": "npm run publish-yuidoc",
4243
"yuidoc": "yuidoc --extension .js,.cpp,.hpp",
@@ -49,6 +50,8 @@
4950
"devDependencies": {
5051
"aws-sdk": "~2.0.25",
5152
"chai": "^3.4.1",
53+
"eslint": "^1.10.1",
54+
"eslint-config-naturalatlas": "latest",
5255
"gh-pages": "~0.2.0",
5356
"mocha": "^2.3.4",
5457
"yuidoc-lucid-theme": "~0.1.1",

scripts/publish-docs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ ghpages.publish(path.resolve(__dirname, '../yuidocs'), {message: 'Updated docume
1111
process.stdout.write('success\n');
1212
process.exit(0);
1313
}
14-
});
14+
});

test/.eslintrc

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"globals": {
3+
"gc": true,
4+
"it": true,
5+
"describe": true,
6+
"before": true,
7+
"after": true,
8+
"beforeEach": true,
9+
"afterEach": true
10+
},
11+
"rules": {
12+
"no-console": 0,
13+
"no-new": 0
14+
}
15+
}

test/_common.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ var gdal = require('../lib/gdal.js');
33
// gc tracing
44
try {
55
gdal.startLogging(__dirname + '/artifacts/log.txt');
6-
} catch (e) {}
6+
} catch (e) {
7+
/* ignore */
8+
}
79

810
// seg fault handler
911
var SegfaultHandler;
1012
try {
1113
SegfaultHandler = require('segfault-handler');
1214
SegfaultHandler.registerHandler();
13-
} catch (err) {}
15+
} catch (err) {
16+
/* ignore */
17+
}

0 commit comments

Comments
 (0)