Skip to content

Commit 9e1f023

Browse files
committed
chore(doc_cli): Format JS and CSS with Prettier
1 parent 5a268fb commit 9e1f023

6 files changed

Lines changed: 164 additions & 82 deletions

File tree

.github/workflows/test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ jobs:
3737
- name: Run style check
3838
run: pre-commit run --all --hook-stage manual
3939

40+
- name: Install Prettier
41+
run: npm i -g prettier
42+
- name: Check formatting with Prettier
43+
run: prettier -c .
44+
4045
clippy:
4146
name: Clippy Lint Check
4247
runs-on: ubuntu-latest

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ repos:
1616
language: system
1717
files: ^tools/schema_json_gen/src/main\.rs$
1818
pass_filenames: false
19+
- id: prettier
20+
name: prettier
21+
entry: prettier
22+
args: [--write, --ignore-unknown]
23+
language: node
24+
types: [text]
25+
additional_dependencies:
26+
- prettier@3.9.6
1927
- repo: https://github.com/pre-commit/pre-commit-hooks
2028
rev: v6.0.0
2129
hooks:

.prettierignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Only format in /crates/emmylua_doc_cli/template.
2+
/*
3+
!/crates
4+
/crates/*
5+
!/crates/emmylua_doc_cli
6+
/crates/emmylua_doc_cli/*
7+
!/crates/emmylua_doc_cli/template
8+
9+
*.md
10+
*.html
11+
12+
# Re-include .prettierrc
13+
!.prettierrc

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"printWidth": 120
4+
}

crates/emmylua_doc_cli/template/static/main.js

Lines changed: 57 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@
1717

1818
function escapeHtml(s) {
1919
return String(s).replace(/[&<>"']/g, function (c) {
20-
return { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c];
20+
return {
21+
'&': '&amp;',
22+
'<': '&lt;',
23+
'>': '&gt;',
24+
'"': '&quot;',
25+
"'": '&#39;',
26+
}[c];
2127
});
2228
}
2329

@@ -51,7 +57,9 @@
5157
document.documentElement.setAttribute('data-theme', next);
5258
try {
5359
localStorage.setItem(THEME_KEY, next);
54-
} catch (e) { /* private mode etc. */ }
60+
} catch (e) {
61+
/* private mode etc. */
62+
}
5563
syncButton();
5664
});
5765
}
@@ -134,7 +142,9 @@
134142
var text = pre.textContent || '';
135143
function done() {
136144
btn.classList.add('copied');
137-
setTimeout(function () { btn.classList.remove('copied'); }, 1500);
145+
setTimeout(function () {
146+
btn.classList.remove('copied');
147+
}, 1500);
138148
}
139149
if (navigator.clipboard && navigator.clipboard.writeText) {
140150
navigator.clipboard.writeText(text).then(done, function () {
@@ -157,7 +167,9 @@
157167
ta.select();
158168
try {
159169
document.execCommand('copy');
160-
} catch (e) { /* best effort */ }
170+
} catch (e) {
171+
/* best effort */
172+
}
161173
document.body.removeChild(ta);
162174
}
163175
}
@@ -208,11 +220,19 @@
208220
resultsPanel.innerHTML = matches
209221
.map(function (entry, i) {
210222
var href = rootPrefix() + entry.href;
211-
return '<a class="search-result' + (i === selected ? ' selected' : '') +
212-
'" role="option" aria-selected="' + (i === selected ? 'true' : 'false') +
213-
'" href="' + escapeHtml(href) + '"><span class="search-result-kind">' +
214-
escapeHtml(entry.kind || '') + '</span><span class="search-result-name">' +
215-
entry.nameHtml + '</span></a>';
223+
return (
224+
'<a class="search-result' +
225+
(i === selected ? ' selected' : '') +
226+
'" role="option" aria-selected="' +
227+
(i === selected ? 'true' : 'false') +
228+
'" href="' +
229+
escapeHtml(href) +
230+
'"><span class="search-result-kind">' +
231+
escapeHtml(entry.kind || '') +
232+
'</span><span class="search-result-name">' +
233+
entry.nameHtml +
234+
'</span></a>'
235+
);
216236
})
217237
.join('');
218238
input.setAttribute('aria-expanded', 'true');
@@ -239,9 +259,13 @@
239259
if (idx === -1) {
240260
return escapeHtml(name);
241261
}
242-
return escapeHtml(name.slice(0, idx)) +
243-
'<mark>' + escapeHtml(name.slice(idx, idx + query.length)) + '</mark>' +
244-
escapeHtml(name.slice(idx + query.length));
262+
return (
263+
escapeHtml(name.slice(0, idx)) +
264+
'<mark>' +
265+
escapeHtml(name.slice(idx, idx + query.length)) +
266+
'</mark>' +
267+
escapeHtml(name.slice(idx + query.length))
268+
);
245269
}
246270

247271
function updateSearch() {
@@ -268,14 +292,13 @@
268292
href: entry.href,
269293
kind: entry.kind,
270294
name: entry.name,
271-
nameHtml: highlight(entry.name, query)
295+
nameHtml: highlight(entry.name, query),
272296
};
273297
});
274298
selected = -1;
275299
if (matches.length === 0) {
276300
resultsPanel.innerHTML =
277-
'<div class="search-result-empty">No results for &ldquo;' +
278-
escapeHtml(input.value) + '&rdquo;</div>';
301+
'<div class="search-result-empty">No results for &ldquo;' + escapeHtml(input.value) + '&rdquo;</div>';
279302
resultsPanel.hidden = false;
280303
return;
281304
}
@@ -294,10 +317,9 @@
294317
link.style.display = query === '' || name.indexOf(query) !== -1 ? '' : 'none';
295318
});
296319
sidebar.querySelectorAll('details').forEach(function (details) {
297-
var anyVisible = Array.prototype.some.call(
298-
details.querySelectorAll('a[data-name]'),
299-
function (a) { return a.style.display !== 'none'; }
300-
);
320+
var anyVisible = Array.prototype.some.call(details.querySelectorAll('a[data-name]'), function (a) {
321+
return a.style.display !== 'none';
322+
});
301323
if (query !== '' && anyVisible && !details.open) {
302324
details.open = true;
303325
}
@@ -424,19 +446,25 @@
424446
return;
425447
}
426448
current = best;
427-
links.forEach(function (l) { l.classList.remove('active'); });
449+
links.forEach(function (l) {
450+
l.classList.remove('active');
451+
});
428452
best.link.classList.add('active');
429453
}
430454
var ticking = false;
431-
document.addEventListener('scroll', function () {
432-
if (!ticking) {
433-
ticking = true;
434-
requestAnimationFrame(function () {
435-
update();
436-
ticking = false;
437-
});
438-
}
439-
}, { passive: true });
455+
document.addEventListener(
456+
'scroll',
457+
function () {
458+
if (!ticking) {
459+
ticking = true;
460+
requestAnimationFrame(function () {
461+
update();
462+
ticking = false;
463+
});
464+
}
465+
},
466+
{ passive: true },
467+
);
440468
update();
441469
}
442470

0 commit comments

Comments
 (0)