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:
@@ -1,51 +1,50 @@
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import DragAndDrop from '../../../../src/ol/interaction/DragAndDrop.js';
|
||||
import Event from '../../../../src/ol/events/Event.js';
|
||||
import EventTarget from '../../../../src/ol/events/Target.js';
|
||||
import GeoJSON from '../../../../src/ol/format/GeoJSON.js';
|
||||
import DragAndDrop from '../../../../src/ol/interaction/DragAndDrop.js';
|
||||
import VectorSource from '../../../../src/ol/source/Vector.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
|
||||
where('FileReader').describe('ol.interaction.DragAndDrop', function() {
|
||||
where('FileReader').describe('ol.interaction.DragAndDrop', function () {
|
||||
let viewport, map, interaction;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
viewport = new EventTarget();
|
||||
map = {
|
||||
getViewport: function() {
|
||||
getViewport: function () {
|
||||
return viewport;
|
||||
},
|
||||
getView: function() {
|
||||
getView: function () {
|
||||
return new View();
|
||||
}
|
||||
},
|
||||
};
|
||||
interaction = new DragAndDrop({
|
||||
formatConstructors: [GeoJSON]
|
||||
formatConstructors: [GeoJSON],
|
||||
});
|
||||
});
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('can be constructed without arguments', function() {
|
||||
describe('constructor', function () {
|
||||
it('can be constructed without arguments', function () {
|
||||
const interaction = new DragAndDrop();
|
||||
expect(interaction).to.be.an(DragAndDrop);
|
||||
});
|
||||
|
||||
it('sets formatConstructors on the instance', function() {
|
||||
it('sets formatConstructors on the instance', function () {
|
||||
expect(interaction.formatConstructors_).to.have.length(1);
|
||||
});
|
||||
|
||||
it('accepts a source option', function() {
|
||||
it('accepts a source option', function () {
|
||||
const source = new VectorSource();
|
||||
const drop = new DragAndDrop({
|
||||
formatConstructors: [GeoJSON],
|
||||
source: source
|
||||
source: source,
|
||||
});
|
||||
expect(drop.source_).to.equal(source);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setActive()', function() {
|
||||
it('registers and unregisters listeners', function() {
|
||||
describe('#setActive()', function () {
|
||||
it('registers and unregisters listeners', function () {
|
||||
interaction.setMap(map);
|
||||
interaction.setActive(true);
|
||||
expect(viewport.hasListener('dragenter')).to.be(true);
|
||||
@@ -58,8 +57,8 @@ where('FileReader').describe('ol.interaction.DragAndDrop', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setMap()', function() {
|
||||
it('registers and unregisters listeners', function() {
|
||||
describe('#setMap()', function () {
|
||||
it('registers and unregisters listeners', function () {
|
||||
interaction.setMap(map);
|
||||
expect(viewport.hasListener('dragenter')).to.be(true);
|
||||
expect(viewport.hasListener('dragover')).to.be(true);
|
||||
@@ -70,11 +69,11 @@ where('FileReader').describe('ol.interaction.DragAndDrop', function() {
|
||||
expect(viewport.hasListener('drop')).to.be(false);
|
||||
});
|
||||
|
||||
it('registers and unregisters listeners on a custom target', function() {
|
||||
it('registers and unregisters listeners on a custom target', function () {
|
||||
const customTarget = new EventTarget();
|
||||
interaction = new DragAndDrop({
|
||||
formatConstructors: [GeoJSON],
|
||||
target: customTarget
|
||||
target: customTarget,
|
||||
});
|
||||
interaction.setMap(map);
|
||||
expect(customTarget.hasListener('dragenter')).to.be(true);
|
||||
@@ -87,10 +86,10 @@ where('FileReader').describe('ol.interaction.DragAndDrop', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#handleDrop_', function() {
|
||||
describe('#handleDrop_', function () {
|
||||
let OrigFileReader;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
OrigFileReader = FileReader;
|
||||
|
||||
class MockFileReader extends EventTarget {
|
||||
@@ -105,12 +104,12 @@ where('FileReader').describe('ol.interaction.DragAndDrop', function() {
|
||||
FileReader = MockFileReader;
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
FileReader = OrigFileReader;
|
||||
});
|
||||
|
||||
it('reads dropped files', function(done) {
|
||||
interaction.on('addfeatures', function(evt) {
|
||||
it('reads dropped files', function (done) {
|
||||
interaction.on('addfeatures', function (evt) {
|
||||
expect(evt.features.length).to.be(1);
|
||||
done();
|
||||
});
|
||||
@@ -124,27 +123,27 @@ where('FileReader').describe('ol.interaction.DragAndDrop', function() {
|
||||
event.type = 'drop';
|
||||
event.dataTransfer.files = {
|
||||
length: 1,
|
||||
item: function() {
|
||||
item: function () {
|
||||
return JSON.stringify({
|
||||
type: 'FeatureCollection',
|
||||
features: [{type: 'Feature', id: '1'}]
|
||||
features: [{type: 'Feature', id: '1'}],
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
viewport.dispatchEvent(event);
|
||||
expect(event.dataTransfer.dropEffect).to.be('copy');
|
||||
expect(event.propagationStopped).to.be(true);
|
||||
});
|
||||
|
||||
it('adds dropped features to a source', function(done) {
|
||||
it('adds dropped features to a source', function (done) {
|
||||
const source = new VectorSource();
|
||||
const drop = new DragAndDrop({
|
||||
formatConstructors: [GeoJSON],
|
||||
source: source
|
||||
source: source,
|
||||
});
|
||||
drop.setMap(map);
|
||||
|
||||
drop.on('addfeatures', function(evt) {
|
||||
drop.on('addfeatures', function (evt) {
|
||||
const features = source.getFeatures();
|
||||
expect(features.length).to.be(1);
|
||||
done();
|
||||
@@ -159,17 +158,16 @@ where('FileReader').describe('ol.interaction.DragAndDrop', function() {
|
||||
event.type = 'drop';
|
||||
event.dataTransfer.files = {
|
||||
length: 1,
|
||||
item: function() {
|
||||
item: function () {
|
||||
return JSON.stringify({
|
||||
type: 'FeatureCollection',
|
||||
features: [{type: 'Feature', id: '1'}]
|
||||
features: [{type: 'Feature', id: '1'}],
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
viewport.dispatchEvent(event);
|
||||
expect(event.dataTransfer.dropEffect).to.be('copy');
|
||||
expect(event.propagationStopped).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user