Skip to content

Commit b0af160

Browse files
committed
chore: lint & format w/ pre-commit
1 parent 275d860 commit b0af160

File tree

13 files changed

+221
-48
lines changed

13 files changed

+221
-48
lines changed

.codespell_ignore_words

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
managable
2+
commitish
3+
matchs
4+
medias
5+
thirdparty
6+
factorIn

.pre-commit-config.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
default_language_version:
2+
python: python3.12
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v5.0.0
6+
hooks:
7+
- id: end-of-file-fixer
8+
- id: trailing-whitespace
9+
- id: check-case-conflict
10+
- id: check-json
11+
- id: check-yaml
12+
- id: check-toml
13+
- id: check-merge-conflict
14+
- repo: https://github.com/asottile/pyupgrade
15+
rev: v3.20.0
16+
hooks:
17+
- id: pyupgrade
18+
args: ["--py39-plus"]
19+
exclude: "setup.py|src/octoprint_setuptools/__init__.py"
20+
- repo: https://github.com/astral-sh/ruff-pre-commit
21+
rev: v0.12.0
22+
hooks:
23+
- id: ruff-check
24+
args: ["--fix"]
25+
- id: ruff-format
26+
- repo: https://github.com/djlint/djlint
27+
rev: v1.36.4
28+
hooks:
29+
- id: djlint
30+
files: "\\.html$"
31+
types: [html]
32+
- id: djlint-reformat
33+
files: "\\.html$"
34+
types: [html]
35+
- id: djlint-jinja
36+
exclude: ^(octoprint_wrapped/templates/wrapped.svg.jinja2)
37+
- id: djlint-reformat-jinja
38+
exclude: ^(octoprint_wrapped/templates/wrapped.svg.jinja2)
39+
- repo: https://github.com/rbubley/mirrors-prettier
40+
rev: v3.6.0
41+
hooks:
42+
- id: prettier
43+
files: "\\.(js|json|css|less|md|yml|yaml)$"
44+
- repo: https://github.com/pre-commit/mirrors-eslint
45+
rev: v9.29.0
46+
hooks:
47+
- id: eslint
48+
files: \.js$
49+
exclude: ^(octoprint_wrapped/static/pure-snow/)
50+
additional_dependencies: ["[email protected]", "[email protected]"]
51+
- repo: https://github.com/codespell-project/codespell
52+
rev: v2.4.1
53+
hooks:
54+
- id: codespell
55+
exclude: ^(octoprint_wrapped/static/pure-snow/)

.prettierrc.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
printWidth: 90
2+
tabWidth: 4
3+
semi: true
4+
trailingComma: "none"
5+
singleQuote: false
6+
quoteProps: consistent
7+
bracketSpacing: false
8+
overrides:
9+
- files: ["*.yaml", "*.yml", "*.json", "*.less"]
10+
options:
11+
tabWidth: 2

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# OctoPrint-Wrapped 🎁
1+
# OctoPrint Wrapped! 🎁
22

33
Get your yearly OctoPrint stats a shareable "wrapped" picture - and let it snow! ❄️
44

Taskfile.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
version: "3"
44

55
env:
6-
LOCALES: [] # list your included locales here, e.g. ["de", "fr"]
7-
TRANSLATIONS: octoprint_wrapped/translations # translations folder, do not touch
8-
6+
LOCALES: [] # list your included locales here, e.g. ["de", "fr"]
7+
TRANSLATIONS: octoprint_wrapped/translations # translations folder, do not touch
98

109
tasks:
1110
install:
@@ -78,4 +77,3 @@ tasks:
7877
7978
echo "Copying translations for locale ${locale} from ${source} to ${target}..."
8079
cp -r "${source}" "${target}"
81-

eslint.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const {defineConfig} = require("eslint/config");
2+
const globals = require("globals");
3+
4+
module.exports = defineConfig([
5+
{
6+
languageOptions: {
7+
globals: {
8+
...globals.browser,
9+
...globals.jquery
10+
}
11+
}
12+
}
13+
]);

octoprint_wrapped/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ def get_svg(self, year):
7171
flask.abort(404)
7272

7373
response = flask.make_response(
74-
flask.render_template(
75-
"wrapped.svg.jinja2", **stats.model_dump(by_alias=True)
76-
)
74+
flask.render_template("wrapped.svg.jinja2", **stats.model_dump(by_alias=True))
7775
)
7876
response.headers["Content-Type"] = "image/svg+xml"
7977
return response
@@ -161,7 +159,7 @@ def _get_available_years(self) -> list[int]:
161159
if not stats_folder:
162160
return []
163161

164-
pattern = re.compile("\d{4}.json")
162+
pattern = re.compile(r"\d{4}.json")
165163

166164
years = []
167165
for entry in os.scandir(stats_folder):
@@ -180,7 +178,7 @@ def _get_year_stats(self, year: int) -> Optional[YearStats]:
180178
return None
181179

182180
try:
183-
with open(stats_file, "r") as f:
181+
with open(stats_file) as f:
184182
stats = json.load(f)
185183
except Exception:
186184
self._logger.exception(

octoprint_wrapped/static/js/ko.src.svgtopng.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
ko.bindingHandlers["src.svgtopng"] = {
2-
init: (
3-
element,
4-
valueAccessor,
5-
allBindingsAccessor,
6-
viewModel,
7-
bindingContext
8-
) => {
2+
init: (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) => {
93
const value = valueAccessor();
104
const valueUnwrapped = ko.unwrap(value);
115
if (!valueUnwrapped) return;
@@ -16,7 +10,7 @@ ko.bindingHandlers["src.svgtopng"] = {
1610
const svgString = xhr.responseText;
1711

1812
const svg = new Blob([svgString], {
19-
type: "image/svg+xml;charset=utf-8",
13+
type: "image/svg+xml;charset=utf-8"
2014
});
2115

2216
const url = URL.createObjectURL(svg);
@@ -37,7 +31,6 @@ ko.bindingHandlers["src.svgtopng"] = {
3731
};
3832
img.src = url;
3933
});
40-
},
34+
}
4135
};
42-
ko.bindingHandlers["src.svgtopng"].update =
43-
ko.bindingHandlers["src.svgtopng"].init;
36+
ko.bindingHandlers["src.svgtopng"].update = ko.bindingHandlers["src.svgtopng"].init;

octoprint_wrapped/static/js/wrapped.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $(function () {
1313
const SNOWFALL_LOCAL_STORAGE_KEY = "plugin.wrapped.snowfall";
1414
const snowfallToLocalStorage = (value) => {
1515
saveToLocalStorage(SNOWFALL_LOCAL_STORAGE_KEY, {
16-
enabled: value,
16+
enabled: value
1717
});
1818
};
1919

@@ -117,15 +117,13 @@ $(function () {
117117

118118
const styleSnow = document.createElement("link");
119119
styleSnow.href =
120-
BASEURL +
121-
"plugin/wrapped/static/pure-snow/pure-snow.css";
120+
BASEURL + "plugin/wrapped/static/pure-snow/pure-snow.css";
122121
styleSnow.rel = "stylesheet";
123122
head.appendChild(styleSnow);
124123

125124
const scriptSnow = document.createElement("script");
126125
scriptSnow.src =
127-
BASEURL +
128-
"plugin/wrapped/static/pure-snow/pure-snow.js";
126+
BASEURL + "plugin/wrapped/static/pure-snow/pure-snow.js";
129127
scriptSnow.defer = true;
130128
scriptSnow.onload = () => {
131129
setTimeout(() => {
@@ -161,15 +159,11 @@ $(function () {
161159

162160
OCTOPRINT_VIEWMODELS.push({
163161
construct: WrappedViewModel,
164-
dependencies: [
165-
"loginStateViewModel",
166-
"accessViewModel",
167-
"aboutViewModel",
168-
],
162+
dependencies: ["loginStateViewModel", "accessViewModel", "aboutViewModel"],
169163
elements: [
170164
"#about_plugin_wrapped",
171165
"#navbar_plugin_wrapped",
172-
"#navbar_plugin_wrapped_2",
173-
],
166+
"#navbar_plugin_wrapped_2"
167+
]
174168
});
175169
});
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
.snowflake {
2-
z-index: 32768;
3-
position: absolute;
4-
width: 10px;
5-
height: 10px;
6-
background: linear-gradient(white, white);
7-
/* Workaround for Chromium's selective color inversion */
8-
border-radius: 50%;
9-
filter: drop-shadow(0 0 10px black);
2+
z-index: 32768;
3+
position: absolute;
4+
width: 10px;
5+
height: 10px;
6+
background: linear-gradient(white, white);
7+
/* Workaround for Chromium's selective color inversion */
8+
border-radius: 50%;
9+
filter: drop-shadow(0 0 10px black);
1010
}

0 commit comments

Comments
 (0)