Make code prettier

This updates ESLint and our shared eslint-config-openlayers to use Prettier.  Most formatting changes were automatically applied with this:

    npm run lint -- --fix

A few manual changes were required:

 * In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
 * In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason.  While editing this, I reworked `ExampleBuilder` to be a class.
 * In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
Tim Schaub
2020-04-06 12:25:12 -06:00
parent 53b48baf62
commit 054af09032
790 changed files with 46833 additions and 33765 deletions
+73 -60
View File
@@ -2,20 +2,20 @@
* @module ol/format/GeoJSON
*/
import {assert} from '../asserts.js';
import Feature from '../Feature.js';
import {transformGeometryWithOptions} from './Feature.js';
import JSONFeature from './JSONFeature.js';
import GeometryCollection from '../geom/GeometryCollection.js';
import GeometryType from '../geom/GeometryType.js';
import JSONFeature from './JSONFeature.js';
import LineString from '../geom/LineString.js';
import MultiLineString from '../geom/MultiLineString.js';
import MultiPoint from '../geom/MultiPoint.js';
import MultiPolygon from '../geom/MultiPolygon.js';
import Point from '../geom/Point.js';
import Polygon from '../geom/Polygon.js';
import {assert} from '../asserts.js';
import {assign, isEmpty} from '../obj.js';
import {get as getProjection} from '../proj.js';
import GeometryType from '../geom/GeometryType.js';
import {transformGeometryWithOptions} from './Feature.js';
/**
* @typedef {import("geojson").GeoJSON} GeoJSONObject
@@ -31,7 +31,6 @@ import GeometryType from '../geom/GeometryType.js';
* @typedef {import("geojson").GeometryCollection} GeoJSONGeometryCollection
*/
/**
* @typedef {Object} Options
* @property {import("../proj.js").ProjectionLike} [dataProjection='EPSG:4326'] Default data projection.
@@ -44,20 +43,17 @@ import GeometryType from '../geom/GeometryType.js';
* and a `geometryName` is provided, the `geometryName` will take precedence.
*/
/**
* @classdesc
* Feature format for reading and writing data in the GeoJSON format.
*
* @api
* @api
*/
class GeoJSON extends JSONFeature {
/**
* @param {Options=} opt_options Options.
*/
constructor(opt_options) {
const options = opt_options ? opt_options : {};
super();
@@ -66,8 +62,8 @@ class GeoJSON extends JSONFeature {
* @type {import("../proj/Projection.js").default}
*/
this.dataProjection = getProjection(
options.dataProjection ?
options.dataProjection : 'EPSG:4326');
options.dataProjection ? options.dataProjection : 'EPSG:4326'
);
if (options.featureProjection) {
this.defaultFeatureProjection = getProjection(options.featureProjection);
@@ -86,7 +82,6 @@ class GeoJSON extends JSONFeature {
* @private
*/
this.extractGeometryName_ = options.extractGeometryName;
}
/**
@@ -106,7 +101,7 @@ class GeoJSON extends JSONFeature {
geoJSONFeature = {
'type': 'Feature',
'geometry': /** @type {GeoJSONGeometry} */ (object),
'properties': null
'properties': null,
};
}
@@ -114,7 +109,10 @@ class GeoJSON extends JSONFeature {
const feature = new Feature();
if (this.geometryName_) {
feature.setGeometryName(this.geometryName_);
} else if (this.extractGeometryName_ && 'geometry_name' in geoJSONFeature !== undefined) {
} else if (
this.extractGeometryName_ &&
'geometry_name' in geoJSONFeature !== undefined
) {
feature.setGeometryName(geoJSONFeature['geometry_name']);
}
feature.setGeometry(geometry);
@@ -144,7 +142,9 @@ class GeoJSON extends JSONFeature {
features = [];
const geoJSONFeatures = geoJSONFeatureCollection['features'];
for (let i = 0, ii = geoJSONFeatures.length; i < ii; ++i) {
features.push(this.readFeatureFromObject(geoJSONFeatures[i], opt_options));
features.push(
this.readFeatureFromObject(geoJSONFeatures[i], opt_options)
);
}
} else {
features = [this.readFeatureFromObject(object, opt_options)];
@@ -181,9 +181,7 @@ class GeoJSON extends JSONFeature {
} else {
projection = this.dataProjection;
}
return (
/** @type {import("../proj/Projection.js").default} */ (projection)
);
return /** @type {import("../proj/Projection.js").default} */ (projection);
}
/**
@@ -201,7 +199,7 @@ class GeoJSON extends JSONFeature {
const object = {
'type': 'Feature',
geometry: null,
properties: null
properties: null,
};
const id = feature.getId();
@@ -238,7 +236,7 @@ class GeoJSON extends JSONFeature {
}
return {
type: 'FeatureCollection',
features: objects
features: objects,
};
}
@@ -255,7 +253,6 @@ class GeoJSON extends JSONFeature {
}
}
/**
* @param {GeoJSONGeometry|GeoJSONGeometryCollection} object Object.
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
@@ -276,7 +273,9 @@ function readGeometry(object, opt_options) {
break;
}
case GeometryType.LINE_STRING: {
geometry = readLineStringGeometry(/** @type {GeoJSONLineString} */ (object));
geometry = readLineStringGeometry(
/** @type {GeoJSONLineString} */ (object)
);
break;
}
case GeometryType.POLYGON: {
@@ -284,19 +283,27 @@ function readGeometry(object, opt_options) {
break;
}
case GeometryType.MULTI_POINT: {
geometry = readMultiPointGeometry(/** @type {GeoJSONMultiPoint} */ (object));
geometry = readMultiPointGeometry(
/** @type {GeoJSONMultiPoint} */ (object)
);
break;
}
case GeometryType.MULTI_LINE_STRING: {
geometry = readMultiLineStringGeometry(/** @type {GeoJSONMultiLineString} */ (object));
geometry = readMultiLineStringGeometry(
/** @type {GeoJSONMultiLineString} */ (object)
);
break;
}
case GeometryType.MULTI_POLYGON: {
geometry = readMultiPolygonGeometry(/** @type {GeoJSONMultiPolygon} */ (object));
geometry = readMultiPolygonGeometry(
/** @type {GeoJSONMultiPolygon} */ (object)
);
break;
}
case GeometryType.GEOMETRY_COLLECTION: {
geometry = readGeometryCollectionGeometry(/** @type {GeoJSONGeometryCollection} */ (object));
geometry = readGeometryCollectionGeometry(
/** @type {GeoJSONGeometryCollection} */ (object)
);
break;
}
default: {
@@ -306,7 +313,6 @@ function readGeometry(object, opt_options) {
return transformGeometryWithOptions(geometry, false, opt_options);
}
/**
* @param {GeoJSONGeometryCollection} object Object.
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
@@ -318,13 +324,13 @@ function readGeometryCollectionGeometry(object, opt_options) {
* @param {GeoJSONGeometry} geometry Geometry.
* @return {import("../geom/Geometry.js").default} geometry Geometry.
*/
function(geometry) {
function (geometry) {
return readGeometry(geometry, opt_options);
});
}
);
return new GeometryCollection(geometries);
}
/**
* @param {GeoJSONPoint} object Object.
* @return {Point} Point.
@@ -333,7 +339,6 @@ function readPointGeometry(object) {
return new Point(object['coordinates']);
}
/**
* @param {GeoJSONLineString} object Object.
* @return {LineString} LineString.
@@ -342,7 +347,6 @@ function readLineStringGeometry(object) {
return new LineString(object['coordinates']);
}
/**
* @param {GeoJSONMultiLineString} object Object.
* @return {MultiLineString} MultiLineString.
@@ -351,7 +355,6 @@ function readMultiLineStringGeometry(object) {
return new MultiLineString(object['coordinates']);
}
/**
* @param {GeoJSONMultiPoint} object Object.
* @return {MultiPoint} MultiPoint.
@@ -360,7 +363,6 @@ function readMultiPointGeometry(object) {
return new MultiPoint(object['coordinates']);
}
/**
* @param {GeoJSONMultiPolygon} object Object.
* @return {MultiPolygon} MultiPolygon.
@@ -369,7 +371,6 @@ function readMultiPolygonGeometry(object) {
return new MultiPolygon(object['coordinates']);
}
/**
* @param {GeoJSONPolygon} object Object.
* @return {Polygon} Polygon.
@@ -378,7 +379,6 @@ function readPolygonGeometry(object) {
return new Polygon(object['coordinates']);
}
/**
* @param {import("../geom/Geometry.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
@@ -392,37 +392,58 @@ function writeGeometry(geometry, opt_options) {
let geoJSON;
switch (type) {
case GeometryType.POINT: {
geoJSON = writePointGeometry(/** @type {Point} */ (geometry), opt_options);
geoJSON = writePointGeometry(
/** @type {Point} */ (geometry),
opt_options
);
break;
}
case GeometryType.LINE_STRING: {
geoJSON = writeLineStringGeometry(/** @type {LineString} */ (geometry), opt_options);
geoJSON = writeLineStringGeometry(
/** @type {LineString} */ (geometry),
opt_options
);
break;
}
case GeometryType.POLYGON: {
geoJSON = writePolygonGeometry(/** @type {Polygon} */ (geometry), opt_options);
geoJSON = writePolygonGeometry(
/** @type {Polygon} */ (geometry),
opt_options
);
break;
}
case GeometryType.MULTI_POINT: {
geoJSON = writeMultiPointGeometry(/** @type {MultiPoint} */ (geometry), opt_options);
geoJSON = writeMultiPointGeometry(
/** @type {MultiPoint} */ (geometry),
opt_options
);
break;
}
case GeometryType.MULTI_LINE_STRING: {
geoJSON = writeMultiLineStringGeometry(/** @type {MultiLineString} */ (geometry), opt_options);
geoJSON = writeMultiLineStringGeometry(
/** @type {MultiLineString} */ (geometry),
opt_options
);
break;
}
case GeometryType.MULTI_POLYGON: {
geoJSON = writeMultiPolygonGeometry(/** @type {MultiPolygon} */ (geometry), opt_options);
geoJSON = writeMultiPolygonGeometry(
/** @type {MultiPolygon} */ (geometry),
opt_options
);
break;
}
case GeometryType.GEOMETRY_COLLECTION: {
geoJSON = writeGeometryCollectionGeometry(/** @type {GeometryCollection} */ (geometry), opt_options);
geoJSON = writeGeometryCollectionGeometry(
/** @type {GeometryCollection} */ (geometry),
opt_options
);
break;
}
case GeometryType.CIRCLE: {
geoJSON = {
type: 'GeometryCollection',
geometries: []
geometries: [],
};
break;
}
@@ -433,25 +454,23 @@ function writeGeometry(geometry, opt_options) {
return geoJSON;
}
/**
* @param {GeometryCollection} geometry Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
* @return {GeoJSONGeometryCollection} GeoJSON geometry collection.
*/
function writeGeometryCollectionGeometry(geometry, opt_options) {
const geometries = geometry.getGeometriesArray().map(function(geometry) {
const geometries = geometry.getGeometriesArray().map(function (geometry) {
const options = assign({}, opt_options);
delete options.featureProjection;
return writeGeometry(geometry, options);
});
return {
type: 'GeometryCollection',
geometries: geometries
geometries: geometries,
};
}
/**
* @param {LineString} geometry Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
@@ -460,11 +479,10 @@ function writeGeometryCollectionGeometry(geometry, opt_options) {
function writeLineStringGeometry(geometry, opt_options) {
return {
type: 'LineString',
coordinates: geometry.getCoordinates()
coordinates: geometry.getCoordinates(),
};
}
/**
* @param {MultiLineString} geometry Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
@@ -473,11 +491,10 @@ function writeLineStringGeometry(geometry, opt_options) {
function writeMultiLineStringGeometry(geometry, opt_options) {
return {
type: 'MultiLineString',
coordinates: geometry.getCoordinates()
coordinates: geometry.getCoordinates(),
};
}
/**
* @param {MultiPoint} geometry Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
@@ -486,11 +503,10 @@ function writeMultiLineStringGeometry(geometry, opt_options) {
function writeMultiPointGeometry(geometry, opt_options) {
return {
type: 'MultiPoint',
coordinates: geometry.getCoordinates()
coordinates: geometry.getCoordinates(),
};
}
/**
* @param {MultiPolygon} geometry Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
@@ -503,11 +519,10 @@ function writeMultiPolygonGeometry(geometry, opt_options) {
}
return {
type: 'MultiPolygon',
coordinates: geometry.getCoordinates(right)
coordinates: geometry.getCoordinates(right),
};
}
/**
* @param {Point} geometry Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
@@ -516,11 +531,10 @@ function writeMultiPolygonGeometry(geometry, opt_options) {
function writePointGeometry(geometry, opt_options) {
return {
type: 'Point',
coordinates: geometry.getCoordinates()
coordinates: geometry.getCoordinates(),
};
}
/**
* @param {Polygon} geometry Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
@@ -533,9 +547,8 @@ function writePolygonGeometry(geometry, opt_options) {
}
return {
type: 'Polygon',
coordinates: geometry.getCoordinates(right)
coordinates: geometry.getCoordinates(right),
};
}
export default GeoJSON;