summaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2021-11-22 09:19:01 +0100
committerGitHub <noreply@github.com>2021-11-22 16:19:01 +0800
commita159c3175f5f60a9de00f4d3c73787ffa6c63ddd (patch)
treedb212e3f9d20eb26bba12774ff3d8fa0bac71cbc /docs
parent7743f13bed7dc5958c19603ccadd095db24c6b80 (diff)
downloadgitea-a159c3175f5f60a9de00f4d3c73787ffa6c63ddd.tar.gz
gitea-a159c3175f5f60a9de00f4d3c73787ffa6c63ddd.zip
Add new JS linter rules (#17699)
* Add new JS linter rules Adds a few useful rules from eslint-plugin-github. Notable changes: - Forbid dataset usage, its camel-casing behaviour makes it hard to grep for attributes. - Forbid .then() and .catch(), we should generally prefer await for new code. For rare cases where they are useful, a eslint-disable-line directive can be set. - Add docs js to linting * also enable github/array-foreach * small tweak Co-authored-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'docs')
-rw-r--r--docs/assets/js/search.js26
1 files changed, 13 insertions, 13 deletions
diff --git a/docs/assets/js/search.js b/docs/assets/js/search.js
index a4dea55e0e..315a5ebd91 100644
--- a/docs/assets/js/search.js
+++ b/docs/assets/js/search.js
@@ -15,7 +15,7 @@ const fuseOptions = {
shouldSort: true,
includeMatches: true,
matchAllTokens: true,
- threshold: 0.0, // for parsing diacritics
+ threshold: 0, // for parsing diacritics
tokenize: true,
location: 0,
distance: 100,
@@ -52,7 +52,7 @@ function doSearch() {
executeSearch(searchQuery);
} else {
const para = document.createElement('P');
- para.innerText = 'Please enter a word or phrase above';
+ para.textContent = 'Please enter a word or phrase above';
document.getElementById('search-results').appendChild(para);
}
}
@@ -60,17 +60,17 @@ function doSearch() {
function getJSON(url, fn) {
const request = new XMLHttpRequest();
request.open('GET', url, true);
- request.onload = function () {
+ request.addEventListener('load', () => {
if (request.status >= 200 && request.status < 400) {
const data = JSON.parse(request.responseText);
fn(data);
} else {
console.error(`Target reached on ${url} with error ${request.status}`);
}
- };
- request.onerror = function () {
+ });
+ request.addEventListener('error', () => {
console.error(`Connection error ${request.status}`);
- };
+ });
request.send();
}
@@ -84,20 +84,20 @@ function executeSearch(searchQuery) {
populateResults(result);
} else {
const para = document.createElement('P');
- para.innerText = 'No matches found';
+ para.textContent = 'No matches found';
document.getElementById('search-results').appendChild(para);
}
});
}
function populateResults(result) {
- result.forEach((value, key) => {
+ for (const [key, value] of result.entries()) {
const content = value.item.contents;
let snippet = '';
const snippetHighlights = [];
if (fuseOptions.tokenize) {
snippetHighlights.push(searchQuery);
- value.matches.forEach((mvalue) => {
+ for (const mvalue of value.matches) {
if (mvalue.key === 'tags' || mvalue.key === 'categories') {
snippetHighlights.push(mvalue.value);
} else if (mvalue.key === 'contents') {
@@ -111,7 +111,7 @@ function populateResults(result) {
snippetHighlights.push(mvalue.value.substring(mvalue.indices[0][0], mvalue.indices[0][1] - mvalue.indices[0][0] + 1));
}
}
- });
+ }
}
if (snippet.length < 1) {
@@ -130,10 +130,10 @@ function populateResults(result) {
});
document.getElementById('search-results').appendChild(htmlToElement(output));
- snippetHighlights.forEach((snipvalue) => {
+ for (const snipvalue of snippetHighlights) {
new Mark(document.getElementById(`summary-${key}`)).mark(snipvalue);
- });
- });
+ }
+ }
}
function render(templateString, data) {