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,14 +1,18 @@
|
||||
import {createCanvasContext2D, outerWidth, outerHeight, replaceChildren} from '../../../../src/ol/dom.js';
|
||||
import {
|
||||
createCanvasContext2D,
|
||||
outerHeight,
|
||||
outerWidth,
|
||||
replaceChildren,
|
||||
} from '../../../../src/ol/dom.js';
|
||||
|
||||
describe('ol.dom', function() {
|
||||
|
||||
describe('ol.dom.createCanvasContext2D', function() {
|
||||
describe('ol.dom', function () {
|
||||
describe('ol.dom.createCanvasContext2D', function () {
|
||||
// default values from
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas
|
||||
const defaultWidth = 300;
|
||||
const defaultHeight = 150;
|
||||
|
||||
it('returns a CanvasRenderingContext2D', function() {
|
||||
it('returns a CanvasRenderingContext2D', function () {
|
||||
const ctx = createCanvasContext2D();
|
||||
expect(ctx).to.be.a(CanvasRenderingContext2D);
|
||||
expect(ctx.canvas).to.be.a(HTMLCanvasElement);
|
||||
@@ -16,7 +20,7 @@ describe('ol.dom', function() {
|
||||
expect(ctx.canvas.height).to.be(defaultHeight);
|
||||
});
|
||||
|
||||
it('has the desired width', function() {
|
||||
it('has the desired width', function () {
|
||||
const ctx = createCanvasContext2D(42);
|
||||
expect(ctx).to.be.a(CanvasRenderingContext2D);
|
||||
expect(ctx.canvas).to.be.a(HTMLCanvasElement);
|
||||
@@ -24,7 +28,7 @@ describe('ol.dom', function() {
|
||||
expect(ctx.canvas.height).to.be(defaultHeight);
|
||||
});
|
||||
|
||||
it('has the desired height', function() {
|
||||
it('has the desired height', function () {
|
||||
const ctx = createCanvasContext2D(undefined, 42);
|
||||
expect(ctx).to.be.a(CanvasRenderingContext2D);
|
||||
expect(ctx.canvas).to.be.a(HTMLCanvasElement);
|
||||
@@ -32,19 +36,18 @@ describe('ol.dom', function() {
|
||||
expect(ctx.canvas.height).to.be(42);
|
||||
});
|
||||
|
||||
it('has the desired height and width', function() {
|
||||
it('has the desired height and width', function () {
|
||||
const ctx = createCanvasContext2D(42, 42);
|
||||
expect(ctx).to.be.a(CanvasRenderingContext2D);
|
||||
expect(ctx.canvas).to.be.a(HTMLCanvasElement);
|
||||
expect(ctx.canvas.width).to.be(42);
|
||||
expect(ctx.canvas.height).to.be(42);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.dom.outerWidth', function() {
|
||||
describe('ol.dom.outerWidth', function () {
|
||||
let element = null;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
element = document.createElement('div');
|
||||
element.style.padding = 0;
|
||||
element.style.margin = 0;
|
||||
@@ -53,126 +56,113 @@ describe('ol.dom', function() {
|
||||
element.style.height = '10px';
|
||||
document.body.appendChild(element);
|
||||
});
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
element.parentNode.removeChild(element);
|
||||
element = null;
|
||||
});
|
||||
|
||||
describe('without padding, margin or border', function() {
|
||||
|
||||
it('calculates correctly', function() {
|
||||
describe('without padding, margin or border', function () {
|
||||
it('calculates correctly', function () {
|
||||
const calcWidth = outerWidth(element);
|
||||
expect(calcWidth).to.be(10);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with padding', function() {
|
||||
it('calculates correctly (both sides)', function() {
|
||||
describe('with padding', function () {
|
||||
it('calculates correctly (both sides)', function () {
|
||||
element.style.padding = '5px';
|
||||
const calcWidth = outerWidth(element);
|
||||
expect(calcWidth).to.be(20);
|
||||
});
|
||||
|
||||
it('calculates correctly (one side)', function() {
|
||||
it('calculates correctly (one side)', function () {
|
||||
element.style.paddingLeft = '5px';
|
||||
const calcWidth = outerWidth(element);
|
||||
expect(calcWidth).to.be(15);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with margin', function() {
|
||||
|
||||
it('calculates correctly (both sides)', function() {
|
||||
describe('with margin', function () {
|
||||
it('calculates correctly (both sides)', function () {
|
||||
element.style.margin = '5px';
|
||||
const calcWidth = outerWidth(element);
|
||||
expect(calcWidth).to.be(20);
|
||||
});
|
||||
|
||||
it('calculates correctly (one side)', function() {
|
||||
it('calculates correctly (one side)', function () {
|
||||
element.style.marginLeft = '5px';
|
||||
const calcWidth = outerWidth(element);
|
||||
expect(calcWidth).to.be(15);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with border', function() {
|
||||
|
||||
it('calculates correctly (both sides)', function() {
|
||||
describe('with border', function () {
|
||||
it('calculates correctly (both sides)', function () {
|
||||
element.style.border = '5px solid chocolate';
|
||||
const calcWidth = outerWidth(element);
|
||||
expect(calcWidth).to.be(20);
|
||||
});
|
||||
|
||||
it('calculates correctly (one side)', function() {
|
||||
it('calculates correctly (one side)', function () {
|
||||
element.style.border = '5px solid chocolate';
|
||||
element.style.borderRightWidth = '0';
|
||||
const calcWidth = outerWidth(element);
|
||||
expect(calcWidth).to.be(15);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with padding and margin', function() {
|
||||
|
||||
it('calculates correctly (both sides)', function() {
|
||||
describe('with padding and margin', function () {
|
||||
it('calculates correctly (both sides)', function () {
|
||||
element.style.padding = '5px';
|
||||
element.style.margin = '5px';
|
||||
const calcWidth = outerWidth(element);
|
||||
expect(calcWidth).to.be(30);
|
||||
});
|
||||
|
||||
it('calculates correctly (one side)', function() {
|
||||
it('calculates correctly (one side)', function () {
|
||||
element.style.paddingLeft = '5px';
|
||||
element.style.marginLeft = '5px';
|
||||
const calcWidth = outerWidth(element);
|
||||
expect(calcWidth).to.be(20);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with padding and border', function() {
|
||||
|
||||
it('calculates correctly (both sides)', function() {
|
||||
describe('with padding and border', function () {
|
||||
it('calculates correctly (both sides)', function () {
|
||||
element.style.padding = '5px';
|
||||
element.style.border = '5px solid chocolate';
|
||||
const calcWidth = outerWidth(element);
|
||||
expect(calcWidth).to.be(30);
|
||||
});
|
||||
|
||||
it('calculates correctly (one side)', function() {
|
||||
it('calculates correctly (one side)', function () {
|
||||
element.style.paddingLeft = '5px';
|
||||
element.style.border = '5px solid chocolate';
|
||||
element.style.borderRightWidth = '0';
|
||||
const calcWidth = outerWidth(element);
|
||||
expect(calcWidth).to.be(20);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with margin and border', function() {
|
||||
|
||||
it('calculates correctly (both sides)', function() {
|
||||
describe('with margin and border', function () {
|
||||
it('calculates correctly (both sides)', function () {
|
||||
element.style.margin = '5px';
|
||||
element.style.border = '5px solid chocolate';
|
||||
const calcWidth = outerWidth(element);
|
||||
expect(calcWidth).to.be(30);
|
||||
});
|
||||
|
||||
it('calculates correctly (one side)', function() {
|
||||
it('calculates correctly (one side)', function () {
|
||||
element.style.marginLeft = '5px';
|
||||
element.style.border = '5px solid chocolate';
|
||||
element.style.borderRightWidth = '0';
|
||||
const calcWidth = outerWidth(element);
|
||||
expect(calcWidth).to.be(20);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with padding, margin and border', function() {
|
||||
|
||||
it('calculates correctly (both sides)', function() {
|
||||
describe('with padding, margin and border', function () {
|
||||
it('calculates correctly (both sides)', function () {
|
||||
element.style.margin = '5px';
|
||||
element.style.padding = '5px';
|
||||
element.style.border = '5px solid chocolate';
|
||||
@@ -180,7 +170,7 @@ describe('ol.dom', function() {
|
||||
expect(calcWidth).to.be(40);
|
||||
});
|
||||
|
||||
it('calculates correctly (one side)', function() {
|
||||
it('calculates correctly (one side)', function () {
|
||||
element.style.marginLeft = '5px';
|
||||
element.style.paddingLeft = '5px';
|
||||
element.style.border = '5px solid chocolate';
|
||||
@@ -188,14 +178,12 @@ describe('ol.dom', function() {
|
||||
const calcWidth = outerWidth(element);
|
||||
expect(calcWidth).to.be(25);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.dom.outerHeight', function() {
|
||||
describe('ol.dom.outerHeight', function () {
|
||||
let element = null;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
element = document.createElement('div');
|
||||
element.style.padding = 0;
|
||||
element.style.margin = 0;
|
||||
@@ -204,126 +192,113 @@ describe('ol.dom', function() {
|
||||
element.style.height = '10px';
|
||||
document.body.appendChild(element);
|
||||
});
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
element.parentNode.removeChild(element);
|
||||
element = null;
|
||||
});
|
||||
|
||||
describe('without padding, margin or border', function() {
|
||||
|
||||
it('calculates correctly', function() {
|
||||
describe('without padding, margin or border', function () {
|
||||
it('calculates correctly', function () {
|
||||
const calcHeight = outerHeight(element);
|
||||
expect(calcHeight).to.be(10);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with padding', function() {
|
||||
it('calculates correctly (both sides)', function() {
|
||||
describe('with padding', function () {
|
||||
it('calculates correctly (both sides)', function () {
|
||||
element.style.padding = '5px';
|
||||
const calcHeight = outerHeight(element);
|
||||
expect(calcHeight).to.be(20);
|
||||
});
|
||||
|
||||
it('calculates correctly (one side)', function() {
|
||||
it('calculates correctly (one side)', function () {
|
||||
element.style.paddingTop = '5px';
|
||||
const calcHeight = outerHeight(element);
|
||||
expect(calcHeight).to.be(15);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with margin', function() {
|
||||
|
||||
it('calculates correctly (both sides)', function() {
|
||||
describe('with margin', function () {
|
||||
it('calculates correctly (both sides)', function () {
|
||||
element.style.margin = '5px';
|
||||
const calcHeight = outerHeight(element);
|
||||
expect(calcHeight).to.be(20);
|
||||
});
|
||||
|
||||
it('calculates correctly (one side)', function() {
|
||||
it('calculates correctly (one side)', function () {
|
||||
element.style.marginTop = '5px';
|
||||
const calcHeight = outerHeight(element);
|
||||
expect(calcHeight).to.be(15);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with border', function() {
|
||||
|
||||
it('calculates correctly (both sides)', function() {
|
||||
describe('with border', function () {
|
||||
it('calculates correctly (both sides)', function () {
|
||||
element.style.border = '5px solid chocolate';
|
||||
const calcHeight = outerHeight(element);
|
||||
expect(calcHeight).to.be(20);
|
||||
});
|
||||
|
||||
it('calculates correctly (one side)', function() {
|
||||
it('calculates correctly (one side)', function () {
|
||||
element.style.border = '5px solid chocolate';
|
||||
element.style.borderBottomWidth = '0';
|
||||
const calcHeight = outerHeight(element);
|
||||
expect(calcHeight).to.be(15);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with padding and margin', function() {
|
||||
|
||||
it('calculates correctly (both sides)', function() {
|
||||
describe('with padding and margin', function () {
|
||||
it('calculates correctly (both sides)', function () {
|
||||
element.style.padding = '5px';
|
||||
element.style.margin = '5px';
|
||||
const calcHeight = outerHeight(element);
|
||||
expect(calcHeight).to.be(30);
|
||||
});
|
||||
|
||||
it('calculates correctly (one side)', function() {
|
||||
it('calculates correctly (one side)', function () {
|
||||
element.style.paddingTop = '5px';
|
||||
element.style.marginTop = '5px';
|
||||
const calcHeight = outerHeight(element);
|
||||
expect(calcHeight).to.be(20);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with padding and border', function() {
|
||||
|
||||
it('calculates correctly (both sides)', function() {
|
||||
describe('with padding and border', function () {
|
||||
it('calculates correctly (both sides)', function () {
|
||||
element.style.padding = '5px';
|
||||
element.style.border = '5px solid chocolate';
|
||||
const calcHeight = outerHeight(element);
|
||||
expect(calcHeight).to.be(30);
|
||||
});
|
||||
|
||||
it('calculates correctly (one side)', function() {
|
||||
it('calculates correctly (one side)', function () {
|
||||
element.style.paddingTop = '5px';
|
||||
element.style.border = '5px solid chocolate';
|
||||
element.style.borderBottomWidth = '0';
|
||||
const calcHeight = outerHeight(element);
|
||||
expect(calcHeight).to.be(20);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with margin and border', function() {
|
||||
|
||||
it('calculates correctly (both sides)', function() {
|
||||
describe('with margin and border', function () {
|
||||
it('calculates correctly (both sides)', function () {
|
||||
element.style.margin = '5px';
|
||||
element.style.border = '5px solid chocolate';
|
||||
const calcHeight = outerHeight(element);
|
||||
expect(calcHeight).to.be(30);
|
||||
});
|
||||
|
||||
it('calculates correctly (one side)', function() {
|
||||
it('calculates correctly (one side)', function () {
|
||||
element.style.marginTop = '5px';
|
||||
element.style.border = '5px solid chocolate';
|
||||
element.style.borderBottomWidth = '0';
|
||||
const calcHeight = outerHeight(element);
|
||||
expect(calcHeight).to.be(20);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with padding, margin and border', function() {
|
||||
|
||||
it('calculates correctly (both sides)', function() {
|
||||
describe('with padding, margin and border', function () {
|
||||
it('calculates correctly (both sides)', function () {
|
||||
element.style.margin = '5px';
|
||||
element.style.padding = '5px';
|
||||
element.style.border = '5px solid chocolate';
|
||||
@@ -331,7 +306,7 @@ describe('ol.dom', function() {
|
||||
expect(calcHeight).to.be(40);
|
||||
});
|
||||
|
||||
it('calculates correctly (one side)', function() {
|
||||
it('calculates correctly (one side)', function () {
|
||||
element.style.marginTop = '5px';
|
||||
element.style.paddingTop = '5px';
|
||||
element.style.border = '5px solid chocolate';
|
||||
@@ -339,13 +314,10 @@ describe('ol.dom', function() {
|
||||
const calcHeight = outerHeight(element);
|
||||
expect(calcHeight).to.be(25);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('replaceChildren()', function() {
|
||||
|
||||
describe('replaceChildren()', function () {
|
||||
function assertChildrenMatch(parent, children) {
|
||||
const actual = parent.childNodes;
|
||||
expect(actual).to.have.length(children.length);
|
||||
@@ -354,26 +326,26 @@ describe('ol.dom', function() {
|
||||
}
|
||||
}
|
||||
|
||||
it('adds new children to an empty parent', function() {
|
||||
it('adds new children to an empty parent', function () {
|
||||
const parent = document.createElement('div');
|
||||
const children = [
|
||||
document.createElement('a'),
|
||||
document.createElement('b'),
|
||||
document.createElement('c')
|
||||
document.createElement('c'),
|
||||
];
|
||||
|
||||
replaceChildren(parent, children);
|
||||
assertChildrenMatch(parent, children);
|
||||
});
|
||||
|
||||
it('removes children', function() {
|
||||
it('removes children', function () {
|
||||
const parent = document.createElement('div');
|
||||
const existingChildren = [
|
||||
document.createElement('a'),
|
||||
document.createElement('b'),
|
||||
document.createElement('c')
|
||||
document.createElement('c'),
|
||||
];
|
||||
existingChildren.forEach(function(child) {
|
||||
existingChildren.forEach(function (child) {
|
||||
parent.appendChild(child);
|
||||
});
|
||||
|
||||
@@ -381,42 +353,42 @@ describe('ol.dom', function() {
|
||||
expect(parent.childNodes).to.have.length(0);
|
||||
});
|
||||
|
||||
it('swaps children', function() {
|
||||
it('swaps children', function () {
|
||||
const parent = document.createElement('div');
|
||||
const existingChildren = [
|
||||
document.createElement('a'),
|
||||
document.createElement('b'),
|
||||
document.createElement('c')
|
||||
document.createElement('c'),
|
||||
];
|
||||
existingChildren.forEach(function(child) {
|
||||
existingChildren.forEach(function (child) {
|
||||
parent.appendChild(child);
|
||||
});
|
||||
|
||||
const newChildren = [
|
||||
document.createElement('d'),
|
||||
document.createElement('e'),
|
||||
document.createElement('f')
|
||||
document.createElement('f'),
|
||||
];
|
||||
|
||||
replaceChildren(parent, newChildren);
|
||||
assertChildrenMatch(parent, newChildren);
|
||||
});
|
||||
|
||||
it('appends children', function() {
|
||||
it('appends children', function () {
|
||||
const parent = document.createElement('div');
|
||||
const existingChildren = [
|
||||
document.createElement('a'),
|
||||
document.createElement('b'),
|
||||
document.createElement('c')
|
||||
document.createElement('c'),
|
||||
];
|
||||
existingChildren.forEach(function(child) {
|
||||
existingChildren.forEach(function (child) {
|
||||
parent.appendChild(child);
|
||||
});
|
||||
|
||||
const newChildren = [
|
||||
document.createElement('d'),
|
||||
document.createElement('e'),
|
||||
document.createElement('f')
|
||||
document.createElement('f'),
|
||||
];
|
||||
|
||||
const allChildren = existingChildren.concat(newChildren);
|
||||
@@ -425,38 +397,35 @@ describe('ol.dom', function() {
|
||||
assertChildrenMatch(parent, allChildren);
|
||||
});
|
||||
|
||||
it('prunes children', function() {
|
||||
it('prunes children', function () {
|
||||
const parent = document.createElement('div');
|
||||
const existingChildren = [
|
||||
document.createElement('a'),
|
||||
document.createElement('b'),
|
||||
document.createElement('c'),
|
||||
document.createElement('d'),
|
||||
document.createElement('e')
|
||||
document.createElement('e'),
|
||||
];
|
||||
existingChildren.forEach(function(child) {
|
||||
existingChildren.forEach(function (child) {
|
||||
parent.appendChild(child);
|
||||
});
|
||||
|
||||
const desiredChildren = [
|
||||
existingChildren[1],
|
||||
existingChildren[3]
|
||||
];
|
||||
const desiredChildren = [existingChildren[1], existingChildren[3]];
|
||||
|
||||
replaceChildren(parent, desiredChildren);
|
||||
assertChildrenMatch(parent, desiredChildren);
|
||||
});
|
||||
|
||||
it('reorders children', function() {
|
||||
it('reorders children', function () {
|
||||
const parent = document.createElement('div');
|
||||
const existingChildren = [
|
||||
document.createElement('a'),
|
||||
document.createElement('b'),
|
||||
document.createElement('c'),
|
||||
document.createElement('d'),
|
||||
document.createElement('e')
|
||||
document.createElement('e'),
|
||||
];
|
||||
existingChildren.forEach(function(child) {
|
||||
existingChildren.forEach(function (child) {
|
||||
parent.appendChild(child);
|
||||
});
|
||||
|
||||
@@ -465,23 +434,23 @@ describe('ol.dom', function() {
|
||||
existingChildren[3],
|
||||
existingChildren[0],
|
||||
existingChildren[4],
|
||||
existingChildren[2]
|
||||
existingChildren[2],
|
||||
];
|
||||
|
||||
replaceChildren(parent, desiredChildren);
|
||||
assertChildrenMatch(parent, desiredChildren);
|
||||
});
|
||||
|
||||
it('reorders, prunes, and appends children', function() {
|
||||
it('reorders, prunes, and appends children', function () {
|
||||
const parent = document.createElement('div');
|
||||
const existingChildren = [
|
||||
document.createElement('a'),
|
||||
document.createElement('b'),
|
||||
document.createElement('c'),
|
||||
document.createElement('d'),
|
||||
document.createElement('e')
|
||||
document.createElement('e'),
|
||||
];
|
||||
existingChildren.forEach(function(child) {
|
||||
existingChildren.forEach(function (child) {
|
||||
parent.appendChild(child);
|
||||
});
|
||||
|
||||
@@ -490,7 +459,7 @@ describe('ol.dom', function() {
|
||||
existingChildren[3],
|
||||
document.createElement('g'),
|
||||
existingChildren[0],
|
||||
existingChildren[2]
|
||||
existingChildren[2],
|
||||
];
|
||||
|
||||
const clone = desiredChildren.slice();
|
||||
@@ -501,7 +470,5 @@ describe('ol.dom', function() {
|
||||
// confirm we haven't modified the input
|
||||
expect(desiredChildren).to.eql(clone);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user