Skip to content

Commit 1f43a70

Browse files
committed
treefmt: add config with lots of formatters
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
1 parent b656e95 commit 1f43a70

File tree

3 files changed

+90
-18
lines changed

3 files changed

+90
-18
lines changed

justfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ src-build-run: src-build src-run
121121
clang-format:
122122
./scripts/clang-format-project.sh
123123

124+
# Do a clang format on the project via the treefmt tool
125+
[group('linter')]
126+
format:
127+
treefmt
128+
124129
# Check links in the markdown files
125130
[group('linter')]
126131
link-check:

shell.nix

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
{
2-
pkgs ? import <nixpkgs> { },
3-
}:
1+
{ pkgs ? import <nixpkgs> { }, }:
42
pkgs.mkShell {
53
# nativeBuildInputs is usually what you want -- tools you need to run
6-
nativeBuildInputs =
7-
with pkgs;
4+
nativeBuildInputs = with pkgs;
85
with qt6;
96
[
107
just
@@ -15,6 +12,10 @@ pkgs.mkShell {
1512
wrapQtAppsHook
1613
pkg-config
1714
libclang # for clang-format
15+
treefmt # formatting tool
16+
nodePackages.prettier # for webpage formatting
17+
shfmt # for shell formatting
18+
nixfmt # for nix formatting
1819
xmlstarlet # for download-icons.sh and download_translations.sh
1920
lychee # for link checking
2021
procs # fetches process info
@@ -32,20 +33,15 @@ pkgs.mkShell {
3233
librsvg
3334
imagemagick
3435
libicns
35-
]
36-
++ (
37-
if pkgs.stdenv.isLinux then
38-
[
39-
pkgs.lurk # strace replacement
40-
]
41-
else
42-
[ ]
43-
);
36+
] ++ (if pkgs.stdenv.isLinux then
37+
[
38+
pkgs.lurk # strace replacement
39+
]
40+
else
41+
[ ]);
4442

45-
buildInputs =
46-
with pkgs;
47-
with qt6;
48-
[
43+
buildInputs = with pkgs;
44+
with qt6; [
4945
qtbase
5046
qtwebsockets
5147
qtdeclarative

treefmt.toml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
on-unmatched = "info"
2+
3+
[formatter.clang-format]
4+
command = "clang-format"
5+
options = ["-i"]
6+
7+
# Only target the exact directories we want
8+
includes = [
9+
# Non-recursive for src root
10+
"src/*.cpp",
11+
"src/*.h",
12+
13+
# Recursive for specific subdirectories
14+
"src/entities/**/*.cpp",
15+
"src/entities/**/*.h",
16+
"src/utils/**/*.cpp",
17+
"src/utils/**/*.h",
18+
"src/helpers/**/*.cpp",
19+
"src/helpers/**/*.h",
20+
"src/services/**/*.cpp",
21+
"src/services/**/*.h",
22+
"src/widgets/**/*.cpp",
23+
"src/widgets/**/*.h",
24+
"src/dialogs/**/*.cpp",
25+
"src/dialogs/**/*.h",
26+
"src/api/**/*.cpp",
27+
"src/api/**/*.h",
28+
"src/libraries/piwiktracker/**/*.cpp",
29+
"src/libraries/piwiktracker/**/*.h",
30+
"src/libraries/qmarkdowntextedit/**/*.cpp",
31+
"src/libraries/qmarkdowntextedit/**/*.h",
32+
33+
# Recursive for tests
34+
"tests/unit_tests/**/*.cpp",
35+
"tests/unit_tests/**/*.h",
36+
]
37+
38+
# Explicitly exclude everything else
39+
excludes = [
40+
# Exclude everything not explicitly included
41+
"src/libraries/**/*.cpp",
42+
"src/libraries/**/*.cxx",
43+
"src/libraries/**/*.c",
44+
"src/libraries/**/*.h",
45+
"src/libraries/**/*.hxx",
46+
# You can add more specific exclusions here as needed
47+
]
48+
49+
[formatter.prettier]
50+
command = "prettier"
51+
options = ["--write"]
52+
includes = [
53+
"webpage/**/*.vue",
54+
"webpage/**/*.js",
55+
"*.md",
56+
"*.yaml",
57+
"*.yml",
58+
]
59+
60+
# Example generated by ../examples.sh
61+
[formatter.shfmt]
62+
command = "shfmt"
63+
excludes = []
64+
includes = ["*.sh", "*.bash", "*.envrc", "*.envrc.*"]
65+
options = ["-s", "-w", "-i", "2"]
66+
67+
[formatter.nixfmt-rfc-style]
68+
command = "nixfmt"
69+
excludes = []
70+
includes = ["*.nix"]
71+
options = []

0 commit comments

Comments
 (0)