Skip to content

Commit d677aac

Browse files
add pedantic clippy setting and fix/allow warnings (#147)
1 parent e87c917 commit d677aac

File tree

24 files changed

+180
-113
lines changed

24 files changed

+180
-113
lines changed

.github/workflows/lint.yml

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ jobs:
2626
with:
2727
persist-credentials: false
2828

29-
- name: Install nightly toolchain for rustfmt
30-
uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b
31-
with:
32-
toolchain: nightly
33-
components: rustfmt
34-
3529
- name: Install uv
3630
uses: astral-sh/setup-uv@6b9c6063abd6010835644d4c2e1bef4cf5cd0fca # v6.0.1
3731
with:
@@ -49,3 +43,44 @@ jobs:
4943
--all-files \
5044
--show-diff-on-failure \
5145
--color always
46+
47+
rustfmt:
48+
runs-on: ubuntu-24.04
49+
steps:
50+
- uses: actions/checkout@v4
51+
with:
52+
persist-credentials: false
53+
54+
- uses: actions-rust-lang/setup-rust-toolchain@9d7e65c320fdb52dcd45ffaa68deb6c02c8754d9
55+
with:
56+
toolchain: nightly
57+
components: rustfmt
58+
59+
- name: Run rustfmt
60+
run: cargo +nightly fmt --all -- --check
61+
62+
clippy:
63+
runs-on: ubuntu-24.04
64+
steps:
65+
- uses: actions/checkout@v4
66+
with:
67+
persist-credentials: false
68+
69+
- uses: actions-rust-lang/setup-rust-toolchain@9d7e65c320fdb52dcd45ffaa68deb6c02c8754d9
70+
with:
71+
components: clippy
72+
73+
- name: Run clippy
74+
run: cargo clippy --all-targets --all-features -- -D warnings
75+
76+
cargo-check:
77+
runs-on: ubuntu-24.04
78+
steps:
79+
- uses: actions/checkout@v4
80+
with:
81+
persist-credentials: false
82+
83+
- uses: actions-rust-lang/setup-rust-toolchain@9d7e65c320fdb52dcd45ffaa68deb6c02c8754d9
84+
85+
- name: Run cargo check
86+
run: cargo check --all-targets --all-features

.pre-commit-config.yaml

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
default_language_version:
2-
rust: "1.86"
3-
41
repos:
52
- repo: https://github.com/pre-commit/pre-commit-hooks
63
rev: v5.0.0
@@ -21,30 +18,3 @@ repos:
2118
rev: v1.6.0
2219
hooks:
2320
- id: zizmor
24-
- repo: local
25-
hooks:
26-
- id: fmt
27-
name: cargo fmt
28-
description: format files with "cargo fmt"
29-
types:
30-
- rust
31-
language: rust
32-
entry: cargo +nightly fmt
33-
args:
34-
- --
35-
- id: check
36-
name: cargo check
37-
description: check the package for errors with "cargo check"
38-
types:
39-
- rust
40-
language: rust
41-
entry: cargo check
42-
pass_filenames: false
43-
- id: clippy
44-
name: cargo clippy
45-
description: check the package with "cargo clippy"
46-
types:
47-
- rust
48-
language: rust
49-
entry: cargo clippy
50-
pass_filenames: false

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ thiserror = "2.0"
2323
tokio = { version = "1.42", features = ["full"] }
2424
tower-lsp-server = { version = "0.21", features = ["proposed"] }
2525

26+
[workspace.lints.clippy]
27+
pedantic = { level = "warn", priority = -1 }
28+
missing_errors_doc = "allow"
29+
2630
[profile.dev.package]
2731
insta.opt-level = 3
2832
similar.opt-level = 3

crates/djls-conf/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ toml = "0.8"
1414

1515
[dev-dependencies]
1616
tempfile = "3.19"
17+
18+
[lints]
19+
workspace = true

crates/djls-conf/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@ impl Settings {
7979
Ok(settings)
8080
}
8181

82+
#[must_use]
8283
pub fn debug(&self) -> bool {
8384
self.debug
8485
}
8586

87+
#[must_use]
8688
pub fn venv_path(&self) -> Option<&str> {
8789
self.venv_path.as_deref()
8890
}

crates/djls-dev/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ publish = false
66

77
[dependencies]
88
pyo3-build-config = { workspace = true, features = ["resolve-config"] }
9+
10+
[lints]
11+
workspace = true

crates/djls-dev/src/build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn setup_python_linking() {
3131
// Only link libpython explicitly if we are NOT building an extension module.
3232
if !is_extension_module {
3333
if let Some(lib_name) = &config.lib_name {
34-
println!("cargo:rustc-link-lib=dylib={}", lib_name);
34+
println!("cargo:rustc-link-lib=dylib={lib_name}");
3535
} else {
3636
// Warn only if linking is actually needed but we can't find the lib name
3737
println!("cargo:warning=Python library name not found in config (needed for non-extension module
@@ -43,9 +43,9 @@ builds).");
4343
// These are needed for test executables and potential future standalone binaries,
4444
// and generally harmless for extension modules.
4545
if let Some(lib_dir) = &config.lib_dir {
46-
println!("cargo:rustc-link-search=native={}", lib_dir);
46+
println!("cargo:rustc-link-search=native={lib_dir}");
4747
#[cfg(not(windows))]
48-
println!("cargo:rustc-link-arg=-Wl,-rpath,{}", lib_dir);
48+
println!("cargo:rustc-link-arg=-Wl,-rpath,{lib_dir}");
4949
} else {
5050
// Warn only if linking is actually needed but we can't find the lib dir
5151
if !is_extension_module {

crates/djls-project/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ djls-dev = { workspace = true }
1919

2020
[dev-dependencies]
2121
tempfile = { workspace = true }
22+
23+
[lints]
24+
workspace = true

crates/djls-project/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub struct DjangoProject {
2323
}
2424

2525
impl DjangoProject {
26+
#[must_use]
2627
pub fn new(path: PathBuf) -> Self {
2728
Self {
2829
path,
@@ -64,17 +65,19 @@ impl DjangoProject {
6465
Ok(())
6566
}
6667
Err(e) => {
67-
eprintln!("Failed to import Django: {}", e);
68+
eprintln!("Failed to import Django: {e}");
6869
Err(e)
6970
}
7071
}
7172
})
7273
}
7374

75+
#[must_use]
7476
pub fn template_tags(&self) -> Option<&TemplateTags> {
7577
self.template_tags.as_ref()
7678
}
7779

80+
#[must_use]
7881
pub fn path(&self) -> &Path {
7982
&self.path
8083
}
@@ -84,7 +87,7 @@ impl fmt::Display for DjangoProject {
8487
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8588
writeln!(f, "Project path: {}", self.path.display())?;
8689
if let Some(py_env) = &self.env {
87-
write!(f, "{}", py_env)?;
90+
write!(f, "{py_env}")?;
8891
}
8992
Ok(())
9093
}
@@ -141,7 +144,7 @@ mod tests {
141144

142145
let project = DjangoProject::new(project_path.clone());
143146

144-
let display_str = format!("{}", project);
147+
let display_str = format!("{project}");
145148
assert!(display_str.contains(&format!("Project path: {}", project_path.display())));
146149
}
147150
}

crates/djls-project/src/python.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@ impl PythonEnvironment {
9696
}
9797

9898
fn from_system_python() -> Option<Self> {
99-
let python_path = match system::find_executable("python") {
100-
Ok(p) => p,
101-
Err(_) => return None,
99+
let Ok(python_path) = system::find_executable("python") else {
100+
return None;
102101
};
103102
let bin_dir = python_path.parent()?;
104103
let prefix = bin_dir.parent()?;

0 commit comments

Comments
 (0)