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
+146 -77
View File
@@ -4,10 +4,7 @@
// FIXME Envelopes should not be treated as geometries! readEnvelope_ is part
// of GEOMETRY_PARSERS_ and methods using GEOMETRY_PARSERS_ do not expect
// envelopes/extents, only geometries!
import {extend} from '../array.js';
import Feature from '../Feature.js';
import {transformGeometryWithOptions, transformExtentWithOptions} from './Feature.js';
import XMLFeature from './XMLFeature.js';
import GeometryLayout from '../geom/GeometryLayout.js';
import LineString from '../geom/LineString.js';
import LinearRing from '../geom/LinearRing.js';
@@ -16,10 +13,22 @@ 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 XMLFeature from './XMLFeature.js';
import {assign} from '../obj.js';
import {extend} from '../array.js';
import {
getAllTextContent,
getAttributeNS,
makeArrayPusher,
makeReplacer,
parseNode,
pushParseAndPop,
} from '../xml.js';
import {get as getProjection} from '../proj.js';
import {getAllTextContent, getAttributeNS, makeArrayPusher, makeReplacer, parseNode, pushParseAndPop} from '../xml.js';
import {
transformExtentWithOptions,
transformGeometryWithOptions,
} from './Feature.js';
/**
* @const
@@ -27,7 +36,6 @@ import {getAllTextContent, getAttributeNS, makeArrayPusher, makeReplacer, parseN
*/
export const GMLNS = 'http://www.opengis.net/gml';
/**
* A regular expression that matches if a string only contains whitespace
* characters. It will e.g. match `''`, `' '`, `'\n'` etc. The non-breaking
@@ -41,7 +49,6 @@ export const GMLNS = 'http://www.opengis.net/gml';
*/
const ONLY_WHITESPACE_RE = /^[\s\xa0]*$/;
/**
* @typedef {Object} Options
* @property {Object<string, string>|string} [featureNS] Feature
@@ -74,7 +81,6 @@ const ONLY_WHITESPACE_RE = /^[\s\xa0]*$/;
* @property {boolean} [hasZ=false] If coordinates have a Z value.
*/
/**
* @classdesc
* Abstract base class; normally only used for creating subclasses and not
@@ -86,7 +92,6 @@ const ONLY_WHITESPACE_RE = /^[\s\xa0]*$/;
* @abstract
*/
class GMLBase extends XMLFeature {
/**
* @param {Options=} opt_options Optional configuration object.
*/
@@ -125,7 +130,7 @@ class GMLBase extends XMLFeature {
this.FEATURE_COLLECTION_PARSERS = {};
this.FEATURE_COLLECTION_PARSERS[this.namespace] = {
'featureMember': makeArrayPusher(this.readFeaturesInternal),
'featureMembers': makeReplacer(this.readFeaturesInternal)
'featureMembers': makeReplacer(this.readFeaturesInternal),
};
}
@@ -138,9 +143,13 @@ class GMLBase extends XMLFeature {
const localName = node.localName;
let features = null;
if (localName == 'FeatureCollection') {
features = pushParseAndPop([],
this.FEATURE_COLLECTION_PARSERS, node,
objectStack, this);
features = pushParseAndPop(
[],
this.FEATURE_COLLECTION_PARSERS,
node,
objectStack,
this
);
} else if (localName == 'featureMembers' || localName == 'featureMember') {
const context = objectStack[0];
let featureType = context['featureType'];
@@ -148,7 +157,7 @@ class GMLBase extends XMLFeature {
const prefix = 'p';
const defaultPrefix = 'p0';
if (!featureType && node.childNodes) {
featureType = [], featureNS = {};
(featureType = []), (featureNS = {});
for (let i = 0, ii = node.childNodes.length; i < ii; ++i) {
const child = node.childNodes[i];
if (child.nodeType === 1) {
@@ -185,18 +194,22 @@ class GMLBase extends XMLFeature {
}
/** @type {Object<string, Object<string, import("../xml.js").Parser>>} */
const parsersNS = {};
const featureTypes = Array.isArray(featureType) ? featureType : [featureType];
const featureTypes = Array.isArray(featureType)
? featureType
: [featureType];
for (const p in featureNS) {
/** @type {Object<string, import("../xml.js").Parser>} */
const parsers = {};
for (let i = 0, ii = featureTypes.length; i < ii; ++i) {
const featurePrefix = featureTypes[i].indexOf(':') === -1 ?
defaultPrefix : featureTypes[i].split(':')[0];
const featurePrefix =
featureTypes[i].indexOf(':') === -1
? defaultPrefix
: featureTypes[i].split(':')[0];
if (featurePrefix === p) {
parsers[featureTypes[i].split(':').pop()] =
(localName == 'featureMembers') ?
makeArrayPusher(this.readFeatureElement, this) :
makeReplacer(this.readFeatureElement, this);
localName == 'featureMembers'
? makeArrayPusher(this.readFeatureElement, this)
: makeReplacer(this.readFeatureElement, this);
}
}
parsersNS[featureNS[p]] = parsers;
@@ -221,13 +234,28 @@ class GMLBase extends XMLFeature {
readGeometryElement(node, objectStack) {
const context = /** @type {Object} */ (objectStack[0]);
context['srsName'] = node.firstElementChild.getAttribute('srsName');
context['srsDimension'] = node.firstElementChild.getAttribute('srsDimension');
const geometry = pushParseAndPop(null, this.GEOMETRY_PARSERS, node, objectStack, this);
context['srsDimension'] = node.firstElementChild.getAttribute(
'srsDimension'
);
const geometry = pushParseAndPop(
null,
this.GEOMETRY_PARSERS,
node,
objectStack,
this
);
if (geometry) {
if (Array.isArray(geometry)) {
return transformExtentWithOptions(/** @type {import("../extent.js").Extent} */ (geometry), context);
return transformExtentWithOptions(
/** @type {import("../extent.js").Extent} */ (geometry),
context
);
} else {
return transformGeometryWithOptions(/** @type {import("../geom/Geometry.js").default} */ (geometry), false, context);
return transformGeometryWithOptions(
/** @type {import("../geom/Geometry.js").default} */ (geometry),
false,
context
);
}
} else {
return undefined;
@@ -247,8 +275,11 @@ class GMLBase extends XMLFeature {
let value;
const localName = n.localName;
// first, check if it is simple attribute
if (n.childNodes.length === 0
|| (n.childNodes.length === 1 && (n.firstChild.nodeType === 3 || n.firstChild.nodeType === 4))) {
if (
n.childNodes.length === 0 ||
(n.childNodes.length === 1 &&
(n.firstChild.nodeType === 3 || n.firstChild.nodeType === 4))
) {
value = getAllTextContent(n, false);
if (ONLY_WHITESPACE_RE.test(value)) {
value = undefined;
@@ -258,7 +289,8 @@ class GMLBase extends XMLFeature {
//if feature, try it as a geometry
value = this.readGeometryElement(n, objectStack);
}
if (!value) { //if not a geometry or not a feature, treat it as a complex attribute
if (!value) {
//if not a geometry or not a feature, treat it as a complex attribute
value = this.readFeatureElementInternal(n, objectStack, false);
} else if (localName !== 'boundedBy') {
// boundedBy is an extent and must not be considered as a geometry
@@ -291,8 +323,8 @@ class GMLBase extends XMLFeature {
if (geometryName) {
feature.setGeometryName(geometryName);
}
const fid = node.getAttribute('fid') ||
getAttributeNS(node, this.namespace, 'id');
const fid =
node.getAttribute('fid') || getAttributeNS(node, this.namespace, 'id');
if (fid) {
feature.setId(fid);
}
@@ -300,7 +332,6 @@ class GMLBase extends XMLFeature {
}
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -316,7 +347,10 @@ class GMLBase extends XMLFeature {
* @return {Point|undefined} Point.
*/
readPoint(node, objectStack) {
const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack);
const flatCoordinates = this.readFlatCoordinatesFromNode_(
node,
objectStack
);
if (flatCoordinates) {
return new Point(flatCoordinates, GeometryLayout.XYZ);
}
@@ -329,8 +363,13 @@ class GMLBase extends XMLFeature {
*/
readMultiPoint(node, objectStack) {
/** @type {Array<Array<number>>} */
const coordinates = pushParseAndPop([],
this.MULTIPOINT_PARSERS_, node, objectStack, this);
const coordinates = pushParseAndPop(
[],
this.MULTIPOINT_PARSERS_,
node,
objectStack,
this
);
if (coordinates) {
return new MultiPoint(coordinates);
} else {
@@ -345,8 +384,13 @@ class GMLBase extends XMLFeature {
*/
readMultiLineString(node, objectStack) {
/** @type {Array<LineString>} */
const lineStrings = pushParseAndPop([],
this.MULTILINESTRING_PARSERS_, node, objectStack, this);
const lineStrings = pushParseAndPop(
[],
this.MULTILINESTRING_PARSERS_,
node,
objectStack,
this
);
if (lineStrings) {
return new MultiLineString(lineStrings);
}
@@ -359,7 +403,13 @@ class GMLBase extends XMLFeature {
*/
readMultiPolygon(node, objectStack) {
/** @type {Array<Polygon>} */
const polygons = pushParseAndPop([], this.MULTIPOLYGON_PARSERS_, node, objectStack, this);
const polygons = pushParseAndPop(
[],
this.MULTIPOLYGON_PARSERS_,
node,
objectStack,
this
);
if (polygons) {
return new MultiPolygon(polygons);
}
@@ -398,7 +448,10 @@ class GMLBase extends XMLFeature {
* @return {LineString|undefined} LineString.
*/
readLineString(node, objectStack) {
const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack);
const flatCoordinates = this.readFlatCoordinatesFromNode_(
node,
objectStack
);
if (flatCoordinates) {
const lineString = new LineString(flatCoordinates, GeometryLayout.XYZ);
return lineString;
@@ -414,9 +467,13 @@ class GMLBase extends XMLFeature {
* @return {Array<number>|undefined} LinearRing flat coordinates.
*/
readFlatLinearRing_(node, objectStack) {
const ring = pushParseAndPop(null,
this.GEOMETRY_FLAT_COORDINATES_PARSERS, node,
objectStack, this);
const ring = pushParseAndPop(
null,
this.GEOMETRY_FLAT_COORDINATES_PARSERS,
node,
objectStack,
this
);
if (ring) {
return ring;
} else {
@@ -430,7 +487,10 @@ class GMLBase extends XMLFeature {
* @return {LinearRing|undefined} LinearRing.
*/
readLinearRing(node, objectStack) {
const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack);
const flatCoordinates = this.readFlatCoordinatesFromNode_(
node,
objectStack
);
if (flatCoordinates) {
return new LinearRing(flatCoordinates, GeometryLayout.XYZ);
}
@@ -443,8 +503,13 @@ class GMLBase extends XMLFeature {
*/
readPolygon(node, objectStack) {
/** @type {Array<Array<number>>} */
const flatLinearRings = pushParseAndPop([null],
this.FLAT_LINEAR_RINGS_PARSERS, node, objectStack, this);
const flatLinearRings = pushParseAndPop(
[null],
this.FLAT_LINEAR_RINGS_PARSERS,
node,
objectStack,
this
);
if (flatLinearRings && flatLinearRings[0]) {
const flatCoordinates = flatLinearRings[0];
const ends = [flatCoordinates.length];
@@ -466,7 +531,13 @@ class GMLBase extends XMLFeature {
* @return {Array<number>} Flat coordinates.
*/
readFlatCoordinatesFromNode_(node, objectStack) {
return pushParseAndPop(null, this.GEOMETRY_FLAT_COORDINATES_PARSERS, node, objectStack, this);
return pushParseAndPop(
null,
this.GEOMETRY_FLAT_COORDINATES_PARSERS,
node,
objectStack,
this
);
}
/**
@@ -477,8 +548,9 @@ class GMLBase extends XMLFeature {
*/
//@ts-ignore
readGeometryFromNode(node, opt_options) {
const geometry = this.readGeometryElement(node,
[this.getReadOptions(node, opt_options ? opt_options : {})]);
const geometry = this.readGeometryElement(node, [
this.getReadOptions(node, opt_options ? opt_options : {}),
]);
return geometry ? geometry : null;
}
@@ -490,7 +562,7 @@ class GMLBase extends XMLFeature {
readFeaturesFromNode(node, opt_options) {
const options = {
featureType: this.featureType,
featureNS: this.featureNS
featureNS: this.featureNS,
};
if (opt_options) {
assign(options, this.getReadOptions(node, opt_options));
@@ -504,44 +576,43 @@ class GMLBase extends XMLFeature {
* @return {import("../proj/Projection.js").default} Projection.
*/
readProjectionFromNode(node) {
return getProjection(this.srsName ? this.srsName : node.firstElementChild.getAttribute('srsName'));
return getProjection(
this.srsName
? this.srsName
: node.firstElementChild.getAttribute('srsName')
);
}
}
GMLBase.prototype.namespace = GMLNS;
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
* @protected
*/
GMLBase.prototype.FLAT_LINEAR_RINGS_PARSERS = {
'http://www.opengis.net/gml': {}
'http://www.opengis.net/gml': {},
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
* @protected
*/
GMLBase.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS = {
'http://www.opengis.net/gml': {}
'http://www.opengis.net/gml': {},
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
* @protected
*/
GMLBase.prototype.GEOMETRY_PARSERS = {
'http://www.opengis.net/gml': {}
'http://www.opengis.net/gml': {},
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
@@ -550,11 +621,10 @@ GMLBase.prototype.GEOMETRY_PARSERS = {
GMLBase.prototype.MULTIPOINT_PARSERS_ = {
'http://www.opengis.net/gml': {
'pointMember': makeArrayPusher(GMLBase.prototype.pointMemberParser_),
'pointMembers': makeArrayPusher(GMLBase.prototype.pointMemberParser_)
}
'pointMembers': makeArrayPusher(GMLBase.prototype.pointMemberParser_),
},
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
@@ -562,12 +632,15 @@ GMLBase.prototype.MULTIPOINT_PARSERS_ = {
*/
GMLBase.prototype.MULTILINESTRING_PARSERS_ = {
'http://www.opengis.net/gml': {
'lineStringMember': makeArrayPusher(GMLBase.prototype.lineStringMemberParser_),
'lineStringMembers': makeArrayPusher(GMLBase.prototype.lineStringMemberParser_)
}
'lineStringMember': makeArrayPusher(
GMLBase.prototype.lineStringMemberParser_
),
'lineStringMembers': makeArrayPusher(
GMLBase.prototype.lineStringMemberParser_
),
},
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
@@ -576,11 +649,10 @@ GMLBase.prototype.MULTILINESTRING_PARSERS_ = {
GMLBase.prototype.MULTIPOLYGON_PARSERS_ = {
'http://www.opengis.net/gml': {
'polygonMember': makeArrayPusher(GMLBase.prototype.polygonMemberParser_),
'polygonMembers': makeArrayPusher(GMLBase.prototype.polygonMemberParser_)
}
'polygonMembers': makeArrayPusher(GMLBase.prototype.polygonMemberParser_),
},
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
@@ -588,11 +660,10 @@ GMLBase.prototype.MULTIPOLYGON_PARSERS_ = {
*/
GMLBase.prototype.POINTMEMBER_PARSERS_ = {
'http://www.opengis.net/gml': {
'Point': makeArrayPusher(GMLBase.prototype.readFlatCoordinatesFromNode_)
}
'Point': makeArrayPusher(GMLBase.prototype.readFlatCoordinatesFromNode_),
},
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
@@ -600,11 +671,10 @@ GMLBase.prototype.POINTMEMBER_PARSERS_ = {
*/
GMLBase.prototype.LINESTRINGMEMBER_PARSERS_ = {
'http://www.opengis.net/gml': {
'LineString': makeArrayPusher(GMLBase.prototype.readLineString)
}
'LineString': makeArrayPusher(GMLBase.prototype.readLineString),
},
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
@@ -612,11 +682,10 @@ GMLBase.prototype.LINESTRINGMEMBER_PARSERS_ = {
*/
GMLBase.prototype.POLYGONMEMBER_PARSERS_ = {
'http://www.opengis.net/gml': {
'Polygon': makeArrayPusher(GMLBase.prototype.readPolygon)
}
'Polygon': makeArrayPusher(GMLBase.prototype.readPolygon),
},
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
@@ -624,8 +693,8 @@ GMLBase.prototype.POLYGONMEMBER_PARSERS_ = {
*/
GMLBase.prototype.RING_PARSERS = {
'http://www.opengis.net/gml': {
'LinearRing': makeReplacer(GMLBase.prototype.readFlatLinearRing_)
}
'LinearRing': makeReplacer(GMLBase.prototype.readFlatLinearRing_),
},
};
export default GMLBase;