Skip to content

Commit 83ef00c

Browse files
Merge pull request #45 from Kijewski/pr-rustfmt
Add `.rustfmt.toml` configuration
2 parents 37c300d + ee3a9e6 commit 83ef00c

File tree

14 files changed

+53
-39
lines changed

14 files changed

+53
-39
lines changed

.rustfmt.toml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
edition = "2021"
2+
group_imports = "StdExternalCrate"
3+
imports_granularity = "Module"
4+
newline_style = "Unix"
5+
normalize_comments = true
6+
unstable_features = true
7+
use_field_init_shorthand = true
8+
version = "Two"
9+
10+
ignore = [
11+
"testing/tests/hello.rs",
12+
]

rinja/src/error.rs

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pub type Result<I, E = Error> = std::result::Result<I, E>;
2222
/// using a adapter the benefits `failure` would
2323
/// bring to this crate are small, which is why
2424
/// `std::error::Error` was used.
25-
///
2625
#[non_exhaustive]
2726
#[derive(Debug)]
2827
pub enum Error {

rinja/src/filters/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ use std::fmt::{self, Write};
99

1010
#[cfg(feature = "serde_json")]
1111
mod json;
12-
#[cfg(feature = "serde_json")]
13-
pub use self::json::{json, json_pretty, AsIndent};
14-
1512
#[cfg(feature = "humansize")]
1613
use humansize::{ISizeFormatter, ToF64, DECIMAL};
1714
#[cfg(feature = "num-traits")]
@@ -20,6 +17,8 @@ use num_traits::{cast::NumCast, Signed};
2017
use percent_encoding::{utf8_percent_encode, AsciiSet, NON_ALPHANUMERIC};
2118
use rinja_escape::{Escaper, MarkupDisplay};
2219

20+
#[cfg(feature = "serde_json")]
21+
pub use self::json::{json, json_pretty, AsIndent};
2322
use crate::{Error, Result};
2423

2524
#[cfg(feature = "urlencode")]
@@ -427,7 +426,6 @@ where
427426
/// This struct implements [`fmt::Display`], but only produces a string once.
428427
/// Any subsequent call to `.to_string()` will result in an empty string, because the iterator is
429428
/// already consumed.
430-
//
431429
// The filter contains a [`Cell`], so we can modify iterator inside a method that takes `self` by
432430
// reference: [`fmt::Display::fmt()`] normally has the contract that it will produce the same result
433431
// in multiple invocations for the same object. We break this contract, because have to consume the

rinja_axum/tests/basic.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
use axum::{
2-
body::Body,
3-
http::{Request, StatusCode},
4-
routing::get,
5-
Router,
6-
};
1+
use axum::body::Body;
2+
use axum::http::{Request, StatusCode};
3+
use axum::routing::get;
4+
use axum::Router;
75
use http_body_util::BodyExt;
86
use rinja_axum::Template;
97
use tower::util::ServiceExt;

rinja_derive/src/config.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ use std::path::{Path, PathBuf};
33
use std::rc::Rc;
44
use std::{env, fs};
55

6+
use parser::node::Whitespace;
7+
use parser::Syntax;
68
#[cfg(feature = "config")]
79
use serde::Deserialize;
810

911
use crate::{CompileError, FileInfo, CRATE};
10-
use parser::node::Whitespace;
11-
use parser::Syntax;
1212

1313
#[derive(Debug)]
1414
pub(crate) struct Config<'a> {
@@ -65,7 +65,7 @@ impl<'a> Config<'a> {
6565
return Err(CompileError::new(
6666
format!("invalid value for `whitespace`: \"{s}\""),
6767
file_info,
68-
))
68+
));
6969
}
7070
};
7171
}

rinja_derive/src/generator.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ use std::path::Path;
66
use std::rc::Rc;
77
use std::{cmp, hash, mem, str};
88

9-
use crate::config::WhitespaceHandling;
10-
use crate::heritage::{Context, Heritage};
11-
use crate::input::{Source, TemplateInput};
12-
use crate::{CompileError, CRATE};
13-
149
use parser::node::{
1510
Call, Comment, CondTest, FilterBlock, If, Include, Let, Lit, Loop, Match, Whitespace, Ws,
1611
};
1712
use parser::{Expr, Filter, Node, Target, WithSpan};
1813
use quote::quote;
1914

15+
use crate::config::WhitespaceHandling;
16+
use crate::heritage::{Context, Heritage};
17+
use crate::input::{Source, TemplateInput};
18+
use crate::{CompileError, CRATE};
19+
2020
pub(crate) struct Generator<'a> {
2121
// The template input state: original struct AST and attributes
2222
input: &'a TemplateInput<'a>,
@@ -240,7 +240,7 @@ impl<'a> Generator<'a> {
240240
));
241241
}
242242

243-
/* Helper methods for handling node types */
243+
// Helper methods for handling node types
244244

245245
fn handle(
246246
&mut self,
@@ -960,7 +960,7 @@ impl<'a> Generator<'a> {
960960
(None, Some((prev_name, gen))) => (prev_name, gen + 1),
961961
// `super()` is called from outside a block
962962
(None, None) => {
963-
return Err(ctx.generate_error("cannot call 'super()' outside block", node))
963+
return Err(ctx.generate_error("cannot call 'super()' outside block", node));
964964
}
965965
};
966966

@@ -1225,7 +1225,7 @@ impl<'a> Generator<'a> {
12251225
self.handle_ws(comment.ws);
12261226
}
12271227

1228-
/* Visitor methods for expression types */
1228+
// Visitor methods for expression types
12291229

12301230
fn visit_expr_root(
12311231
&mut self,
@@ -1415,7 +1415,7 @@ impl<'a> Generator<'a> {
14151415
let opt_escaper = match args.get(1).map(|expr| &**expr) {
14161416
Some(Expr::StrLit(name)) => Some(*name),
14171417
Some(_) => {
1418-
return Err(ctx.generate_error("invalid escaper type for escape filter", node))
1418+
return Err(ctx.generate_error("invalid escaper type for escape filter", node));
14191419
}
14201420
None => None,
14211421
};
@@ -1618,7 +1618,7 @@ impl<'a> Generator<'a> {
16181618
_ => {
16191619
return Err(
16201620
ctx.generate_error("loop.cycle(…) cannot use an empty array", left)
1621-
)
1621+
);
16221622
}
16231623
},
16241624
s => return Err(ctx.generate_error(&format!("unknown loop method: {s:?}"), left)),
@@ -1873,7 +1873,7 @@ impl<'a> Generator<'a> {
18731873
}
18741874
}
18751875

1876-
/* Helper methods for dealing with whitespace nodes */
1876+
// Helper methods for dealing with whitespace nodes
18771877

18781878
// Combines `flush_ws()` and `prepare_ws()` to handle both trailing whitespace from the
18791879
// preceding literal and leading whitespace from the succeeding literal.

rinja_derive/src/input.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl TemplateInput<'_> {
5757
(&Source::Source(_), None) => {
5858
return Err(CompileError::no_file_info(
5959
"must include 'ext' attribute when using 'source' attribute",
60-
))
60+
));
6161
}
6262
};
6363

@@ -240,12 +240,12 @@ impl TemplateArgs {
240240
Ok(_) => {
241241
return Err(CompileError::no_file_info(
242242
"duplicated 'template' attribute",
243-
))
243+
));
244244
}
245245
Err(e) => {
246246
return Err(CompileError::no_file_info(format!(
247247
"unable to parse template arguments: {e}"
248-
)))
248+
)));
249249
}
250250
};
251251
}
@@ -264,7 +264,7 @@ impl TemplateArgs {
264264
return Err(CompileError::no_file_info(format!(
265265
"unsupported attribute argument {:?}",
266266
item.to_token_stream()
267-
)))
267+
)));
268268
}
269269
};
270270

@@ -280,13 +280,13 @@ impl TemplateArgs {
280280
_ => {
281281
return Err(CompileError::no_file_info(format!(
282282
"unsupported argument value type for {ident:?}"
283-
)))
283+
)));
284284
}
285285
},
286286
_ => {
287287
return Err(CompileError::no_file_info(format!(
288288
"unsupported argument value type for {ident:?}"
289-
)))
289+
)));
290290
}
291291
};
292292

@@ -440,7 +440,7 @@ impl FromStr for Print {
440440
v => {
441441
return Err(CompileError::no_file_info(format!(
442442
"invalid value for print option: {v}"
443-
)))
443+
)));
444444
}
445445
})
446446
}

rinja_escape/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,10 @@ pub trait Escaper {
169169
mod tests {
170170
extern crate std;
171171

172-
use super::*;
173172
use std::string::ToString;
174173

174+
use super::*;
175+
175176
#[test]
176177
fn test_escape() {
177178
assert_eq!(escape("", Html).to_string(), "");

rinja_parser/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -792,9 +792,10 @@ pub fn strip_common(base: &Path, path: &Path) -> String {
792792
#[cfg(not(windows))]
793793
#[cfg(test)]
794794
mod test {
795-
use super::{char_lit, num_lit, strip_common};
796795
use std::path::Path;
797796

797+
use super::{char_lit, num_lit, strip_common};
798+
798799
#[test]
799800
fn test_strip_common() {
800801
// Full path is returned instead of empty when the entire path is in common.

testing/tests/inheritance.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ pub mod parent {
6262
}
6363

6464
pub mod child {
65-
use super::parent::*;
6665
use rinja::Template;
6766

67+
use super::parent::*;
68+
6869
#[derive(Template)]
6970
#[template(path = "child.html")]
7071
pub struct ChildTemplate<'a> {

testing/tests/render_in_place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ fn test_render_in_place() {
3434
};
3535
assert_eq!(
3636
t.render().unwrap(),
37-
"Section 1: A=A\nB=B\nSection 2: C=C\nD=D\nSection 3 for:\n* A=1\nB=2\n* A=A\nB=B\n* A=a\nB=b\n"
37+
"Section 1: A=A\nB=B\nSection 2: C=C\nD=D\nSection 3 for:\n* A=1\nB=2\n* A=A\nB=B\n* A=a\nB=b\n"
3838
);
3939
}

testing/tests/simple.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#![allow(clippy::disallowed_names)] // For the use of `foo` in test cases
22

3-
use rinja::Template;
4-
53
use std::collections::HashMap;
64

5+
use rinja::Template;
6+
77
#[derive(Template)]
88
#[template(path = "simple.html")]
99
struct VariablesTemplate<'a> {

testing/tests/ui.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use std::os::unix::fs::symlink;
44
use std::path::Path;
5+
56
use trybuild::TestCases;
67

78
#[test]

testing/tests/whitespace.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ fn test_extra_whitespace() {
3939
let mut template = AllowWhitespaces::default();
4040
template.nested_1.nested_2.array = &["a0", "a1", "a2", "a3"];
4141
template.nested_1.nested_2.hash.insert("key", "value");
42-
assert_eq!(template.render().unwrap(), "\n0\n0\n0\n0\n\n\n\n0\n0\n0\n0\n0\n\na0\na1\nvalue\n\n\n\n\n\n[\n &quot;a0&quot;,\n &quot;a1&quot;,\n &quot;a2&quot;,\n &quot;a3&quot;\n]\n[\n &quot;a0&quot;,\n &quot;a1&quot;,\n &quot;a2&quot;,\n &quot;a3&quot;\n][\n &quot;a0&quot;,\n &quot;a1&quot;,\n &quot;a2&quot;,\n &quot;a3&quot;\n]\n[\n &quot;a1&quot;\n][\n &quot;a1&quot;\n]\n[\n &quot;a1&quot;,\n &quot;a2&quot;\n][\n &quot;a1&quot;,\n &quot;a2&quot;\n]\n[\n &quot;a1&quot;\n][\n &quot;a1&quot;\n]1-1-1\n3333 3\n2222 2\n0000 0\n3333 3\n\ntruefalse\nfalsefalsefalse\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
42+
assert_eq!(
43+
template.render().unwrap(),
44+
"\n0\n0\n0\n0\n\n\n\n0\n0\n0\n0\n0\n\na0\na1\nvalue\n\n\n\n\n\n[\n &quot;a0&quot;,\n &quot;a1&quot;,\n &quot;a2&quot;,\n &quot;a3&quot;\n]\n[\n &quot;a0&quot;,\n &quot;a1&quot;,\n &quot;a2&quot;,\n &quot;a3&quot;\n][\n &quot;a0&quot;,\n &quot;a1&quot;,\n &quot;a2&quot;,\n &quot;a3&quot;\n]\n[\n &quot;a1&quot;\n][\n &quot;a1&quot;\n]\n[\n &quot;a1&quot;,\n &quot;a2&quot;\n][\n &quot;a1&quot;,\n &quot;a2&quot;\n]\n[\n &quot;a1&quot;\n][\n &quot;a1&quot;\n]1-1-1\n3333 3\n2222 2\n0000 0\n3333 3\n\ntruefalse\nfalsefalsefalse\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
45+
);
4346
}
4447

4548
macro_rules! test_template_minimize {

0 commit comments

Comments
 (0)