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,33 +1,34 @@
import Circle from '../../../../src/ol/geom/Circle.js';
import Collection from '../../../../src/ol/Collection.js';
import Feature from '../../../../src/ol/Feature.js';
import Map from '../../../../src/ol/Map.js';
import View from '../../../../src/ol/View.js';
import Circle from '../../../../src/ol/geom/Circle.js';
import Point from '../../../../src/ol/geom/Point.js';
import LineString from '../../../../src/ol/geom/LineString.js';
import Map from '../../../../src/ol/Map.js';
import Point from '../../../../src/ol/geom/Point.js';
import Snap from '../../../../src/ol/interaction/Snap.js';
import {useGeographic, clearUserProjection, setUserProjection, transform} from '../../../../src/ol/proj.js';
import View from '../../../../src/ol/View.js';
import {
clearUserProjection,
setUserProjection,
transform,
useGeographic,
} from '../../../../src/ol/proj.js';
import {overrideRAF} from '../../util.js';
describe('ol.interaction.Snap', function() {
describe('constructor', function() {
it('can be constructed without arguments', function() {
describe('ol.interaction.Snap', function () {
describe('constructor', function () {
it('can be constructed without arguments', function () {
const instance = new Snap();
expect(instance).to.be.an(Snap);
});
});
describe('handleEvent', function() {
describe('handleEvent', function () {
let target, map;
const width = 360;
const height = 180;
beforeEach(function(done) {
beforeEach(function (done) {
target = document.createElement('div');
const style = target.style;
@@ -43,166 +44,207 @@ describe('ol.interaction.Snap', 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();
});
it('can handle XYZ coordinates', function() {
it('can handle XYZ coordinates', function () {
const point = new Feature(new Point([0, 0, 123]));
const snapInteraction = new Snap({
features: new Collection([point])
features: new Collection([point]),
});
snapInteraction.setMap(map);
const event = {
pixel: [width / 2, height / 2],
coordinate: [0, 0],
map: map
map: map,
};
snapInteraction.handleEvent(event);
// check that the coordinate is in XY and not XYZ
expect(event.coordinate).to.eql([0, 0]);
});
it('snaps to edges only', function() {
const point = new Feature(new LineString([[-10, 0], [10, 0]]));
it('snaps to edges only', function () {
const point = new Feature(
new LineString([
[-10, 0],
[10, 0],
])
);
const snapInteraction = new Snap({
features: new Collection([point]),
pixelTolerance: 5,
vertex: false
vertex: false,
});
snapInteraction.setMap(map);
const event = {
pixel: [7 + width / 2, height / 2 - 4],
coordinate: [7, 4],
map: map
map: map,
};
snapInteraction.handleEvent(event);
expect(event.coordinate).to.eql([7, 0]);
});
it('snaps to vertices only', function() {
const point = new Feature(new LineString([[-10, 0], [10, 0]]));
it('snaps to vertices only', function () {
const point = new Feature(
new LineString([
[-10, 0],
[10, 0],
])
);
const snapInteraction = new Snap({
features: new Collection([point]),
pixelTolerance: 5,
edge: false
edge: false,
});
snapInteraction.setMap(map);
const event = {
pixel: [7 + width / 2, height / 2 - 4],
coordinate: [7, 4],
map: map
map: map,
};
snapInteraction.handleEvent(event);
expect(event.coordinate).to.eql([10, 0]);
});
it('snaps to circle', function() {
it('snaps to circle', function () {
const circle = new Feature(new Circle([0, 0], 10));
const snapInteraction = new Snap({
features: new Collection([circle]),
pixelTolerance: 5
pixelTolerance: 5,
});
snapInteraction.setMap(map);
const event = {
pixel: [5 + width / 2, height / 2 - 5],
coordinate: [5, 5],
map: map
map: map,
};
snapInteraction.handleEvent(event);
expect(event.coordinate[0]).to.roughlyEqual(Math.sin(Math.PI / 4) * 10, 1e-10);
expect(event.coordinate[1]).to.roughlyEqual(Math.sin(Math.PI / 4) * 10, 1e-10);
expect(event.coordinate[0]).to.roughlyEqual(
Math.sin(Math.PI / 4) * 10,
1e-10
);
expect(event.coordinate[1]).to.roughlyEqual(
Math.sin(Math.PI / 4) * 10,
1e-10
);
});
it('snaps to circle in a user projection', function() {
it('snaps to circle in a user projection', function () {
const userProjection = 'EPSG:3857';
setUserProjection(userProjection);
const viewProjection = map.getView().getProjection();
const circle = new Feature(new Circle([0, 0], 10).transform(viewProjection, userProjection));
const circle = new Feature(
new Circle([0, 0], 10).transform(viewProjection, userProjection)
);
const snapInteraction = new Snap({
features: new Collection([circle]),
pixelTolerance: 5
pixelTolerance: 5,
});
snapInteraction.setMap(map);
const event = {
pixel: [5 + width / 2, height / 2 - 5],
coordinate: transform([5, 5], viewProjection, userProjection),
map: map
map: map,
};
snapInteraction.handleEvent(event);
const coordinate = transform([Math.sin(Math.PI / 4) * 10, Math.sin(Math.PI / 4) * 10], viewProjection, userProjection);
const coordinate = transform(
[Math.sin(Math.PI / 4) * 10, Math.sin(Math.PI / 4) * 10],
viewProjection,
userProjection
);
expect(event.coordinate[0]).to.roughlyEqual(coordinate[0], 1e-10);
expect(event.coordinate[1]).to.roughlyEqual(coordinate[1], 1e-10);
});
it('handle feature without geometry', function() {
it('handle feature without geometry', function () {
const feature = new Feature();
const snapInteraction = new Snap({
features: new Collection([feature]),
pixelTolerance: 5,
edge: false
edge: false,
});
snapInteraction.setMap(map);
feature.setGeometry(new LineString([[-10, 0], [10, 0]]));
feature.setGeometry(
new LineString([
[-10, 0],
[10, 0],
])
);
const event = {
pixel: [7 + width / 2, height / 2 - 4],
coordinate: [7, 4],
map: map
map: map,
};
snapInteraction.handleEvent(event);
expect(event.coordinate).to.eql([10, 0]);
});
it('handle geometry changes', function() {
const line = new Feature(new LineString([[-10, 0], [0, 0]]));
it('handle geometry changes', function () {
const line = new Feature(
new LineString([
[-10, 0],
[0, 0],
])
);
const snapInteraction = new Snap({
features: new Collection([line]),
pixelTolerance: 5,
edge: false
edge: false,
});
snapInteraction.setMap(map);
line.getGeometry().setCoordinates([[-10, 0], [10, 0]]);
line.getGeometry().setCoordinates([
[-10, 0],
[10, 0],
]);
const event = {
pixel: [7 + width / 2, height / 2 - 4],
coordinate: [7, 4],
map: map
map: map,
};
snapInteraction.handleEvent(event);
expect(event.coordinate).to.eql([10, 0]);
});
it('handle geometry name changes', function() {
it('handle geometry name changes', function () {
const line = new Feature({
geometry: new LineString([[-10, 0], [0, 0]]),
alt_geometry: new LineString([[-10, 0], [10, 0]])
geometry: new LineString([
[-10, 0],
[0, 0],
]),
alt_geometry: new LineString([
[-10, 0],
[10, 0],
]),
});
const snapInteraction = new Snap({
features: new Collection([line]),
pixelTolerance: 5,
edge: false
edge: false,
});
snapInteraction.setMap(map);
@@ -211,12 +253,11 @@ describe('ol.interaction.Snap', function() {
const event = {
pixel: [7 + width / 2, height / 2 - 4],
coordinate: [7, 4],
map: map
map: map,
};
snapInteraction.handleEvent(event);
expect(event.coordinate).to.eql([10, 0]);
});
});
describe('handleEvent - useGeographic', () => {
@@ -225,7 +266,7 @@ describe('ol.interaction.Snap', function() {
let restoreRAF;
beforeEach(done => {
beforeEach((done) => {
restoreRAF = overrideRAF();
useGeographic();
@@ -236,7 +277,7 @@ describe('ol.interaction.Snap', function() {
top: 0,
left: 0,
width: `${size}px`,
height: `${size}px`
height: `${size}px`,
});
document.body.appendChild(target);
@@ -244,8 +285,8 @@ describe('ol.interaction.Snap', function() {
target: target,
view: new View({
center: [0, 0],
zoom: 0
})
zoom: 0,
}),
});
map.once('postrender', () => {
@@ -266,11 +307,13 @@ describe('ol.interaction.Snap', function() {
const point = new Feature(new Point([lon, lat]));
const snap = new Snap({
features: new Collection([point])
features: new Collection([point]),
});
snap.setMap(map);
const expectedPixel = map.getPixelFromCoordinate([lon, lat]).map(value => Math.round(value));
const expectedPixel = map
.getPixelFromCoordinate([lon, lat])
.map((value) => Math.round(value));
const delta = 5;
const pixel = expectedPixel.slice();
@@ -282,14 +325,12 @@ describe('ol.interaction.Snap', function() {
const event = {
pixel: pixel,
coordinate: coordinate,
map: map
map: map,
};
snap.handleEvent(event);
expect(event.coordinate).to.eql([lon, lat]);
expect(event.pixel).to.eql(expectedPixel);
});
});
});