Skip to content

Commit a01caf5

Browse files
authored
Chore/formatting setup (#735)
* chore: add eslint, prettier and lint staged configs * chore: run eslint:fix * chore: run prettier
1 parent 9b9926e commit a01caf5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+28860
-24490
lines changed

.eslintignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.json
2+
*.html
3+
*.less
4+
*.css
5+
package.json
6+
docusaurus.config.js
7+
public/
8+
src/vendor/

.eslintrc.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module.exports = {
2+
parserOptions: {
3+
ecmaVersion: 2020,
4+
sourceType: 'module',
5+
},
6+
extends: ['eslint:recommended', 'prettier'],
7+
root: true,
8+
env: {
9+
node: true,
10+
jquery: true,
11+
es2017: true,
12+
browser: true,
13+
webextensions: true,
14+
},
15+
rules: {
16+
// TODO: currently a lot of these issues are marked as
17+
// warnings because they are in the codebase already
18+
// and I don't want to fix them all at once.
19+
// Eventually, they should be fixed and the rules
20+
// should be set to 'error' (default in preset).
21+
'no-var': 'warn',
22+
'no-unused-vars': 'warn',
23+
'no-undef': 'warn',
24+
'no-redeclare': 'warn',
25+
'no-prototype-builtins': 'warn',
26+
'no-empty': 'warn',
27+
'no-inner-declarations': 'warn',
28+
'no-fallthrough': 'warn',
29+
'no-useless-escape': 'warn',
30+
'no-constant-condition': 'warn',
31+
'no-unreachable': 'warn',
32+
'no-duplicate-case': 'warn',
33+
'no-dupe-keys': 'warn',
34+
'no-irregular-whitespace': 'warn',
35+
'no-case-declarations': 'warn',
36+
'prefer-template': 'warn',
37+
'comma-dangle': ['warn', 'always-multiline'],
38+
semi: ['error', 'always'],
39+
},
40+
};

.lintstagedrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"**/*.{tsx,js}": [
3+
"prettier --write --ignore-unknown",
4+
"eslint --fix --ext .tsx,.js"
5+
],
6+
"**/*.{html,md,mdx,less,css,json}": ["prettier --write --ignore-unknown"]
7+
}

.prettierignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# node.js npm related
2+
3+
node_modules/
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Configurator Build process
9+
cache/
10+
apps/
11+
dist/
12+
public/
13+
src/vendor/
14+
dist_cordova/
15+
debug/
16+
release/
17+
testresults/
18+
.eslintcache
19+
cordova/bundle.keystore
20+
21+
# OSX
22+
.DS_store
23+
24+
# artefacts for Visual Studio Code
25+
/.vscode/
26+
27+
# NetBeans
28+
nbproject/
29+
30+
# IntelliJ
31+
.idea
32+
33+
# Eclipse
34+
.project
35+
.settings/
36+
test-results-junit/

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
"scripts": {
1010
"start": "vite",
1111
"build": "vite build",
12-
"preview": "vite preview"
12+
"preview": "vite preview",
13+
"lint": "eslint src",
14+
"lint:fix": "eslint src --fix",
15+
"format": "prettier --write src"
1316
},
1417
"repository": {
1518
"type": "git",
@@ -20,12 +23,15 @@
2023
"dependencies": {
2124
"Leaflet.MultiOptionsPolyline": "hgoebl/Leaflet.MultiOptionsPolyline",
2225
"bootstrap": "~3.4.1",
26+
"eslint": "^8.24.0",
27+
"eslint-config-prettier": "^8.5.0",
2328
"html2canvas": "^1.0.0-rc.5",
2429
"jquery": "^3.7.1",
2530
"jquery-ui": "^1.13.2",
2631
"leaflet": "^1.9.3",
2732
"leaflet-marker-rotation": "^0.4.0",
2833
"lodash": "^4.17.21",
34+
"prettier": "^2.8.1",
2935
"throttle-debounce": "^5.0.0",
3036
"vite": "^5.2.6",
3137
"vite-plugin-pwa": "^0.19.7"

src/cache.js

Lines changed: 78 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,88 @@
11
/**
22
* A FIFO cache to hold key-pair mappings. Its capacity will be at least the initialCapacity
3-
* supplied on creation, which you can increase by increasing the "capacity" property.
4-
*
3+
* supplied on creation, which you can increase by increasing the "capacity" property.
4+
*
55
* One extra element beyond the set capacity will be stored which can be fetched by calling "recycle()".
6-
* This allows the oldest value to be removed in order to be reused, instead of leaving it to be collected
6+
* This allows the oldest value to be removed in order to be reused, instead of leaving it to be collected
77
* by the garbage collector.
8-
*
8+
*
99
* Element age is determined by the time it was added or last get()'d from the cache.
1010
*/
1111
export function FIFOCache(initialCapacity) {
12-
//Private:
13-
var
14-
queue = [],
15-
items = {};
12+
//Private:
13+
let queue = [],
14+
items = {};
1615

17-
function removeFromQueue(key) {
18-
for (var i = 0; i < queue.length; i++) {
19-
if (queue[i] == key) {
20-
//Assume there's only one copy to remove:
21-
for (var j = i; j < queue.length - 1; j++) {
22-
queue[j] = queue[j + 1];
23-
}
24-
25-
queue.length--;
26-
break;
27-
}
16+
function removeFromQueue(key) {
17+
for (let i = 0; i < queue.length; i++) {
18+
if (queue[i] == key) {
19+
//Assume there's only one copy to remove:
20+
for (let j = i; j < queue.length - 1; j++) {
21+
queue[j] = queue[j + 1];
2822
}
23+
24+
queue.length--;
25+
break;
26+
}
2927
}
30-
31-
//Public:
32-
this.capacity = initialCapacity;
33-
34-
/**
35-
* Remove and return the oldest value from the cache to be reused, or null if the cache wasn't full.
36-
*/
37-
this.recycle = function() {
38-
if (queue.length > this.capacity) {
39-
var
40-
key = queue.shift(),
41-
result = items[key];
42-
43-
delete items[key];
44-
45-
return result;
46-
}
47-
48-
return null;
49-
};
50-
51-
/**
52-
* Add a mapping for the given key to the cache. If an existing value with that key was
53-
* present, it will be overwritten.
54-
*/
55-
this.add = function(key, value) {
56-
// Was this already cached? Bump it back up to the end of the queue
57-
if (items[key] !== undefined)
58-
removeFromQueue(key);
59-
60-
queue.push(key);
61-
62-
items[key] = value;
63-
64-
while (queue.length > this.capacity + 1) {
65-
delete items[queue.shift()];
66-
}
67-
};
68-
69-
/**
70-
* Return the value in the cache that corresponds to the given key, or undefined if it has
71-
* expired or had never been stored.
72-
*/
73-
this.get = function(key) {
74-
var item = items[key];
75-
76-
if (item) {
77-
removeFromQueue(key);
78-
queue.push(key);
79-
}
80-
81-
return item;
82-
};
83-
84-
/**
85-
* Erase the entire content of the cache
86-
*/
87-
this.clear = function() {
88-
queue = [];
89-
items = {};
90-
};
91-
}
28+
}
29+
30+
//Public:
31+
this.capacity = initialCapacity;
32+
33+
/**
34+
* Remove and return the oldest value from the cache to be reused, or null if the cache wasn't full.
35+
*/
36+
this.recycle = function () {
37+
if (queue.length > this.capacity) {
38+
let key = queue.shift(),
39+
result = items[key];
40+
41+
delete items[key];
42+
43+
return result;
44+
}
45+
46+
return null;
47+
};
48+
49+
/**
50+
* Add a mapping for the given key to the cache. If an existing value with that key was
51+
* present, it will be overwritten.
52+
*/
53+
this.add = function (key, value) {
54+
// Was this already cached? Bump it back up to the end of the queue
55+
if (items[key] !== undefined) removeFromQueue(key);
56+
57+
queue.push(key);
58+
59+
items[key] = value;
60+
61+
while (queue.length > this.capacity + 1) {
62+
delete items[queue.shift()];
63+
}
64+
};
65+
66+
/**
67+
* Return the value in the cache that corresponds to the given key, or undefined if it has
68+
* expired or had never been stored.
69+
*/
70+
this.get = function (key) {
71+
let item = items[key];
72+
73+
if (item) {
74+
removeFromQueue(key);
75+
queue.push(key);
76+
}
77+
78+
return item;
79+
};
80+
81+
/**
82+
* Erase the entire content of the cache
83+
*/
84+
this.clear = function () {
85+
queue = [];
86+
items = {};
87+
};
88+
}

0 commit comments

Comments
 (0)