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,52 +1,53 @@
import Icon from '../../../../src/ol/style/Icon.js';
import IconImage, {
get as getIconImage,
} from '../../../../src/ol/style/IconImage.js';
import {getUid} from '../../../../src/ol/util.js';
import {shared as iconImageCache} from '../../../../src/ol/style/IconImageCache.js';
import Icon from '../../../../src/ol/style/Icon.js';
import IconImage, {get as getIconImage} from '../../../../src/ol/style/IconImage.js';
describe('ol.style.Icon', function() {
describe('ol.style.Icon', function () {
const size = [36, 48];
const src = 'data:image/gif;base64,' +
'R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=';
const src =
'data:image/gif;base64,' +
'R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=';
describe('constructor', function() {
it('caches canvas images with a uid as src', function() {
describe('constructor', function () {
it('caches canvas images with a uid as src', function () {
const canvas = document.createElement('canvas');
new Icon({
img: canvas,
imgSize: size
imgSize: size,
});
expect(getIconImage(canvas, getUid(canvas), size, '').getImage()).to.eql(canvas);
expect(getIconImage(canvas, getUid(canvas), size, '').getImage()).to.eql(
canvas
);
});
it('imgSize overrides img.width and img.height', function(done) {
it('imgSize overrides img.width and img.height', function (done) {
const style = new Icon({
src: src,
imgSize: size
imgSize: size,
});
const iconImage = style.iconImage_;
iconImage.addEventListener('change', function() {
iconImage.addEventListener('change', function () {
expect([iconImage.image_.width, iconImage.image_.height]).to.eql(size);
done();
});
style.load();
});
});
describe('#clone', function() {
it('creates a new ol.style.Icon', function() {
describe('#clone', function () {
it('creates a new ol.style.Icon', function () {
const original = new Icon({
src: src
src: src,
});
const clone = original.clone();
expect(clone).to.be.an(Icon);
expect(clone).to.not.be(original);
});
it('copies all values ', function() {
it('copies all values ', function () {
const canvas = document.createElement('canvas');
const original = new Icon({
anchor: [1, 0],
@@ -62,7 +63,7 @@ describe('ol.style.Icon', function() {
opacity: 0.5,
scale: 2,
rotation: 4,
size: [10, 12]
size: [10, 12],
});
const clone = original.clone();
@@ -83,7 +84,7 @@ describe('ol.style.Icon', function() {
expect(original.getRotateWithView()).to.eql(clone.getRotateWithView());
const original2 = new Icon({
src: src
src: src,
});
const clone2 = original2.clone();
expect(original2.getImage(1)).to.be(clone2.getImage(1));
@@ -91,14 +92,14 @@ describe('ol.style.Icon', function() {
expect(original2.getSrc()).to.eql(clone2.getSrc());
});
it('the clone does not reference the same objects as the original', function() {
it('the clone does not reference the same objects as the original', function () {
const original = new Icon({
anchor: [1, 0],
color: [1, 2, 3, 0.4],
src: src,
offset: [1, 2],
size: [10, 12],
displacement: [5, 6]
displacement: [5, 6],
});
const clone = original.clone();
expect(original.getAnchor()).not.to.be(clone.getAnchor());
@@ -120,66 +121,66 @@ describe('ol.style.Icon', function() {
});
});
describe('#getAnchor', function() {
describe('#getAnchor', function () {
const fractionAnchor = [0.25, 0.25];
it('uses fractional units by default', function() {
it('uses fractional units by default', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
anchor: fractionAnchor
anchor: fractionAnchor,
});
expect(iconStyle.getAnchor()).to.eql([9, 12]);
});
it('uses pixels units', function() {
it('uses pixels units', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
anchor: [2, 18],
anchorXUnits: 'pixels',
anchorYUnits: 'pixels'
anchorYUnits: 'pixels',
});
expect(iconStyle.getAnchor()).to.eql([2, 18]);
});
it('uses a bottom left anchor origin', function() {
it('uses a bottom left anchor origin', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
anchor: fractionAnchor,
anchorOrigin: 'bottom-left'
anchorOrigin: 'bottom-left',
});
expect(iconStyle.getAnchor()).to.eql([9, 36]);
});
it('uses a bottom right anchor origin', function() {
it('uses a bottom right anchor origin', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
anchor: fractionAnchor,
anchorOrigin: 'bottom-right'
anchorOrigin: 'bottom-right',
});
expect(iconStyle.getAnchor()).to.eql([27, 36]);
});
it('uses a top right anchor origin', function() {
it('uses a top right anchor origin', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
anchor: fractionAnchor,
anchorOrigin: 'top-right'
anchorOrigin: 'top-right',
});
expect(iconStyle.getAnchor()).to.eql([27, 12]);
});
});
describe('#setAnchor', function() {
it('resets the cached anchor', function() {
describe('#setAnchor', function () {
it('resets the cached anchor', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
anchor: [0.25, 0.25]
anchor: [0.25, 0.25],
});
expect(iconStyle.getAnchor()).to.eql([9, 12]);
@@ -188,69 +189,69 @@ describe('ol.style.Icon', function() {
});
});
describe('#getOrigin', function() {
describe('#getOrigin', function () {
const offset = [16, 20];
const imageSize = [144, 192];
it('uses a top left offset origin (default)', function() {
const iconStyle = new Icon({
src: 'test.png',
size: size,
offset: offset
});
expect(iconStyle.getOrigin()).to.eql([16, 20]);
});
it('uses a bottom left offset origin', function() {
it('uses a top left offset origin (default)', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
offset: offset,
offsetOrigin: 'bottom-left'
});
expect(iconStyle.getOrigin()).to.eql([16, 20]);
});
it('uses a bottom left offset origin', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
offset: offset,
offsetOrigin: 'bottom-left',
});
iconStyle.iconImage_.size_ = imageSize;
expect(iconStyle.getOrigin()).to.eql([16, 124]);
});
it('uses a bottom right offset origin', function() {
it('uses a bottom right offset origin', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
offset: offset,
offsetOrigin: 'bottom-right'
offsetOrigin: 'bottom-right',
});
iconStyle.iconImage_.size_ = imageSize;
expect(iconStyle.getOrigin()).to.eql([92, 124]);
});
it('uses a top right offset origin', function() {
const iconStyle = new Icon({
src: 'test.png',
size: size,
offset: offset,
offsetOrigin: 'top-right'
});
iconStyle.iconImage_.size_ = imageSize;
expect(iconStyle.getOrigin()).to.eql([92, 20]);
});
it('uses a top right offset origin + displacement', function() {
it('uses a top right offset origin', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
offset: offset,
offsetOrigin: 'top-right',
displacement: [20, 10]
});
iconStyle.iconImage_.size_ = imageSize;
expect(iconStyle.getOrigin()).to.eql([92, 20]);
});
it('uses a top right offset origin + displacement', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
offset: offset,
offsetOrigin: 'top-right',
displacement: [20, 10],
});
iconStyle.iconImage_.size_ = imageSize;
expect(iconStyle.getOrigin()).to.eql([92 + 20, 20 + 10]);
});
});
describe('#getImageSize', function() {
describe('#getImageSize', function () {
const imgSize = [144, 192];
it('takes the real image size', function() {
it('takes the real image size', function () {
// pretend that the image is already in the cache,
// this image will be used for the icon.
const src = 'test.png';
@@ -258,15 +259,15 @@ describe('ol.style.Icon', function() {
iconImageCache.set(src, null, null, iconImage);
const iconStyle = new Icon({
src: 'test.png'
src: 'test.png',
});
expect(iconStyle.getImageSize()).to.eql(imgSize);
});
it('uses the given image size', function() {
it('uses the given image size', function () {
const iconStyle = new Icon({
img: {src: 'test.png'},
imgSize: imgSize
imgSize: imgSize,
});
expect(iconStyle.getImageSize()).to.eql(imgSize);
});