Skip to content

Commit e87c917

Browse files
use nightly rustfmt and sort imports (#145)
1 parent 00140c5 commit e87c917

File tree

25 files changed

+143
-60
lines changed

25 files changed

+143
-60
lines changed

.github/workflows/lint.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ 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+
2935
- name: Install uv
3036
uses: astral-sh/setup-uv@6b9c6063abd6010835644d4c2e1bef4cf5cd0fca # v6.0.1
3137
with:

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ repos:
2929
types:
3030
- rust
3131
language: rust
32-
entry: cargo fmt
32+
entry: cargo +nightly fmt
3333
args:
3434
- --
3535
- id: check

.rustfmt.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
group_imports = "StdExternalCrate"
2+
imports_granularity = "Item"
3+
imports_layout = "Vertical"
4+
reorder_imports = true
5+
unstable_features = true

crates/djls-conf/src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
use config::{Config, ConfigError as ExternalConfigError, File, FileFormat};
1+
use std::fs;
2+
use std::path::Path;
3+
4+
use config::Config;
5+
use config::ConfigError as ExternalConfigError;
6+
use config::File;
7+
use config::FileFormat;
28
use directories::ProjectDirs;
39
use serde::Deserialize;
4-
use std::{fs, path::Path};
510
use thiserror::Error;
611

712
#[derive(Error, Debug)]
@@ -85,10 +90,12 @@ impl Settings {
8590

8691
#[cfg(test)]
8792
mod tests {
88-
use super::*;
8993
use std::fs;
94+
9095
use tempfile::tempdir;
9196

97+
use super::*;
98+
9299
mod defaults {
93100
use super::*;
94101

crates/djls-project/src/lib.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ mod python;
44
mod system;
55
mod templatetags;
66

7+
use std::fmt;
8+
use std::path::Path;
9+
use std::path::PathBuf;
10+
711
use db::ProjectDatabase;
812
use meta::ProjectMetadata;
9-
use python::{find_python_environment, PythonEnvironment};
10-
pub use templatetags::TemplateTags;
11-
1213
use pyo3::prelude::*;
13-
use std::fmt;
14-
use std::path::{Path, PathBuf};
14+
use python::find_python_environment;
15+
use python::PythonEnvironment;
16+
pub use templatetags::TemplateTags;
1517

1618
#[derive(Debug)]
1719
pub struct DjangoProject {
@@ -90,10 +92,12 @@ impl fmt::Display for DjangoProject {
9092

9193
#[cfg(test)]
9294
mod tests {
93-
use super::*;
9495
use std::fs;
96+
9597
use tempfile::tempdir;
9698

99+
use super::*;
100+
97101
fn create_mock_django_project(dir: &Path) -> PathBuf {
98102
let project_path = dir.to_path_buf();
99103
fs::create_dir_all(&project_path).unwrap();

crates/djls-project/src/python.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
use std::fmt;
2+
use std::path::Path;
3+
use std::path::PathBuf;
4+
5+
use pyo3::prelude::*;
6+
17
use crate::db::Db;
28
use crate::system;
3-
use pyo3::prelude::*;
4-
use std::fmt;
5-
use std::path::{Path, PathBuf};
69

710
#[salsa::tracked]
811
pub fn find_python_environment(db: &dyn Db) -> Option<PythonEnvironment> {
@@ -152,12 +155,14 @@ impl fmt::Display for PythonEnvironment {
152155

153156
#[cfg(test)]
154157
mod tests {
155-
use super::*;
156158
use std::fs;
157159
#[cfg(unix)]
158160
use std::os::unix::fs::PermissionsExt;
161+
159162
use tempfile::tempdir;
160163

164+
use super::*;
165+
161166
fn create_mock_venv(dir: &Path, version: Option<&str>) -> PathBuf {
162167
let prefix = dir.to_path_buf();
163168

@@ -200,10 +205,14 @@ mod tests {
200205
}
201206

202207
mod env_discovery {
203-
use super::*;
204-
use crate::system::mock::{self as sys_mock, MockGuard};
205208
use which::Error as WhichError;
206209

210+
use super::*;
211+
use crate::system::mock::MockGuard;
212+
use crate::system::mock::{
213+
self as sys_mock,
214+
};
215+
207216
#[test]
208217
fn test_explicit_venv_path_found() {
209218
let project_dir = tempdir().unwrap();

crates/djls-project/src/system.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::env::VarError;
22
use std::path::PathBuf;
3+
34
use which::Error as WhichError;
45

56
pub fn find_executable(name: &str) -> Result<PathBuf, WhichError> {
@@ -26,11 +27,12 @@ pub fn env_var(key: &str) -> Result<String, VarError> {
2627

2728
#[cfg(test)]
2829
pub mod mock {
29-
use super::*;
3030
use std::cell::RefCell;
3131
use std::collections::HashMap;
3232
use std::thread_local;
3333

34+
use super::*;
35+
3436
thread_local! {
3537
static MOCK_EXEC_RESULTS: RefCell<HashMap<String, Result<PathBuf, WhichError>>> = RefCell::new(HashMap::new());
3638
static MOCK_ENV_RESULTS: RefCell<HashMap<String, Result<String, VarError>>> = RefCell::new(HashMap::new());
@@ -95,12 +97,17 @@ pub mod mock {
9597

9698
#[cfg(test)]
9799
mod tests {
98-
use super::mock::{self as sys_mock, MockGuard};
99-
use super::*;
100100
use std::env::VarError;
101101
use std::path::PathBuf;
102+
102103
use which::Error as WhichError;
103104

105+
use super::mock::MockGuard;
106+
use super::mock::{
107+
self as sys_mock,
108+
};
109+
use super::*;
110+
104111
#[test]
105112
fn test_exec_mock_path_retrieval() {
106113
let _guard = MockGuard;

crates/djls-project/src/templatetags.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
use pyo3::prelude::*;
2-
use pyo3::types::{PyDict, PyList};
31
use std::ops::Deref;
42

3+
use pyo3::prelude::*;
4+
use pyo3::types::PyDict;
5+
use pyo3::types::PyList;
6+
57
#[derive(Debug, Default, Clone)]
68
pub struct TemplateTags(Vec<TemplateTag>);
79

crates/djls-server/src/documents.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
use anyhow::{anyhow, Result};
2-
use djls_project::TemplateTags;
31
use std::collections::HashMap;
2+
3+
use anyhow::anyhow;
4+
use anyhow::Result;
5+
use djls_project::TemplateTags;
46
use tower_lsp_server::lsp_types::*;
57

68
#[derive(Debug, Default)]

crates/djls-server/src/queue.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
use anyhow::{anyhow, Result};
21
use std::future::Future;
32
use std::pin::Pin;
43
use std::sync::Arc;
5-
use tokio::sync::{mpsc, oneshot};
4+
5+
use anyhow::anyhow;
6+
use anyhow::Result;
7+
use tokio::sync::mpsc;
8+
use tokio::sync::oneshot;
69

710
/// Type alias for a type-erased, pinned, heap-allocated, Send-able future
811
/// that resolves to `Result<()>`.
@@ -186,12 +189,15 @@ impl Drop for QueueInner {
186189

187190
#[cfg(test)]
188191
mod tests {
189-
use super::*;
190-
use anyhow::anyhow;
191-
use std::sync::atomic::{AtomicUsize, Ordering};
192+
use std::sync::atomic::AtomicUsize;
193+
use std::sync::atomic::Ordering;
192194
use std::time::Duration;
195+
196+
use anyhow::anyhow;
193197
use tokio::time::sleep;
194198

199+
use super::*;
200+
195201
#[tokio::test]
196202
async fn test_submit_and_process() {
197203
let queue = Queue::new();

0 commit comments

Comments
 (0)