Skip to content

Commit c5cf5cc

Browse files
style(pre-commit): auto fixes from pre-commit.com hooks
1 parent dd9b65e commit c5cf5cc

File tree

2 files changed

+74
-70
lines changed

2 files changed

+74
-70
lines changed

docs/_static/searchtools.js

+73-69
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,18 @@ if (typeof Scorer === "undefined") {
4949

5050
// Global search result kind enum, used by themes to style search results.
5151
class SearchResultContext {
52-
static get index() { return "index"; }
53-
static get object() { return "object"; }
54-
static get text() { return "text"; }
55-
static get title() { return "title"; }
52+
static get index() {
53+
return "index";
54+
}
55+
static get object() {
56+
return "object";
57+
}
58+
static get text() {
59+
return "text";
60+
}
61+
static get title() {
62+
return "title";
63+
}
5664
}
5765

5866
const _removeChildren = (element) => {
@@ -62,8 +70,7 @@ const _removeChildren = (element) => {
6270
/**
6371
* See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
6472
*/
65-
const _escapeRegExp = (string) =>
66-
string.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
73+
const _escapeRegExp = (string) => string.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
6774

6875
const _displayItem = (item, searchTerms, highlightTerms) => {
6976
const docBuilder = DOCUMENTATION_OPTIONS.BUILDER;
@@ -84,8 +91,7 @@ const _displayItem = (item, searchTerms, highlightTerms) => {
8491
if (docBuilder === "dirhtml") {
8592
// dirhtml builder
8693
let dirname = docName + "/";
87-
if (dirname.match(/\/index\/$/))
88-
dirname = dirname.substring(0, dirname.length - 6);
94+
if (dirname.match(/\/index\/$/)) dirname = dirname.substring(0, dirname.length - 6);
8995
else if (dirname === "index/") dirname = "";
9096
requestUrl = contentRoot + dirname;
9197
linkUrl = requestUrl;
@@ -99,23 +105,23 @@ const _displayItem = (item, searchTerms, highlightTerms) => {
99105
linkEl.dataset.score = score;
100106
linkEl.innerHTML = title;
101107
if (descr) {
102-
listItem.appendChild(document.createElement("span")).innerHTML =
103-
" (" + descr + ")";
108+
listItem.appendChild(document.createElement("span")).innerHTML = " (" + descr + ")";
104109
// highlight search terms in the description
105-
if (SPHINX_HIGHLIGHT_ENABLED) // set in sphinx_highlight.js
110+
if (SPHINX_HIGHLIGHT_ENABLED)
111+
// set in sphinx_highlight.js
106112
highlightTerms.forEach((term) => _highlightText(listItem, term, "highlighted"));
107-
}
108-
else if (showSearchSummary)
113+
} else if (showSearchSummary)
109114
fetch(requestUrl)
110115
.then((responseData) => responseData.text())
111116
.then((data) => {
112117
if (data)
113-
listItem.appendChild(
114-
Search.makeSearchSummary(data, searchTerms, anchor)
115-
);
118+
listItem.appendChild(Search.makeSearchSummary(data, searchTerms, anchor));
116119
// highlight search terms in the summary
117-
if (SPHINX_HIGHLIGHT_ENABLED) // set in sphinx_highlight.js
118-
highlightTerms.forEach((term) => _highlightText(listItem, term, "highlighted"));
120+
if (SPHINX_HIGHLIGHT_ENABLED)
121+
// set in sphinx_highlight.js
122+
highlightTerms.forEach((term) =>
123+
_highlightText(listItem, term, "highlighted"),
124+
);
119125
});
120126
Search.output.appendChild(listItem);
121127
};
@@ -124,28 +130,23 @@ const _finishSearch = (resultCount) => {
124130
Search.title.innerText = _("Search Results");
125131
if (!resultCount)
126132
Search.status.innerText = Documentation.gettext(
127-
"Your search did not match any documents. Please make sure that all words are spelled correctly and that you've selected enough categories."
133+
"Your search did not match any documents. Please make sure that all words are spelled correctly and that you've selected enough categories.",
128134
);
129135
else
130136
Search.status.innerText = Documentation.ngettext(
131137
"Search finished, found one page matching the search query.",
132138
"Search finished, found ${resultCount} pages matching the search query.",
133139
resultCount,
134-
).replace('${resultCount}', resultCount);
140+
).replace("${resultCount}", resultCount);
135141
};
136-
const _displayNextItem = (
137-
results,
138-
resultCount,
139-
searchTerms,
140-
highlightTerms,
141-
) => {
142+
const _displayNextItem = (results, resultCount, searchTerms, highlightTerms) => {
142143
// results left, load the summary and display it
143144
// this is intended to be dynamic (don't sub resultsCount)
144145
if (results.length) {
145146
_displayItem(results.pop(), searchTerms, highlightTerms);
146147
setTimeout(
147148
() => _displayNextItem(results, resultCount, searchTerms, highlightTerms),
148-
5
149+
5,
149150
);
150151
}
151152
// search finished, update title and status message
@@ -177,9 +178,10 @@ const _orderResultsByScoreThenName = (a, b) => {
177178
* This is the same as ``\W+`` in Python, preserving the surrogate pair area.
178179
*/
179180
if (typeof splitQuery === "undefined") {
180-
var splitQuery = (query) => query
181+
var splitQuery = (query) =>
182+
query
181183
.split(/[^\p{Letter}\p{Number}_\p{Emoji_Presentation}]+/gu)
182-
.filter(term => term) // remove remaining empty strings
184+
.filter((term) => term); // remove remaining empty strings
183185
}
184186

185187
/**
@@ -191,16 +193,18 @@ const Search = {
191193
_pulse_status: -1,
192194

193195
htmlToText: (htmlString, anchor) => {
194-
const htmlElement = new DOMParser().parseFromString(htmlString, 'text/html');
196+
const htmlElement = new DOMParser().parseFromString(htmlString, "text/html");
195197
for (const removalQuery of [".headerlink", "script", "style"]) {
196-
htmlElement.querySelectorAll(removalQuery).forEach((el) => { el.remove() });
198+
htmlElement.querySelectorAll(removalQuery).forEach((el) => {
199+
el.remove();
200+
});
197201
}
198202
if (anchor) {
199203
const anchorContent = htmlElement.querySelector(`[role="main"] ${anchor}`);
200204
if (anchorContent) return anchorContent.textContent;
201205

202206
console.warn(
203-
`Anchored content block not found. Sphinx search tries to obtain it via DOM query '[role=main] ${anchor}'. Check your theme or template.`
207+
`Anchored content block not found. Sphinx search tries to obtain it via DOM query '[role=main] ${anchor}'. Check your theme or template.`,
204208
);
205209
}
206210

@@ -209,16 +213,14 @@ const Search = {
209213
if (docContent) return docContent.textContent;
210214

211215
console.warn(
212-
"Content block not found. Sphinx search tries to obtain it via DOM query '[role=main]'. Check your theme or template."
216+
"Content block not found. Sphinx search tries to obtain it via DOM query '[role=main]'. Check your theme or template.",
213217
);
214218
return "";
215219
},
216220

217221
init: () => {
218222
const query = new URLSearchParams(window.location.search).get("q");
219-
document
220-
.querySelectorAll('input[name="q"]')
221-
.forEach((el) => (el.value = query));
223+
document.querySelectorAll('input[name="q"]').forEach((el) => (el.value = query));
222224
if (query) Search.performSearch(query);
223225
},
224226

@@ -295,11 +297,7 @@ const Search = {
295297

296298
// maybe skip this "word"
297299
// stopwords array is from language_data.js
298-
if (
299-
stopwords.indexOf(queryTermLower) !== -1 ||
300-
queryTerm.match(/^\d+$/)
301-
)
302-
return;
300+
if (stopwords.indexOf(queryTermLower) !== -1 || queryTerm.match(/^\d+$/)) return;
303301

304302
// stem the word
305303
let word = stemmer.stemWord(queryTermLower);
@@ -311,8 +309,9 @@ const Search = {
311309
}
312310
});
313311

314-
if (SPHINX_HIGHLIGHT_ENABLED) { // set in sphinx_highlight.js
315-
localStorage.setItem("sphinx_highlight_terms", [...highlightTerms].join(" "))
312+
if (SPHINX_HIGHLIGHT_ENABLED) {
313+
// set in sphinx_highlight.js
314+
localStorage.setItem("sphinx_highlight_terms", [...highlightTerms].join(" "));
316315
}
317316

318317
// console.debug("SEARCH: searching for:");
@@ -341,10 +340,13 @@ const Search = {
341340

342341
const queryLower = query.toLowerCase().trim();
343342
for (const [title, foundTitles] of Object.entries(allTitles)) {
344-
if (title.toLowerCase().trim().includes(queryLower) && (queryLower.length >= title.length/2)) {
343+
if (
344+
title.toLowerCase().trim().includes(queryLower) &&
345+
queryLower.length >= title.length / 2
346+
) {
345347
for (const [file, id] of foundTitles) {
346-
const score = Math.round(Scorer.title * queryLower.length / title.length);
347-
const boost = titles[file] === title ? 1 : 0; // add a boost for document titles
348+
const score = Math.round((Scorer.title * queryLower.length) / title.length);
349+
const boost = titles[file] === title ? 1 : 0; // add a boost for document titles
348350
normalResults.push([
349351
docNames[file],
350352
titles[file] !== title ? `${titles[file]} > ${title}` : title,
@@ -360,9 +362,9 @@ const Search = {
360362

361363
// search for explicit entries in index directives
362364
for (const [entry, foundEntries] of Object.entries(indexEntries)) {
363-
if (entry.includes(queryLower) && (queryLower.length >= entry.length/2)) {
365+
if (entry.includes(queryLower) && queryLower.length >= entry.length / 2) {
364366
for (const [file, id, isMain] of foundEntries) {
365-
const score = Math.round(100 * queryLower.length / entry.length);
367+
const score = Math.round((100 * queryLower.length) / entry.length);
366368
const result = [
367369
docNames[file],
368370
titles[file],
@@ -383,7 +385,7 @@ const Search = {
383385

384386
// lookup as object
385387
objectTerms.forEach((term) =>
386-
normalResults.push(...Search.performObjectSearch(term, objectTerms))
388+
normalResults.push(...Search.performObjectSearch(term, objectTerms)),
387389
);
388390

389391
// lookup as search terms in fulltext
@@ -408,7 +410,11 @@ const Search = {
408410
// note the reversing of results, so that in the case of duplicates, the highest-scoring entry is kept
409411
let seen = new Set();
410412
results = results.reverse().reduce((acc, result) => {
411-
let resultStr = result.slice(0, 4).concat([result[5]]).map(v => String(v)).join(',');
413+
let resultStr = result
414+
.slice(0, 4)
415+
.concat([result[5]])
416+
.map((v) => String(v))
417+
.join(",");
412418
if (!seen.has(resultStr)) {
413419
acc.push(result);
414420
seen.add(resultStr);
@@ -420,8 +426,15 @@ const Search = {
420426
},
421427

422428
query: (query) => {
423-
const [searchQuery, searchTerms, excludedTerms, highlightTerms, objectTerms] = Search._parseQuery(query);
424-
const results = Search._performSearch(searchQuery, searchTerms, excludedTerms, highlightTerms, objectTerms);
429+
const [searchQuery, searchTerms, excludedTerms, highlightTerms, objectTerms] =
430+
Search._parseQuery(query);
431+
const results = Search._performSearch(
432+
searchQuery,
433+
searchTerms,
434+
excludedTerms,
435+
highlightTerms,
436+
objectTerms,
437+
);
425438

426439
// for debugging
427440
//Search.lastresults = results.slice(); // a copy
@@ -444,7 +457,7 @@ const Search = {
444457
const results = [];
445458

446459
const objectSearchCallback = (prefix, match) => {
447-
const name = match[4]
460+
const name = match[4];
448461
const fullname = (prefix ? prefix + "." : "") + name;
449462
const fullnameLower = fullname.toLowerCase();
450463
if (fullnameLower.indexOf(object) < 0) return;
@@ -456,8 +469,7 @@ const Search = {
456469
// "last name" (i.e. last dotted part)
457470
if (fullnameLower === object || parts.slice(-1)[0] === object)
458471
score += Scorer.objNameMatch;
459-
else if (parts.slice(-1)[0].indexOf(object) > -1)
460-
score += Scorer.objPartialMatch; // matches in last name
472+
else if (parts.slice(-1)[0].indexOf(object) > -1) score += Scorer.objPartialMatch; // matches in last name
461473

462474
const objName = objNames[match[1]][2];
463475
const title = titles[match[0]];
@@ -468,9 +480,7 @@ const Search = {
468480
otherTerms.delete(object);
469481
if (otherTerms.size > 0) {
470482
const haystack = `${prefix} ${name} ${objName} ${title}`.toLowerCase();
471-
if (
472-
[...otherTerms].some((otherTerm) => haystack.indexOf(otherTerm) < 0)
473-
)
483+
if ([...otherTerms].some((otherTerm) => haystack.indexOf(otherTerm) < 0))
474484
return;
475485
}
476486

@@ -481,8 +491,7 @@ const Search = {
481491
const descr = objName + _(", in ") + title;
482492

483493
// add custom score for some objects according to scorer
484-
if (Scorer.objPrio.hasOwnProperty(match[2]))
485-
score += Scorer.objPrio[match[2]];
494+
if (Scorer.objPrio.hasOwnProperty(match[2])) score += Scorer.objPrio[match[2]];
486495
else score += Scorer.objPrioDefault;
487496

488497
results.push([
@@ -496,9 +505,7 @@ const Search = {
496505
]);
497506
};
498507
Object.keys(objects).forEach((prefix) =>
499-
objects[prefix].forEach((array) =>
500-
objectSearchCallback(prefix, array)
501-
)
508+
objects[prefix].forEach((array) => objectSearchCallback(prefix, array)),
502509
);
503510
return results;
504511
},
@@ -573,12 +580,9 @@ const Search = {
573580

574581
// as search terms with length < 3 are discarded
575582
const filteredTermCount = [...searchTerms].filter(
576-
(term) => term.length > 2
583+
(term) => term.length > 2,
577584
).length;
578-
if (
579-
wordList.length !== searchTerms.size &&
580-
wordList.length !== filteredTermCount
581-
)
585+
if (wordList.length !== searchTerms.size && wordList.length !== filteredTermCount)
582586
continue;
583587

584588
// ensure that none of the excluded terms is in the search result
@@ -588,7 +592,7 @@ const Search = {
588592
terms[term] === file ||
589593
titleTerms[term] === file ||
590594
(terms[term] || []).includes(file) ||
591-
(titleTerms[term] || []).includes(file)
595+
(titleTerms[term] || []).includes(file),
592596
)
593597
)
594598
break;

requirements/docs.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ sphinx-copybutton==0.5.2
77
furo==2024.8.6
88
sphinx-autodoc-typehints==2.2.3
99
sphinx-intl==2.2.0
10-
typing_extensions==4.12.2
10+
typing_extensions==4.12.2

0 commit comments

Comments
 (0)