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

View File

@@ -1,30 +1,31 @@
import Circle from '../../../../src/ol/geom/Circle.js';
import Collection from '../../../../src/ol/Collection.js';
import Event from '../../../../src/ol/events/Event.js';
import Feature from '../../../../src/ol/Feature.js';
import LineString from '../../../../src/ol/geom/LineString.js';
import Map from '../../../../src/ol/Map.js';
import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js';
import View from '../../../../src/ol/View.js';
import {doubleClick} from '../../../../src/ol/events/condition.js';
import Circle from '../../../../src/ol/geom/Circle.js';
import LineString from '../../../../src/ol/geom/LineString.js';
import Modify, {ModifyEvent} from '../../../../src/ol/interaction/Modify.js';
import Point from '../../../../src/ol/geom/Point.js';
import Polygon from '../../../../src/ol/geom/Polygon.js';
import Modify, {ModifyEvent} from '../../../../src/ol/interaction/Modify.js';
import Snap from '../../../../src/ol/interaction/Snap.js';
import VectorLayer from '../../../../src/ol/layer/Vector.js';
import VectorSource from '../../../../src/ol/source/Vector.js';
import Event from '../../../../src/ol/events/Event.js';
import View from '../../../../src/ol/View.js';
import {
clearUserProjection,
setUserProjection,
} from '../../../../src/ol/proj.js';
import {doubleClick} from '../../../../src/ol/events/condition.js';
import {getValues} from '../../../../src/ol/obj.js';
import {clearUserProjection, setUserProjection} from '../../../../src/ol/proj.js';
describe('ol.interaction.Modify', function() {
describe('ol.interaction.Modify', function () {
let target, map, source, features;
const width = 360;
const height = 180;
beforeEach(function(done) {
beforeEach(function (done) {
target = document.createElement('div');
const style = target.style;
@@ -38,13 +39,19 @@ describe('ol.interaction.Modify', function() {
features = [
new Feature({
geometry: new Polygon([
[[0, 0], [10, 20], [0, 40], [40, 40], [40, 0]]
])
})
[
[0, 0],
[10, 20],
[0, 40],
[40, 40],
[40, 0],
],
]),
}),
];
source = new VectorSource({
features: features
features: features,
});
const layer = new VectorLayer({source: source});
@@ -55,16 +62,16 @@ describe('ol.interaction.Modify', function() {
view: new View({
projection: 'EPSG:4326',
center: [0, 0],
resolution: 1
})
resolution: 1,
}),
});
map.once('postrender', function() {
map.once('postrender', function () {
done();
});
});
afterEach(function() {
afterEach(function () {
map.dispose();
document.body.removeChild(target);
clearUserProjection();
@@ -92,7 +99,7 @@ describe('ol.interaction.Modify', function() {
pointerEvent.shiftKey = modifiers.shift || false;
pointerEvent.altKey = modifiers.alt || false;
pointerEvent.pointerId = 1;
pointerEvent.preventDefault = function() {};
pointerEvent.preventDefault = function () {};
pointerEvent.button = button;
pointerEvent.isPrimary = true;
const event = new MapBrowserPointerEvent(type, map, pointerEvent);
@@ -108,27 +115,26 @@ describe('ol.interaction.Modify', function() {
*/
function trackEvents(feature, interaction) {
const events = [];
feature.on('change', function(event) {
feature.on('change', function (event) {
events.push('change');
});
interaction.on('modifystart', function(event) {
interaction.on('modifystart', function (event) {
events.push(event);
});
interaction.on('modifyend', function(event) {
interaction.on('modifyend', function (event) {
events.push(event);
});
return events;
}
/**
* Validates the event array to verify proper event sequence. Checks
* that first and last event are correct ModifyEvents and that feature
* modifications event are in between.
* @param {Array<ModifyEvent|string>} events The events.
* @param {Array<ol.Feature>} features The features.
*/
* Validates the event array to verify proper event sequence. Checks
* that first and last event are correct ModifyEvents and that feature
* modifications event are in between.
* @param {Array<ModifyEvent|string>} events The events.
* @param {Array<ol.Feature>} features The features.
*/
function validateEvents(events, features) {
const startevent = events[0];
const endevent = events[events.length - 1];
@@ -152,24 +158,23 @@ describe('ol.interaction.Modify', function() {
expect(endevent.features.getArray()).to.eql(features);
}
describe('constructor', function() {
it('adds features to the RTree', function() {
const feature = new Feature(
new Point([0, 0]));
describe('constructor', function () {
it('adds features to the RTree', function () {
const feature = new Feature(new Point([0, 0]));
const features = new Collection([feature]);
const modify = new Modify({
features: features
features: features,
});
const rbushEntries = modify.rBush_.getAll();
expect(rbushEntries.length).to.be(1);
expect(rbushEntries[0].feature).to.be(feature);
});
it('accepts feature without geometry', function() {
it('accepts feature without geometry', function () {
const feature = new Feature();
const features = new Collection([feature]);
const modify = new Modify({
features: features
features: features,
});
let rbushEntries = modify.rBush_.getAll();
expect(rbushEntries.length).to.be(0);
@@ -180,21 +185,18 @@ describe('ol.interaction.Modify', function() {
expect(rbushEntries[0].feature).to.be(feature);
});
it('accepts a source', function() {
const feature = new Feature(
new Point([0, 0]));
it('accepts a source', function () {
const feature = new Feature(new Point([0, 0]));
const source = new VectorSource({features: [feature]});
const modify = new Modify({source: source});
const rbushEntries = modify.rBush_.getAll();
expect(rbushEntries.length).to.be(1);
expect(rbushEntries[0].feature).to.be(feature);
});
});
describe('vertex deletion', function() {
it('works when clicking on a shared vertex', function() {
describe('vertex deletion', function () {
it('works when clicking on a shared vertex', function () {
features.push(features[0].clone());
const first = features[0];
@@ -203,7 +205,7 @@ describe('ol.interaction.Modify', function() {
const secondRevision = second.getGeometry().getRevision();
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
@@ -227,11 +229,15 @@ describe('ol.interaction.Modify', function() {
validateEvents(events, features);
});
it('deletes first vertex of a LineString', function() {
it('deletes first vertex of a LineString', function () {
const lineFeature = new Feature({
geometry: new LineString(
[[0, 0], [10, 20], [0, 40], [40, 40], [40, 0]]
)
geometry: new LineString([
[0, 0],
[10, 20],
[0, 40],
[40, 40],
[40, 0],
]),
});
features.length = 0;
features.push(lineFeature);
@@ -241,7 +247,7 @@ describe('ol.interaction.Modify', function() {
const firstRevision = first.getGeometry().getRevision();
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
@@ -263,11 +269,15 @@ describe('ol.interaction.Modify', function() {
validateEvents(events, features);
});
it('deletes last vertex of a LineString', function() {
it('deletes last vertex of a LineString', function () {
const lineFeature = new Feature({
geometry: new LineString(
[[0, 0], [10, 20], [0, 40], [40, 40], [40, 0]]
)
geometry: new LineString([
[0, 0],
[10, 20],
[0, 40],
[40, 40],
[40, 0],
]),
});
features.length = 0;
features.push(lineFeature);
@@ -277,7 +287,7 @@ describe('ol.interaction.Modify', function() {
const firstRevision = first.getGeometry().getRevision();
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
@@ -299,11 +309,15 @@ describe('ol.interaction.Modify', function() {
validateEvents(events, features);
});
it('deletes vertex of a LineString programmatically', function() {
it('deletes vertex of a LineString programmatically', function () {
const lineFeature = new Feature({
geometry: new LineString(
[[0, 0], [10, 20], [0, 40], [40, 40], [40, 0]]
)
geometry: new LineString([
[0, 0],
[10, 20],
[0, 40],
[40, 40],
[40, 0],
]),
});
features.length = 0;
features.push(lineFeature);
@@ -313,7 +327,7 @@ describe('ol.interaction.Modify', function() {
const firstRevision = first.getGeometry().getRevision();
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
@@ -335,23 +349,24 @@ describe('ol.interaction.Modify', function() {
validateEvents(events, features);
});
});
describe('vertex modification', function() {
it('keeps the third dimension', function() {
describe('vertex modification', function () {
it('keeps the third dimension', function () {
const lineFeature = new Feature({
geometry: new LineString(
[[0, 0, 10], [10, 20, 20], [0, 40, 30], [40, 40, 40], [40, 0, 50]]
)
geometry: new LineString([
[0, 0, 10],
[10, 20, 20],
[0, 40, 30],
[40, 40, 40],
[40, 0, 50],
]),
});
features.length = 0;
features.push(lineFeature);
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
@@ -380,17 +395,16 @@ describe('ol.interaction.Modify', function() {
expect(lineFeature.getGeometry().getCoordinates()[2][2]).to.equal(30);
expect(lineFeature.getGeometry().getCoordinates()[4][2]).to.equal(50);
});
});
describe('circle modification', function() {
it('changes the circle radius and center', function() {
describe('circle modification', function () {
it('changes the circle radius and center', function () {
const circleFeature = new Feature(new Circle([10, 10], 20));
features.length = 0;
features.push(circleFeature);
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
@@ -425,17 +439,19 @@ describe('ol.interaction.Modify', function() {
expect(circleFeature.getGeometry().getCenter()).to.eql([5, 5]);
});
it('changes the circle radius and center in a user projection', function() {
it('changes the circle radius and center in a user projection', function () {
const userProjection = 'EPSG:3857';
setUserProjection(userProjection);
const viewProjection = map.getView().getProjection();
const circleFeature = new Feature(new Circle([10, 10], 20).transform(viewProjection, userProjection));
const circleFeature = new Feature(
new Circle([10, 10], 20).transform(viewProjection, userProjection)
);
features.length = 0;
features.push(circleFeature);
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
@@ -446,7 +462,10 @@ describe('ol.interaction.Modify', function() {
simulateEvent('pointerdrag', 5, -5, null, 0);
simulateEvent('pointerup', 5, -5, null, 0);
const geometry1 = circleFeature.getGeometry().clone().transform(userProjection, viewProjection);
const geometry1 = circleFeature
.getGeometry()
.clone()
.transform(userProjection, viewProjection);
expect(geometry1.getRadius()).to.roughlyEqual(20, 1e-9);
expect(geometry1.getCenter()).to.eql([5, 5]);
@@ -457,7 +476,10 @@ describe('ol.interaction.Modify', function() {
simulateEvent('pointerdrag', 30, -5, null, 0);
simulateEvent('pointerup', 30, -5, null, 0);
const geometry2 = circleFeature.getGeometry().clone().transform(userProjection, viewProjection);
const geometry2 = circleFeature
.getGeometry()
.clone()
.transform(userProjection, viewProjection);
expect(geometry2.getRadius()).to.roughlyEqual(25, 1e-9);
expect(geometry2.getCenter()).to.eql([5, 5]);
@@ -468,18 +490,21 @@ describe('ol.interaction.Modify', function() {
simulateEvent('pointerdrag', 5, -35, null, 0);
simulateEvent('pointerup', 5, -35, null, 0);
const geometry3 = circleFeature.getGeometry().clone().transform(userProjection, viewProjection);
const geometry3 = circleFeature
.getGeometry()
.clone()
.transform(userProjection, viewProjection);
expect(geometry3.getRadius()).to.roughlyEqual(30, 1e-9);
expect(geometry3.getCenter()).to.eql([5, 5]);
});
});
describe('boundary modification', function() {
describe('boundary modification', function () {
let modify, feature, events;
beforeEach(function() {
beforeEach(function () {
modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
@@ -488,7 +513,7 @@ describe('ol.interaction.Modify', function() {
events = trackEvents(feature, modify);
});
it('clicking vertex should delete it and +r1', function() {
it('clicking vertex should delete it and +r1', function () {
expect(feature.getGeometry().getRevision()).to.equal(1);
expect(feature.getGeometry().getCoordinates()[0]).to.have.length(5);
@@ -503,7 +528,7 @@ describe('ol.interaction.Modify', function() {
validateEvents(events, [feature]);
});
it('single clicking boundary should add vertex and +r1', function() {
it('single clicking boundary should add vertex and +r1', function () {
expect(feature.getGeometry().getRevision()).to.equal(1);
expect(feature.getGeometry().getCoordinates()[0]).to.have.length(5);
@@ -518,7 +543,7 @@ describe('ol.interaction.Modify', function() {
validateEvents(events, [feature]);
});
it('single clicking on created vertex should delete it again', function() {
it('single clicking on created vertex should delete it again', function () {
expect(feature.getGeometry().getRevision()).to.equal(1);
expect(feature.getGeometry().getCoordinates()[0]).to.have.length(5);
@@ -544,7 +569,7 @@ describe('ol.interaction.Modify', function() {
validateEvents(events, [feature]);
});
it('clicking with drag should add vertex and +r3', function() {
it('clicking with drag should add vertex and +r3', function () {
expect(feature.getGeometry().getRevision()).to.equal(1);
expect(feature.getGeometry().getCoordinates()[0]).to.have.length(5);
@@ -560,7 +585,7 @@ describe('ol.interaction.Modify', function() {
validateEvents(events, [feature]);
});
it('clicking with right button should not add a vertex', function() {
it('clicking with right button should not add a vertex', function () {
expect(feature.getGeometry().getRevision()).to.equal(1);
expect(feature.getGeometry().getCoordinates()[0]).to.have.length(5);
@@ -575,17 +600,15 @@ describe('ol.interaction.Modify', function() {
expect(feature.getGeometry().getCoordinates()[0]).to.have.length(5);
expect(events).to.have.length(0);
});
});
describe('double click deleteCondition', function() {
describe('double click deleteCondition', function () {
let modify, feature, events;
beforeEach(function() {
beforeEach(function () {
modify = new Modify({
features: new Collection(features),
deleteCondition: doubleClick
deleteCondition: doubleClick,
});
map.addInteraction(modify);
@@ -594,8 +617,7 @@ describe('ol.interaction.Modify', function() {
events = trackEvents(feature, modify);
});
it('should delete vertex on double click', function() {
it('should delete vertex on double click', function () {
expect(feature.getGeometry().getRevision()).to.equal(1);
expect(feature.getGeometry().getCoordinates()[0]).to.have.length(5);
@@ -613,8 +635,7 @@ describe('ol.interaction.Modify', function() {
validateEvents(events, features);
});
it('should do nothing on single click', function() {
it('should do nothing on single click', function () {
expect(feature.getGeometry().getRevision()).to.equal(1);
expect(feature.getGeometry().getCoordinates()[0]).to.have.length(5);
@@ -630,15 +651,15 @@ describe('ol.interaction.Modify', function() {
});
});
describe('insertVertexCondition', function() {
it('calls the callback function', function() {
const listenerSpy = sinon.spy(function(event) {
describe('insertVertexCondition', function () {
it('calls the callback function', function () {
const listenerSpy = sinon.spy(function (event) {
return false;
});
const modify = new Modify({
features: new Collection(features),
insertVertexCondition: listenerSpy
insertVertexCondition: listenerSpy,
});
map.addInteraction(modify);
const feature = features[0];
@@ -664,26 +685,26 @@ describe('ol.interaction.Modify', function() {
});
});
describe('handle feature change', function() {
describe('handle feature change', function () {
let getModifyListeners;
beforeEach(function() {
getModifyListeners = function(feature, modify) {
beforeEach(function () {
getModifyListeners = function (feature, modify) {
const listeners = feature.listeners_['change'];
const candidates = getValues(modify);
return listeners.filter(function(listener) {
return listeners.filter(function (listener) {
return candidates.indexOf(listener) !== -1;
});
};
});
it('updates circle segment data', function() {
it('updates circle segment data', function () {
const feature = new Feature(new Circle([10, 10], 20));
features.length = 0;
features.push(feature);
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
@@ -694,10 +715,11 @@ describe('ol.interaction.Modify', function() {
let firstSegmentData;
firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5],
function(node) {
return node;
});
firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5], function (
node
) {
return node;
});
expect(firstSegmentData.segment[0]).to.eql([10, 10]);
expect(firstSegmentData.segment[1]).to.eql([10, 10]);
@@ -706,10 +728,11 @@ describe('ol.interaction.Modify', function() {
center[1] = 1;
feature.getGeometry().setCenter(center);
firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5],
function(node) {
return node;
});
firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5], function (
node
) {
return node;
});
expect(firstSegmentData.segment[0]).to.eql([1, 1]);
expect(firstSegmentData.segment[1]).to.eql([1, 1]);
@@ -717,9 +740,9 @@ describe('ol.interaction.Modify', function() {
expect(listeners).to.have.length(1);
});
it('updates polygon segment data', function() {
it('updates polygon segment data', function () {
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
@@ -731,10 +754,11 @@ describe('ol.interaction.Modify', function() {
let firstSegmentData;
firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5],
function(node) {
return node;
});
firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5], function (
node
) {
return node;
});
expect(firstSegmentData.segment[0]).to.eql([0, 0]);
expect(firstSegmentData.segment[1]).to.eql([10, 20]);
@@ -744,10 +768,11 @@ describe('ol.interaction.Modify', function() {
firstVertex[1] = 1;
feature.getGeometry().setCoordinates(coordinates);
firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5],
function(node) {
return node;
});
firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5], function (
node
) {
return node;
});
expect(firstSegmentData.segment[0]).to.eql([1, 1]);
expect(firstSegmentData.segment[1]).to.eql([10, 20]);
@@ -756,11 +781,11 @@ describe('ol.interaction.Modify', function() {
});
});
describe('handle feature removal during down-up sequence', function() {
it('removes segment data of removed features from dragSegments_', function() {
describe('handle feature removal during down-up sequence', function () {
it('removes segment data of removed features from dragSegments_', function () {
const collection = new Collection(features);
const modify = new Modify({
features: collection
features: collection,
});
map.addInteraction(modify);
simulateEvent('pointermove', 0, 0, null, 0);
@@ -768,16 +793,16 @@ describe('ol.interaction.Modify', function() {
simulateEvent('pointermove', -10, -10, null, 0);
simulateEvent('pointerdrag', -10, -10, null, 0);
collection.remove(features[0]);
expect(function() {
expect(function () {
simulateEvent('pointerup', -10, -10, null, 0);
}).to.not.throwException();
});
});
describe('#setActive', function() {
it('removes the vertexFeature of deactivation', function() {
describe('#setActive', function () {
it('removes the vertexFeature of deactivation', function () {
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
expect(modify.vertexFeature_).to.be(null);
@@ -790,29 +815,29 @@ describe('ol.interaction.Modify', function() {
});
});
describe('#getOverlay', function() {
it('returns the feature overlay layer', function() {
describe('#getOverlay', function () {
it('returns the feature overlay layer', function () {
const modify = new Modify({
features: new Collection()
features: new Collection(),
});
expect (modify.getOverlay()).to.eql(modify.overlay_);
expect(modify.getOverlay()).to.eql(modify.overlay_);
});
});
describe('circle modification with snap', function() {
it('changes the circle radius and center', function() {
describe('circle modification with snap', function () {
it('changes the circle radius and center', function () {
const circleFeature = new Feature(new Circle([10, 10], 20));
features.length = 0;
features.push(circleFeature);
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
const snap = new Snap({
features: new Collection(features),
pixelTolerance: 1
pixelTolerance: 1,
});
map.addInteraction(snap);
@@ -847,23 +872,25 @@ describe('ol.interaction.Modify', function() {
expect(circleFeature.getGeometry().getCenter()).to.eql([5, 5]);
});
it('changes the circle radius and center in a user projection', function() {
it('changes the circle radius and center in a user projection', function () {
const userProjection = 'EPSG:3857';
setUserProjection(userProjection);
const viewProjection = map.getView().getProjection();
const circleFeature = new Feature(new Circle([10, 10], 20).transform(viewProjection, userProjection));
const circleFeature = new Feature(
new Circle([10, 10], 20).transform(viewProjection, userProjection)
);
features.length = 0;
features.push(circleFeature);
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
const snap = new Snap({
features: new Collection(features),
pixelTolerance: 1
pixelTolerance: 1,
});
map.addInteraction(snap);
@@ -874,7 +901,10 @@ describe('ol.interaction.Modify', function() {
simulateEvent('pointerdrag', 5, -5, null, 0);
simulateEvent('pointerup', 5, -5, null, 0);
const geometry1 = circleFeature.getGeometry().clone().transform(userProjection, viewProjection);
const geometry1 = circleFeature
.getGeometry()
.clone()
.transform(userProjection, viewProjection);
expect(geometry1.getRadius()).to.roughlyEqual(20, 1e-9);
expect(geometry1.getCenter()).to.eql([5, 5]);
@@ -885,7 +915,10 @@ describe('ol.interaction.Modify', function() {
simulateEvent('pointerdrag', 30, -5, null, 0);
simulateEvent('pointerup', 30, -5, null, 0);
const geometry2 = circleFeature.getGeometry().clone().transform(userProjection, viewProjection);
const geometry2 = circleFeature
.getGeometry()
.clone()
.transform(userProjection, viewProjection);
expect(geometry2.getRadius()).to.roughlyEqual(25, 1e-9);
expect(geometry2.getCenter()).to.eql([5, 5]);
@@ -896,10 +929,12 @@ describe('ol.interaction.Modify', function() {
simulateEvent('pointerdrag', 5, -35, null, 0);
simulateEvent('pointerup', 5, -35, null, 0);
const geometry3 = circleFeature.getGeometry().clone().transform(userProjection, viewProjection);
const geometry3 = circleFeature
.getGeometry()
.clone()
.transform(userProjection, viewProjection);
expect(geometry3.getRadius()).to.roughlyEqual(30, 1e-9);
expect(geometry3.getCenter()).to.eql([5, 5]);
});
});
});