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
+35 -34
View File
@@ -1,10 +1,9 @@
/**
* @module ol/coordinate
*/
import {getWidth} from './extent.js';
import {modulo} from './math.js';
import {padNumber} from './string.js';
import {getWidth} from './extent.js';
/**
* An array of numbers representing an xy coordinate. Example: `[16, 48]`.
@@ -12,7 +11,6 @@ import {getWidth} from './extent.js';
* @api
*/
/**
* A function that takes a {@link module:ol/coordinate~Coordinate} and
* transforms it into a `{string}`.
@@ -21,7 +19,6 @@ import {getWidth} from './extent.js';
* @api
*/
/**
* Add `delta` to `coordinate`. `coordinate` is modified in place and returned
* by the function.
@@ -46,7 +43,6 @@ export function add(coordinate, delta) {
return coordinate;
}
/**
* Calculates the point closest to the passed coordinate on the passed circle.
*
@@ -69,13 +65,12 @@ export function closestOnCircle(coordinate, circle) {
}
const d = Math.sqrt(dx * dx + dy * dy);
const x = x0 + r * dx / d;
const y = y0 + r * dy / d;
const x = x0 + (r * dx) / d;
const y = y0 + (r * dy) / d;
return [x, y];
}
/**
* Calculates the point closest to the passed coordinate on the passed segment.
* This is the foot of the perpendicular of the coordinate to the segment when
@@ -99,8 +94,10 @@ export function closestOnSegment(coordinate, segment) {
const y2 = end[1];
const dx = x2 - x1;
const dy = y2 - y1;
const along = (dx === 0 && dy === 0) ? 0 :
((dx * (x0 - x1)) + (dy * (y0 - y1))) / ((dx * dx + dy * dy) || 0);
const along =
dx === 0 && dy === 0
? 0
: (dx * (x0 - x1) + dy * (y0 - y1)) / (dx * dx + dy * dy || 0);
let x, y;
if (along <= 0) {
x = x1;
@@ -115,7 +112,6 @@ export function closestOnSegment(coordinate, segment) {
return [x, y];
}
/**
* Returns a {@link module:ol/coordinate~CoordinateFormat} function that can be
* used to format
@@ -150,13 +146,12 @@ export function createStringXY(opt_fractionDigits) {
* @param {Coordinate} coordinate Coordinate.
* @return {string} String XY.
*/
function(coordinate) {
function (coordinate) {
return toStringXY(coordinate, opt_fractionDigits);
}
);
}
/**
* @param {string} hemispheres Hemispheres.
* @param {number} degrees Degrees.
@@ -172,7 +167,7 @@ export function degreesToStringHDMS(hemispheres, degrees, opt_fractionDigits) {
let deg = Math.floor(x / 3600);
let min = Math.floor((x - deg * 3600) / 60);
let sec = x - (deg * 3600) - (min * 60);
let sec = x - deg * 3600 - min * 60;
sec = Math.ceil(sec * precision) / precision;
if (sec >= 60) {
@@ -185,12 +180,19 @@ export function degreesToStringHDMS(hemispheres, degrees, opt_fractionDigits) {
deg += 1;
}
return deg + '\u00b0 ' + padNumber(min, 2) + '\u2032 ' +
padNumber(sec, 2, dflPrecision) + '\u2033' +
(normalizedDegrees == 0 ? '' : ' ' + hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0));
return (
deg +
'\u00b0 ' +
padNumber(min, 2) +
'\u2032 ' +
padNumber(sec, 2, dflPrecision) +
'\u2033' +
(normalizedDegrees == 0
? ''
: ' ' + hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0))
);
}
/**
* Transforms the given {@link module:ol/coordinate~Coordinate} to a string
* using the given string template. The strings `{x}` and `{y}` in the template
@@ -232,7 +234,6 @@ export function format(coordinate, template, opt_fractionDigits) {
}
}
/**
* @param {Coordinate} coordinate1 First coordinate.
* @param {Coordinate} coordinate2 Second coordinate.
@@ -249,7 +250,6 @@ export function equals(coordinate1, coordinate2) {
return equals;
}
/**
* Rotate `coordinate` by `angle`. `coordinate` is modified in place and
* returned by the function.
@@ -278,7 +278,6 @@ export function rotate(coordinate, angle) {
return coordinate;
}
/**
* Scale `coordinate` by `scale`. `coordinate` is modified in place and returned
* by the function.
@@ -302,7 +301,6 @@ export function scale(coordinate, scale) {
return coordinate;
}
/**
* @param {Coordinate} coord1 First coordinate.
* @param {Coordinate} coord2 Second coordinate.
@@ -314,7 +312,6 @@ export function squaredDistance(coord1, coord2) {
return dx * dx + dy * dy;
}
/**
* @param {Coordinate} coord1 First coordinate.
* @param {Coordinate} coord2 Second coordinate.
@@ -324,7 +321,6 @@ export function distance(coord1, coord2) {
return Math.sqrt(squaredDistance(coord1, coord2));
}
/**
* Calculate the squared distance from a coordinate to a line segment.
*
@@ -334,11 +330,9 @@ export function distance(coord1, coord2) {
* @return {number} Squared distance from the point to the line segment.
*/
export function squaredDistanceToSegment(coordinate, segment) {
return squaredDistance(coordinate,
closestOnSegment(coordinate, segment));
return squaredDistance(coordinate, closestOnSegment(coordinate, segment));
}
/**
* Format a geographic coordinate with the hemisphere, degrees, minutes, and
* seconds.
@@ -367,14 +361,16 @@ export function squaredDistanceToSegment(coordinate, segment) {
*/
export function toStringHDMS(coordinate, opt_fractionDigits) {
if (coordinate) {
return degreesToStringHDMS('NS', coordinate[1], opt_fractionDigits) + ' ' +
degreesToStringHDMS('EW', coordinate[0], opt_fractionDigits);
return (
degreesToStringHDMS('NS', coordinate[1], opt_fractionDigits) +
' ' +
degreesToStringHDMS('EW', coordinate[0], opt_fractionDigits)
);
} else {
return '';
}
}
/**
* Format a coordinate as a comma delimited string.
*
@@ -404,7 +400,6 @@ export function toStringXY(coordinate, opt_fractionDigits) {
return format(coordinate, '{x}, {y}', opt_fractionDigits);
}
/**
* Modifies the provided coordinate in-place to be within the real world
* extent. The lower projection extent boundary is inclusive, the upper one
@@ -416,10 +411,16 @@ export function toStringXY(coordinate, opt_fractionDigits) {
*/
export function wrapX(coordinate, projection) {
const projectionExtent = projection.getExtent();
if (projection.canWrapX() && (coordinate[0] < projectionExtent[0] || coordinate[0] >= projectionExtent[2])) {
if (
projection.canWrapX() &&
(coordinate[0] < projectionExtent[0] ||
coordinate[0] >= projectionExtent[2])
) {
const worldWidth = getWidth(projectionExtent);
const worldsAway = Math.floor((coordinate[0] - projectionExtent[0]) / worldWidth);
coordinate[0] -= (worldsAway * worldWidth);
const worldsAway = Math.floor(
(coordinate[0] - projectionExtent[0]) / worldWidth
);
coordinate[0] -= worldsAway * worldWidth;
}
return coordinate;
}