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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user