Skip to content

Commit cc4f553

Browse files
authored
Run prettier via pre-commit (#234)
1 parent 5e1eac3 commit cc4f553

File tree

3 files changed

+40
-45
lines changed

3 files changed

+40
-45
lines changed

Diff for: .github/workflows/lint.yml

+1-12
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ permissions:
1010
contents: read
1111

1212
jobs:
13-
pre-commit:
13+
lint:
1414
runs-on: ubuntu-latest
1515

1616
steps:
@@ -20,14 +20,3 @@ jobs:
2020
python-version: "3.x"
2121
cache: pip
2222
- uses: pre-commit/[email protected]
23-
24-
prettier:
25-
runs-on: ubuntu-latest
26-
27-
steps:
28-
- uses: actions/checkout@v4
29-
- uses: actions/setup-node@v4
30-
with:
31-
node-version: "22"
32-
- name: Lint with Prettier
33-
run: npx prettier templates/switchers.js --check --single-quote

Diff for: .pre-commit-config.yaml

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.6.0
3+
rev: v5.0.0
44
hooks:
55
- id: check-added-large-files
66
- id: check-case-conflict
@@ -14,35 +14,41 @@ repos:
1414
- id: trailing-whitespace
1515

1616
- repo: https://github.com/astral-sh/ruff-pre-commit
17-
rev: v0.6.7
17+
rev: v0.7.1
1818
hooks:
1919
- id: ruff-format
2020

2121
- repo: https://github.com/python-jsonschema/check-jsonschema
22-
rev: 0.29.2
22+
rev: 0.29.4
2323
hooks:
2424
- id: check-github-workflows
2525

2626
- repo: https://github.com/rhysd/actionlint
27-
rev: v1.7.1
27+
rev: v1.7.3
2828
hooks:
2929
- id: actionlint
3030

3131
- repo: https://github.com/tox-dev/pyproject-fmt
32-
rev: 2.2.3
32+
rev: v2.5.0
3333
hooks:
3434
- id: pyproject-fmt
3535

3636
- repo: https://github.com/abravalheri/validate-pyproject
37-
rev: v0.19
37+
rev: v0.22
3838
hooks:
3939
- id: validate-pyproject
4040

4141
- repo: https://github.com/tox-dev/tox-ini-fmt
42-
rev: 1.4.0
42+
rev: 1.4.1
4343
hooks:
4444
- id: tox-ini-fmt
4545

46+
- repo: https://github.com/rbubley/mirrors-prettier
47+
rev: v3.3.3
48+
hooks:
49+
- id: prettier
50+
files: templates/switchers.js
51+
4652
- repo: meta
4753
hooks:
4854
- id: check-hooks-apply

Diff for: templates/switchers.js

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
'use strict';
1+
"use strict";
22

33
// File URIs must begin with either one or three forward slashes
4-
const _is_file_uri = (uri) => uri.startsWith('file:/');
4+
const _is_file_uri = (uri) => uri.startsWith("file:/");
55

66
const _IS_LOCAL = _is_file_uri(window.location.href);
7-
const _CURRENT_RELEASE = DOCUMENTATION_OPTIONS.VERSION || '';
8-
const _CURRENT_VERSION = _CURRENT_RELEASE.split('.', 2).join('.');
9-
const _CURRENT_LANGUAGE = DOCUMENTATION_OPTIONS.LANGUAGE?.toLowerCase() || 'en';
7+
const _CURRENT_RELEASE = DOCUMENTATION_OPTIONS.VERSION || "";
8+
const _CURRENT_VERSION = _CURRENT_RELEASE.split(".", 2).join(".");
9+
const _CURRENT_LANGUAGE = DOCUMENTATION_OPTIONS.LANGUAGE?.toLowerCase() || "en";
1010
const _CURRENT_PREFIX = (() => {
1111
if (_IS_LOCAL) return null;
1212
// Sphinx 7.2+ defines the content root data attribute in the HTML element.
@@ -15,8 +15,8 @@ const _CURRENT_PREFIX = (() => {
1515
return new URL(_CONTENT_ROOT, window.location).pathname;
1616
}
1717
// Fallback for older versions of Sphinx (used in Python 3.10 and older).
18-
const _NUM_PREFIX_PARTS = _CURRENT_LANGUAGE === 'en' ? 2 : 3;
19-
return window.location.pathname.split('/', _NUM_PREFIX_PARTS).join('/') + '/';
18+
const _NUM_PREFIX_PARTS = _CURRENT_LANGUAGE === "en" ? 2 : 3;
19+
return window.location.pathname.split("/", _NUM_PREFIX_PARTS).join("/") + "/";
2020
})();
2121

2222
const _ALL_VERSIONS = new Map($VERSIONS);
@@ -28,15 +28,15 @@ const _ALL_LANGUAGES = new Map($LANGUAGES);
2828
* @private
2929
*/
3030
const _create_version_select = (versions) => {
31-
const select = document.createElement('select');
32-
select.className = 'version-select';
31+
const select = document.createElement("select");
32+
select.className = "version-select";
3333
if (_IS_LOCAL) {
3434
select.disabled = true;
35-
select.title = 'Version switching is disabled in local builds';
35+
select.title = "Version switching is disabled in local builds";
3636
}
3737

3838
for (const [version, title] of versions) {
39-
const option = document.createElement('option');
39+
const option = document.createElement("option");
4040
option.value = version;
4141
if (version === _CURRENT_VERSION) {
4242
option.text = _CURRENT_RELEASE;
@@ -61,15 +61,15 @@ const _create_language_select = (languages) => {
6161
languages.set(_CURRENT_LANGUAGE, _CURRENT_LANGUAGE);
6262
}
6363

64-
const select = document.createElement('select');
65-
select.className = 'language-select';
64+
const select = document.createElement("select");
65+
select.className = "language-select";
6666
if (_IS_LOCAL) {
6767
select.disabled = true;
68-
select.title = 'Language switching is disabled in local builds';
68+
select.title = "Language switching is disabled in local builds";
6969
}
7070

7171
for (const [language, title] of languages) {
72-
const option = document.createElement('option');
72+
const option = document.createElement("option");
7373
option.value = language;
7474
option.text = title;
7575
if (language === _CURRENT_LANGUAGE) option.selected = true;
@@ -88,7 +88,7 @@ const _navigate_to_first_existing = async (urls) => {
8888
// Navigate to the first existing URL in urls.
8989
for (const url of urls) {
9090
try {
91-
const response = await fetch(url, { method: 'HEAD' });
91+
const response = await fetch(url, { method: "HEAD" });
9292
if (response.ok) {
9393
window.location.href = url;
9494
return url;
@@ -99,8 +99,8 @@ const _navigate_to_first_existing = async (urls) => {
9999
}
100100

101101
// if all else fails, redirect to the d.p.o root
102-
window.location.href = '/';
103-
return '/';
102+
window.location.href = "/";
103+
return "/";
104104
};
105105

106106
/**
@@ -116,7 +116,7 @@ const _on_version_switch = async (event) => {
116116
// English has no language prefix.
117117
const new_prefix_en = `/${selected_version}/`;
118118
const new_prefix =
119-
_CURRENT_LANGUAGE === 'en'
119+
_CURRENT_LANGUAGE === "en"
120120
? new_prefix_en
121121
: `/${_CURRENT_LANGUAGE}/${selected_version}/`;
122122
if (_CURRENT_PREFIX !== new_prefix) {
@@ -146,7 +146,7 @@ const _on_language_switch = async (event) => {
146146
const selected_language = event.target.value;
147147
// English has no language prefix.
148148
const new_prefix =
149-
selected_language === 'en'
149+
selected_language === "en"
150150
? `/${_CURRENT_VERSION}/`
151151
: `/${selected_language}/${_CURRENT_VERSION}/`;
152152
if (_CURRENT_PREFIX !== new_prefix) {
@@ -170,24 +170,24 @@ const _initialise_switchers = () => {
170170
const languages = _ALL_LANGUAGES;
171171

172172
document
173-
.querySelectorAll('.version_switcher_placeholder')
173+
.querySelectorAll(".version_switcher_placeholder")
174174
.forEach((placeholder) => {
175175
const s = _create_version_select(versions);
176-
s.addEventListener('change', _on_version_switch);
176+
s.addEventListener("change", _on_version_switch);
177177
placeholder.append(s);
178178
});
179179

180180
document
181-
.querySelectorAll('.language_switcher_placeholder')
181+
.querySelectorAll(".language_switcher_placeholder")
182182
.forEach((placeholder) => {
183183
const s = _create_language_select(languages);
184-
s.addEventListener('change', _on_language_switch);
184+
s.addEventListener("change", _on_language_switch);
185185
placeholder.append(s);
186186
});
187187
};
188188

189-
if (document.readyState !== 'loading') {
189+
if (document.readyState !== "loading") {
190190
_initialise_switchers();
191191
} else {
192-
document.addEventListener('DOMContentLoaded', _initialise_switchers);
192+
document.addEventListener("DOMContentLoaded", _initialise_switchers);
193193
}

0 commit comments

Comments
 (0)