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

@@ -4,7 +4,6 @@
import {assert} from '../asserts.js';
/**
* @typedef {Object} Entry
* @property {string} key_
@@ -13,7 +12,6 @@ import {assert} from '../asserts.js';
* @property {*} value_
*/
/**
* @classdesc
* Implements a Least-Recently-Used cache where the keys do not conflict with
@@ -24,16 +22,15 @@ import {assert} from '../asserts.js';
* @template T
*/
class LRUCache {
/**
* @param {number=} opt_highWaterMark High water mark.
*/
constructor(opt_highWaterMark) {
/**
* @type {number}
*/
this.highWaterMark = opt_highWaterMark !== undefined ? opt_highWaterMark : 2048;
this.highWaterMark =
opt_highWaterMark !== undefined ? opt_highWaterMark : 2048;
/**
* @private
@@ -58,10 +55,8 @@ class LRUCache {
* @type {?Entry}
*/
this.newest_ = null;
}
/**
* @return {boolean} Can expire cache.
*/
@@ -69,7 +64,6 @@ class LRUCache {
return this.getCount() > this.highWaterMark;
}
/**
* FIXME empty description for jsdoc
*/
@@ -80,7 +74,6 @@ class LRUCache {
this.newest_ = null;
}
/**
* @param {string} key Key.
* @return {boolean} Contains key.
@@ -89,7 +82,6 @@ class LRUCache {
return this.entries_.hasOwnProperty(key);
}
/**
* @param {function(T, string, LRUCache<T>): ?} f The function
* to call for every entry from the oldest to the newer. This function takes
@@ -104,7 +96,6 @@ class LRUCache {
}
}
/**
* @param {string} key Key.
* @param {*=} opt_options Options (reserverd for subclasses).
@@ -112,8 +103,7 @@ class LRUCache {
*/
get(key, opt_options) {
const entry = this.entries_[key];
assert(entry !== undefined,
15); // Tried to get a value for a key that does not exist in the cache
assert(entry !== undefined, 15); // Tried to get a value for a key that does not exist in the cache
if (entry === this.newest_) {
return entry.value_;
} else if (entry === this.oldest_) {
@@ -130,7 +120,6 @@ class LRUCache {
return entry.value_;
}
/**
* Remove an entry from the cache.
* @param {string} key The entry key.
@@ -158,7 +147,6 @@ class LRUCache {
return entry.value_;
}
/**
* @return {number} Count.
*/
@@ -166,7 +154,6 @@ class LRUCache {
return this.count_;
}
/**
* @return {Array<string>} Keys.
*/
@@ -180,7 +167,6 @@ class LRUCache {
return keys;
}
/**
* @return {Array<T>} Values.
*/
@@ -194,7 +180,6 @@ class LRUCache {
return values;
}
/**
* @return {T} Last value.
*/
@@ -202,7 +187,6 @@ class LRUCache {
return this.oldest_.value_;
}
/**
* @return {string} Last key.
*/
@@ -210,7 +194,6 @@ class LRUCache {
return this.oldest_.key_;
}
/**
* Get the key of the newest item in the cache. Throws if the cache is empty.
* @return {string} The newest key.
@@ -219,7 +202,6 @@ class LRUCache {
return this.newest_.key_;
}
/**
* @return {T} value Value.
*/
@@ -237,7 +219,6 @@ class LRUCache {
return entry.value_;
}
/**
* @param {string} key Key.
* @param {T} value Value.
@@ -247,19 +228,17 @@ class LRUCache {
this.entries_[key].value_ = value;
}
/**
* @param {string} key Key.
* @param {T} value Value.
*/
set(key, value) {
assert(!(key in this.entries_),
16); // Tried to set a value for a key that is used already
assert(!(key in this.entries_), 16); // Tried to set a value for a key that is used already
const entry = {
key_: key,
newer: null,
older: this.newest_,
value_: value
value_: value,
};
if (!this.newest_) {
this.oldest_ = entry;
@@ -271,7 +250,6 @@ class LRUCache {
++this.count_;
}
/**
* Set a maximum number of entries for the cache.
* @param {number} size Cache size.
@@ -280,7 +258,6 @@ class LRUCache {
setSize(size) {
this.highWaterMark = size;
}
}
export default LRUCache;

View File

@@ -2,7 +2,6 @@
* @module ol/structs/LinkedList
*/
/**
* @typedef {Object} Item
* @property {Item} [prev]
@@ -15,13 +14,11 @@
* Creates an empty linked list structure.
*/
class LinkedList {
/**
* @param {boolean=} opt_circular The last item is connected to the first one,
* and the first item to the last one. Default is true.
*/
constructor(opt_circular) {
/**
* @private
* @type {Item|undefined}
@@ -51,7 +48,6 @@ class LinkedList {
* @type {number}
*/
this.length_ = 0;
}
/**
@@ -60,12 +56,11 @@ class LinkedList {
* @param {?} data Item data.
*/
insertItem(data) {
/** @type {Item} */
const item = {
prev: undefined,
next: undefined,
data: data
data: data,
};
const head = this.head_;
@@ -140,10 +135,10 @@ class LinkedList {
}
/**
* Sets the cursor to the last item, and returns the associated data.
*
* @return {?} Item data.
*/
* Sets the cursor to the last item, and returns the associated data.
*
* @return {?} Item data.
*/
lastItem() {
this.head_ = this.last_;
if (this.head_) {
@@ -259,8 +254,6 @@ class LinkedList {
getLength() {
return this.length_;
}
}
export default LinkedList;

View File

@@ -4,13 +4,11 @@
import {assert} from '../asserts.js';
import {clear} from '../obj.js';
/**
* @type {number}
*/
export const DROP = Infinity;
/**
* @classdesc
* Priority queue.
@@ -24,13 +22,11 @@ export const DROP = Infinity;
* @template T
*/
class PriorityQueue {
/**
* @param {function(T): number} priorityFunction Priority function.
* @param {function(T): string} keyFunction Key function.
*/
constructor(priorityFunction, keyFunction) {
/**
* @type {function(T): number}
* @private
@@ -60,7 +56,6 @@ class PriorityQueue {
* @private
*/
this.queuedElements_ = {};
}
/**
@@ -72,7 +67,6 @@ class PriorityQueue {
clear(this.queuedElements_);
}
/**
* Remove and return the highest-priority element. O(log N).
* @return {T} Element.
@@ -94,15 +88,13 @@ class PriorityQueue {
return element;
}
/**
* Enqueue an element. O(log N).
* @param {T} element Element.
* @return {boolean} The element was added to the queue.
*/
enqueue(element) {
assert(!(this.keyFunction_(element) in this.queuedElements_),
31); // Tried to enqueue an `element` that was already added to the queue
assert(!(this.keyFunction_(element) in this.queuedElements_), 31); // Tried to enqueue an `element` that was already added to the queue
const priority = this.priorityFunction_(element);
if (priority != DROP) {
this.elements_.push(element);
@@ -114,7 +106,6 @@ class PriorityQueue {
return false;
}
/**
* @return {number} Count.
*/
@@ -122,7 +113,6 @@ class PriorityQueue {
return this.elements_.length;
}
/**
* Gets the index of the left child of the node at the given index.
* @param {number} index The index of the node to get the left child for.
@@ -133,7 +123,6 @@ class PriorityQueue {
return index * 2 + 1;
}
/**
* Gets the index of the right child of the node at the given index.
* @param {number} index The index of the node to get the right child for.
@@ -144,7 +133,6 @@ class PriorityQueue {
return index * 2 + 2;
}
/**
* Gets the index of the parent of the node at the given index.
* @param {number} index The index of the node to get the parent for.
@@ -155,7 +143,6 @@ class PriorityQueue {
return (index - 1) >> 1;
}
/**
* Make this a heap. O(N).
* @private
@@ -167,7 +154,6 @@ class PriorityQueue {
}
}
/**
* @return {boolean} Is empty.
*/
@@ -175,7 +161,6 @@ class PriorityQueue {
return this.elements_.length === 0;
}
/**
* @param {string} key Key.
* @return {boolean} Is key queued.
@@ -184,7 +169,6 @@ class PriorityQueue {
return key in this.queuedElements_;
}
/**
* @param {T} element Element.
* @return {boolean} Is queued.
@@ -193,7 +177,6 @@ class PriorityQueue {
return this.isKeyQueued(this.keyFunction_(element));
}
/**
* @param {number} index The index of the node to move down.
* @private
@@ -206,13 +189,14 @@ class PriorityQueue {
const priority = priorities[index];
const startIndex = index;
while (index < (count >> 1)) {
while (index < count >> 1) {
const lIndex = this.getLeftChildIndex_(index);
const rIndex = this.getRightChildIndex_(index);
const smallerChildIndex = rIndex < count &&
priorities[rIndex] < priorities[lIndex] ?
rIndex : lIndex;
const smallerChildIndex =
rIndex < count && priorities[rIndex] < priorities[lIndex]
? rIndex
: lIndex;
elements[index] = elements[smallerChildIndex];
priorities[index] = priorities[smallerChildIndex];
@@ -224,7 +208,6 @@ class PriorityQueue {
this.siftDown_(startIndex, index);
}
/**
* @param {number} startIndex The index of the root.
* @param {number} index The index of the node to move up.
@@ -250,7 +233,6 @@ class PriorityQueue {
priorities[index] = priority;
}
/**
* FIXME empty description for jsdoc
*/
@@ -275,8 +257,6 @@ class PriorityQueue {
priorities.length = index;
this.heapify_();
}
}
export default PriorityQueue;

View File

@@ -1,9 +1,9 @@
/**
* @module ol/structs/RBush
*/
import {getUid} from '../util.js';
import RBush_ from 'rbush/rbush.js';
import {createOrUpdate, equals} from '../extent.js';
import {getUid} from '../util.js';
import {isEmpty} from '../obj.js';
/**
@@ -27,7 +27,6 @@ class RBush {
* @param {number=} opt_maxEntries Max entries.
*/
constructor(opt_maxEntries) {
/**
* @private
*/
@@ -40,7 +39,6 @@ class RBush {
* @type {Object<string, Entry>}
*/
this.items_ = {};
}
/**
@@ -55,14 +53,13 @@ class RBush {
minY: extent[1],
maxX: extent[2],
maxY: extent[3],
value: value
value: value,
};
this.rbush_.insert(item);
this.items_[getUid(value)] = item;
}
/**
* Bulk-insert values into the RBush.
* @param {Array<import("../extent.js").Extent>} extents Extents.
@@ -80,7 +77,7 @@ class RBush {
minY: extent[1],
maxX: extent[2],
maxY: extent[3],
value: value
value: value,
};
items[i] = item;
this.items_[getUid(value)] = item;
@@ -88,7 +85,6 @@ class RBush {
this.rbush_.load(items);
}
/**
* Remove a value from the RBush.
* @param {T} value Value.
@@ -104,7 +100,6 @@ class RBush {
return this.rbush_.remove(item) !== null;
}
/**
* Update the extent of a value in the RBush.
* @param {import("../extent.js").Extent} extent Extent.
@@ -119,19 +114,17 @@ class RBush {
}
}
/**
* Return all values in the RBush.
* @return {Array<T>} All.
*/
getAll() {
const items = this.rbush_.all();
return items.map(function(item) {
return items.map(function (item) {
return item.value;
});
}
/**
* Return all values in the given extent.
* @param {import("../extent.js").Extent} extent Extent.
@@ -143,15 +136,14 @@ class RBush {
minX: extent[0],
minY: extent[1],
maxX: extent[2],
maxY: extent[3]
maxY: extent[3],
};
const items = this.rbush_.search(bbox);
return items.map(function(item) {
return items.map(function (item) {
return item.value;
});
}
/**
* Calls a callback function with each value in the tree.
* If the callback returns a truthy value, this value is returned without
@@ -163,7 +155,6 @@ class RBush {
return this.forEach_(this.getAll(), callback);
}
/**
* Calls a callback function with each value in the provided extent.
* @param {import("../extent.js").Extent} extent Extent.
@@ -174,7 +165,6 @@ class RBush {
return this.forEach_(this.getInExtent(extent), callback);
}
/**
* @param {Array<T>} values Values.
* @param {function(T): *} callback Callback.
@@ -192,7 +182,6 @@ class RBush {
return result;
}
/**
* @return {boolean} Is empty.
*/
@@ -200,7 +189,6 @@ class RBush {
return isEmpty(this.items_);
}
/**
* Remove all values from the RBush.
*/
@@ -209,17 +197,21 @@ class RBush {
this.items_ = {};
}
/**
* @param {import("../extent.js").Extent=} opt_extent Extent.
* @return {import("../extent.js").Extent} Extent.
*/
getExtent(opt_extent) {
const data = this.rbush_.toJSON();
return createOrUpdate(data.minX, data.minY, data.maxX, data.maxY, opt_extent);
return createOrUpdate(
data.minX,
data.minY,
data.maxX,
data.maxY,
opt_extent
);
}
/**
* @param {RBush} rbush R-Tree.
*/
@@ -229,8 +221,6 @@ class RBush {
this.items_[i] = rbush.items_[i];
}
}
}
export default RBush;