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
+45 -34
View File
@@ -1,19 +1,18 @@
/**
* @module ol/layer/Group
*/
import {getUid} from '../util.js';
import BaseLayer from './Base.js';
import Collection from '../Collection.js';
import CollectionEventType from '../CollectionEventType.js';
import {getChangeEventType} from '../Object.js';
import ObjectEventType from '../ObjectEventType.js';
import {assert} from '../asserts.js';
import {listen, unlistenByKey} from '../events.js';
import EventType from '../events/EventType.js';
import {getIntersection} from '../extent.js';
import BaseLayer from './Base.js';
import {assign, clear} from '../obj.js';
import ObjectEventType from '../ObjectEventType.js';
import SourceState from '../source/State.js';
import {assert} from '../asserts.js';
import {assign, clear} from '../obj.js';
import {getChangeEventType} from '../Object.js';
import {getIntersection} from '../extent.js';
import {getUid} from '../util.js';
import {listen, unlistenByKey} from '../events.js';
/**
* @typedef {Object} Options
@@ -40,16 +39,14 @@ import SourceState from '../source/State.js';
* @property {Array<import("./Base.js").default>|import("../Collection.js").default<import("./Base.js").default>} [layers] Child layers.
*/
/**
* @enum {string}
* @private
*/
const Property = {
LAYERS: 'layers'
LAYERS: 'layers',
};
/**
* @classdesc
* A {@link module:ol/Collection~Collection} of layers that are handled together.
@@ -63,7 +60,6 @@ class LayerGroup extends BaseLayer {
* @param {Options=} opt_options Layer options.
*/
constructor(opt_options) {
const options = opt_options || {};
const baseOptions = /** @type {Options} */ (assign({}, options));
delete baseOptions.layers;
@@ -84,21 +80,22 @@ class LayerGroup extends BaseLayer {
*/
this.listenerKeys_ = {};
this.addEventListener(getChangeEventType(Property.LAYERS), this.handleLayersChanged_);
this.addEventListener(
getChangeEventType(Property.LAYERS),
this.handleLayersChanged_
);
if (layers) {
if (Array.isArray(layers)) {
layers = new Collection(layers.slice(), {unique: true});
} else {
assert(typeof /** @type {?} */ (layers).getArray === 'function',
43); // Expected `layers` to be an array or a `Collection`
assert(typeof (/** @type {?} */ (layers).getArray) === 'function', 43); // Expected `layers` to be an array or a `Collection`
}
} else {
layers = new Collection(undefined, {unique: true});
}
this.setLayers(layers);
}
/**
@@ -130,8 +127,13 @@ class LayerGroup extends BaseLayer {
for (let i = 0, ii = layersArray.length; i < ii; i++) {
const layer = layersArray[i];
this.listenerKeys_[getUid(layer)] = [
listen(layer, ObjectEventType.PROPERTYCHANGE, this.handleLayerChange_, this),
listen(layer, EventType.CHANGE, this.handleLayerChange_, this)
listen(
layer,
ObjectEventType.PROPERTYCHANGE,
this.handleLayerChange_,
this
),
listen(layer, EventType.CHANGE, this.handleLayerChange_, this),
];
}
@@ -145,8 +147,13 @@ class LayerGroup extends BaseLayer {
handleLayersAdd_(collectionEvent) {
const layer = /** @type {import("./Base.js").default} */ (collectionEvent.element);
this.listenerKeys_[getUid(layer)] = [
listen(layer, ObjectEventType.PROPERTYCHANGE, this.handleLayerChange_, this),
listen(layer, EventType.CHANGE, this.handleLayerChange_, this)
listen(
layer,
ObjectEventType.PROPERTYCHANGE,
this.handleLayerChange_,
this
),
listen(layer, EventType.CHANGE, this.handleLayerChange_, this),
];
this.changed();
}
@@ -172,9 +179,9 @@ class LayerGroup extends BaseLayer {
* @api
*/
getLayers() {
return (
/** @type {!import("../Collection.js").default<import("./Base.js").default>} */ (this.get(Property.LAYERS))
);
return /** @type {!import("../Collection.js").default<import("./Base.js").default>} */ (this.get(
Property.LAYERS
));
}
/**
@@ -195,7 +202,7 @@ class LayerGroup extends BaseLayer {
*/
getLayersArray(opt_array) {
const array = opt_array !== undefined ? opt_array : [];
this.getLayers().forEach(function(layer) {
this.getLayers().forEach(function (layer) {
layer.getLayersArray(array);
});
return array;
@@ -210,7 +217,7 @@ class LayerGroup extends BaseLayer {
const pos = states.length;
this.getLayers().forEach(function(layer) {
this.getLayers().forEach(function (layer) {
layer.getLayerStatesArray(states);
});
@@ -220,16 +227,21 @@ class LayerGroup extends BaseLayer {
layerState.opacity *= ownLayerState.opacity;
layerState.visible = layerState.visible && ownLayerState.visible;
layerState.maxResolution = Math.min(
layerState.maxResolution, ownLayerState.maxResolution);
layerState.maxResolution,
ownLayerState.maxResolution
);
layerState.minResolution = Math.max(
layerState.minResolution, ownLayerState.minResolution);
layerState.minZoom = Math.max(
layerState.minZoom, ownLayerState.minZoom);
layerState.maxZoom = Math.min(
layerState.maxZoom, ownLayerState.maxZoom);
layerState.minResolution,
ownLayerState.minResolution
);
layerState.minZoom = Math.max(layerState.minZoom, ownLayerState.minZoom);
layerState.maxZoom = Math.min(layerState.maxZoom, ownLayerState.maxZoom);
if (ownLayerState.extent !== undefined) {
if (layerState.extent !== undefined) {
layerState.extent = getIntersection(layerState.extent, ownLayerState.extent);
layerState.extent = getIntersection(
layerState.extent,
ownLayerState.extent
);
} else {
layerState.extent = ownLayerState.extent;
}
@@ -247,5 +259,4 @@ class LayerGroup extends BaseLayer {
}
}
export default LayerGroup;