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,8 +1,7 @@
import {drawTextOnPath} from '../../../../../src/ol/geom/flat/textpath.js';
import {lineStringLength} from '../../../../../src/ol/geom/flat/length.js';
describe('ol.geom.flat.drawTextOnPath', function() {
describe('ol.geom.flat.drawTextOnPath', function () {
const horizontal = [0, 0, 100, 0];
const vertical = [0, 0, 0, 100];
const diagonal = [0, 0, 100, 100];
@@ -14,103 +13,234 @@ describe('ol.geom.flat.drawTextOnPath', function() {
return 10 * text.length;
}
it('center-aligns text on a horizontal line', function() {
it('center-aligns text on a horizontal line', function () {
const startM = 50 - 15;
const instructions = drawTextOnPath(
horizontal, 0, horizontal.length, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
horizontal,
0,
horizontal.length,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions).to.eql([[40, 0, 5, 0, 'foo']]);
});
it('left-aligns text on a horizontal line', function() {
it('left-aligns text on a horizontal line', function () {
const instructions = drawTextOnPath(
horizontal, 0, horizontal.length, 2, 'foo', 0, Infinity, 1, measureAndCacheTextWidth, '', {});
horizontal,
0,
horizontal.length,
2,
'foo',
0,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions).to.eql([[5, 0, 5, 0, 'foo']]);
});
it('right-aligns text on a horizontal line', function() {
it('right-aligns text on a horizontal line', function () {
const startM = 100 - 30;
const instructions = drawTextOnPath(
horizontal, 0, horizontal.length, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
horizontal,
0,
horizontal.length,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions).to.eql([[75, 0, 5, 0, 'foo']]);
});
it('draws text on a vertical line', function() {
it('draws text on a vertical line', function () {
const startM = 50 - 15;
const instructions = drawTextOnPath(
vertical, 0, vertical.length, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
const a = 90 * Math.PI / 180;
vertical,
0,
vertical.length,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
const a = (90 * Math.PI) / 180;
expect(instructions).to.eql([[0, 40, 5, a, 'foo']]);
});
it('draws text on a diagonal line', function() {
it('draws text on a diagonal line', function () {
const startM = Math.sqrt(2) * 50 - 15;
const instructions = drawTextOnPath(
diagonal, 0, diagonal.length, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
expect(instructions[0][3]).to.be(45 * Math.PI / 180);
diagonal,
0,
diagonal.length,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions[0][3]).to.be((45 * Math.PI) / 180);
expect(instructions.length).to.be(1);
});
it('draws reverse text on a diagonal line', function() {
it('draws reverse text on a diagonal line', function () {
const startM = Math.sqrt(2) * 50 - 15;
const instructions = drawTextOnPath(
reverse, 0, reverse.length, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
expect(instructions[0][3]).to.be(-45 * Math.PI / 180);
reverse,
0,
reverse.length,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions[0][3]).to.be((-45 * Math.PI) / 180);
expect(instructions.length).to.be(1);
});
it('renders long text with extrapolation', function() {
it('renders long text with extrapolation', function () {
const startM = 50 - 75;
const instructions = drawTextOnPath(
horizontal, 0, horizontal.length, 2, 'foo-foo-foo-foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
horizontal,
0,
horizontal.length,
2,
'foo-foo-foo-foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions[0]).to.eql([-20, 0, 5, 0, 'foo-foo-foo-foo']);
expect(instructions.length).to.be(1);
});
it('renders angled text', function() {
it('renders angled text', function () {
const length = lineStringLength(angled, 0, angled.length, 2);
const startM = length / 2 - 15;
const instructions = drawTextOnPath(
angled, 0, angled.length, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
expect(instructions[0][3]).to.eql(45 * Math.PI / 180);
angled,
0,
angled.length,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions[0][3]).to.eql((45 * Math.PI) / 180);
expect(instructions[0][4]).to.be('f');
expect(instructions[1][3]).to.eql(45 * Math.PI / 180);
expect(instructions[1][3]).to.eql((45 * Math.PI) / 180);
expect(instructions[1][4]).to.be('o');
expect(instructions[2][3]).to.eql(-45 * Math.PI / 180);
expect(instructions[2][3]).to.eql((-45 * Math.PI) / 180);
expect(instructions[2][4]).to.be('o');
});
it('respects maxAngle', function() {
it('respects maxAngle', function () {
const length = lineStringLength(angled, 0, angled.length, 2);
const startM = length / 2 - 15;
const instructions = drawTextOnPath(
angled, 0, angled.length, 2, 'foo', startM, Math.PI / 4, 1, measureAndCacheTextWidth, '', {});
angled,
0,
angled.length,
2,
'foo',
startM,
Math.PI / 4,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions).to.be(null);
});
it('uses the smallest angle for maxAngleDelta', function() {
it('uses the smallest angle for maxAngleDelta', function () {
const length = lineStringLength(reverseangled, 0, reverseangled.length, 2);
const startM = length / 2 - 15;
const instructions = drawTextOnPath(
reverseangled, 0, reverseangled.length, 2, 'foo', startM, Math.PI, 1, measureAndCacheTextWidth, '', {});
reverseangled,
0,
reverseangled.length,
2,
'foo',
startM,
Math.PI,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions).to.not.be(undefined);
});
it('respects the offset option', function() {
it('respects the offset option', function () {
const length = lineStringLength(angled, 2, angled.length, 2);
const startM = length / 2 - 15;
const instructions = drawTextOnPath(
angled, 2, angled.length, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
expect(instructions[0][3]).to.be(-45 * Math.PI / 180);
angled,
2,
angled.length,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions[0][3]).to.be((-45 * Math.PI) / 180);
expect(instructions.length).to.be(1);
});
it('respects the end option', function() {
it('respects the end option', function () {
const length = lineStringLength(angled, 0, 4, 2);
const startM = length / 2 - 15;
const instructions = drawTextOnPath(
angled, 0, 4, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
expect(instructions[0][3]).to.be(45 * Math.PI / 180);
angled,
0,
4,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions[0][3]).to.be((45 * Math.PI) / 180);
expect(instructions.length).to.be(1);
});
});