mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-29 22:11:17 +00:00
ci: update formatting for edition=2024
This commit is contained in:
parent
8256eadf5a
commit
4b44189809
@ -5,7 +5,7 @@ newline_style = "Unix"
|
||||
normalize_comments = true
|
||||
unstable_features = true
|
||||
use_field_init_shorthand = true
|
||||
version = "Two"
|
||||
style_edition = "2024"
|
||||
|
||||
ignore = [
|
||||
"testing/tests/hello.rs",
|
||||
|
@ -1,5 +1,5 @@
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use rinja::filters::{escape, Html};
|
||||
use criterion::{Criterion, black_box, criterion_group, criterion_main};
|
||||
use rinja::filters::{Html, escape};
|
||||
|
||||
criterion_main!(benches);
|
||||
criterion_group!(benches, functions);
|
||||
|
@ -1,4 +1,4 @@
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use criterion::{Criterion, black_box, criterion_group, criterion_main};
|
||||
use rinja::Template;
|
||||
|
||||
criterion_main!(benches);
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::convert::Infallible;
|
||||
use std::fmt;
|
||||
|
||||
use humansize::{ISizeFormatter, ToF64, DECIMAL};
|
||||
use humansize::{DECIMAL, ISizeFormatter, ToF64};
|
||||
|
||||
/// Returns adequate string representation (in KB, ..) of number of bytes
|
||||
///
|
||||
|
@ -2,7 +2,7 @@ use std::convert::Infallible;
|
||||
use std::{fmt, io, str};
|
||||
|
||||
use serde::Serialize;
|
||||
use serde_json::ser::{to_writer, PrettyFormatter, Serializer};
|
||||
use serde_json::ser::{PrettyFormatter, Serializer, to_writer};
|
||||
|
||||
use super::FastWritable;
|
||||
|
||||
|
@ -22,17 +22,17 @@ mod num_traits;
|
||||
mod urlencode;
|
||||
|
||||
pub use builtin::{
|
||||
capitalize, center, fmt, format, indent, join, linebreaks, linebreaksbr, lower, lowercase,
|
||||
paragraphbreaks, pluralize, title, trim, truncate, upper, uppercase, wordcount, PluralizeCount,
|
||||
PluralizeCount, capitalize, center, fmt, format, indent, join, linebreaks, linebreaksbr, lower,
|
||||
lowercase, paragraphbreaks, pluralize, title, trim, truncate, upper, uppercase, wordcount,
|
||||
};
|
||||
pub use escape::{
|
||||
e, escape, safe, AutoEscape, AutoEscaper, Escaper, FastWritable, Html, HtmlSafe,
|
||||
HtmlSafeOutput, MaybeSafe, Safe, Text, Unsafe, Writable, WriteWritable,
|
||||
AutoEscape, AutoEscaper, Escaper, FastWritable, Html, HtmlSafe, HtmlSafeOutput, MaybeSafe,
|
||||
Safe, Text, Unsafe, Writable, WriteWritable, e, escape, safe,
|
||||
};
|
||||
#[cfg(feature = "humansize")]
|
||||
pub use humansize::filesizeformat;
|
||||
#[cfg(feature = "serde_json")]
|
||||
pub use json::{json, json_pretty, AsIndent};
|
||||
pub use json::{AsIndent, json, json_pretty};
|
||||
#[cfg(feature = "num-traits")]
|
||||
pub use num_traits::{abs, into_f64, into_isize};
|
||||
#[cfg(feature = "urlencode")]
|
||||
|
@ -1,5 +1,5 @@
|
||||
use num_traits::cast::NumCast;
|
||||
use num_traits::Signed;
|
||||
use num_traits::cast::NumCast;
|
||||
|
||||
use crate::{Error, Result};
|
||||
|
||||
|
@ -2,7 +2,7 @@ use std::convert::Infallible;
|
||||
use std::fmt;
|
||||
use std::fmt::Write;
|
||||
|
||||
use percent_encoding::{utf8_percent_encode, AsciiSet, NON_ALPHANUMERIC};
|
||||
use percent_encoding::{AsciiSet, NON_ALPHANUMERIC, utf8_percent_encode};
|
||||
|
||||
use crate::filters::{FastWritable, HtmlSafeOutput};
|
||||
|
||||
|
@ -34,14 +34,11 @@ where
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<(<I as Iterator>::Item, LoopItem)> {
|
||||
self.iter.next().map(|(index, item)| {
|
||||
(
|
||||
item,
|
||||
LoopItem {
|
||||
index,
|
||||
first: index == 0,
|
||||
last: self.iter.peek().is_none(),
|
||||
},
|
||||
)
|
||||
(item, LoopItem {
|
||||
index,
|
||||
first: index == 0,
|
||||
last: self.iter.peek().is_none(),
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ use std::fmt;
|
||||
#[doc(no_inline)]
|
||||
pub use actix_web;
|
||||
use actix_web::body::BoxBody;
|
||||
use actix_web::http::header::HeaderValue;
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::http::header::HeaderValue;
|
||||
use actix_web::{HttpResponse, HttpResponseBuilder, ResponseError};
|
||||
#[doc(no_inline)]
|
||||
pub use rinja::*;
|
||||
|
@ -1,7 +1,7 @@
|
||||
use axum::Router;
|
||||
use axum::body::Body;
|
||||
use axum::http::{Request, StatusCode};
|
||||
use axum::routing::get;
|
||||
use axum::Router;
|
||||
use http_body_util::BodyExt;
|
||||
use rinja_axum::Template;
|
||||
use tower::util::ServiceExt;
|
||||
|
@ -14,7 +14,7 @@ use rustc_hash::FxBuildHasher;
|
||||
#[cfg(feature = "config")]
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{CompileError, FileInfo, CRATE};
|
||||
use crate::{CRATE, CompileError, FileInfo};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Config {
|
||||
@ -682,22 +682,19 @@ mod tests {
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
config.escapers,
|
||||
vec![
|
||||
(str_set(&["js"]), "::my_filters::Js".into()),
|
||||
(
|
||||
str_set(&[
|
||||
"html", "htm", "j2", "jinja", "jinja2", "rinja", "svg", "xml"
|
||||
]),
|
||||
"::rinja::filters::Html".into()
|
||||
),
|
||||
(
|
||||
str_set(&["md", "none", "txt", "yml", ""]),
|
||||
"::rinja::filters::Text".into()
|
||||
),
|
||||
]
|
||||
);
|
||||
assert_eq!(config.escapers, vec![
|
||||
(str_set(&["js"]), "::my_filters::Js".into()),
|
||||
(
|
||||
str_set(&[
|
||||
"html", "htm", "j2", "jinja", "jinja2", "rinja", "svg", "xml"
|
||||
]),
|
||||
"::rinja::filters::Html".into()
|
||||
),
|
||||
(
|
||||
str_set(&["md", "none", "txt", "yml", ""]),
|
||||
"::rinja::filters::Text".into()
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
#[cfg(feature = "config")]
|
||||
|
@ -20,7 +20,7 @@ use crate::config::WhitespaceHandling;
|
||||
use crate::heritage::{Context, Heritage};
|
||||
use crate::html::write_escaped_str;
|
||||
use crate::input::{Source, TemplateInput};
|
||||
use crate::{CompileError, FileInfo, MsgValidEscapers, BUILT_IN_FILTERS, CRATE};
|
||||
use crate::{BUILT_IN_FILTERS, CRATE, CompileError, FileInfo, MsgValidEscapers};
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||
enum EvaluatedResult {
|
||||
|
@ -15,11 +15,11 @@ use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::path::Path;
|
||||
|
||||
use config::{read_config_file, Config};
|
||||
use config::{Config, read_config_file};
|
||||
use generator::{Generator, MapChain};
|
||||
use heritage::{Context, Heritage};
|
||||
use input::{Print, TemplateArgs, TemplateInput};
|
||||
use parser::{strip_common, Parsed, WithSpan};
|
||||
use parser::{Parsed, WithSpan, strip_common};
|
||||
#[cfg(not(feature = "__standalone"))]
|
||||
use proc_macro::TokenStream as TokenStream12;
|
||||
#[cfg(feature = "__standalone")]
|
||||
|
@ -1,4 +1,4 @@
|
||||
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
|
||||
use criterion::{BatchSize, Criterion, criterion_group, criterion_main};
|
||||
use quote::quote;
|
||||
|
||||
criterion_main!(benches);
|
||||
|
@ -1,4 +1,4 @@
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput};
|
||||
use criterion::{Criterion, Throughput, black_box, criterion_group, criterion_main};
|
||||
use rinja_parser::{Ast, Syntax};
|
||||
|
||||
criterion_main!(benches);
|
||||
|
@ -11,8 +11,8 @@ use nom::multi::{fold_many0, many0, separated_list0, separated_list1};
|
||||
use nom::sequence::{pair, preceded, terminated, tuple};
|
||||
|
||||
use crate::{
|
||||
char_lit, filter, identifier, keyword, not_ws, num_lit, path_or_identifier, str_lit, ws,
|
||||
CharLit, ErrorContext, Level, Num, ParseResult, PathOrIdentifier, StrLit, WithSpan,
|
||||
CharLit, ErrorContext, Level, Num, ParseResult, PathOrIdentifier, StrLit, WithSpan, char_lit,
|
||||
filter, identifier, keyword, not_ws, num_lit, path_or_identifier, str_lit, ws,
|
||||
};
|
||||
|
||||
macro_rules! expr_prec_layer {
|
||||
|
@ -535,13 +535,10 @@ fn char_lit(i: &str) -> Result<(&str, CharLit<'_>), ParseErr<'_>> {
|
||||
|
||||
let (nb, max_value, err1, err2) = match c {
|
||||
Char::Literal | Char::Escaped => {
|
||||
return Ok((
|
||||
i,
|
||||
CharLit {
|
||||
prefix: b_prefix.map(|_| CharPrefix::Binary),
|
||||
content: s,
|
||||
},
|
||||
));
|
||||
return Ok((i, CharLit {
|
||||
prefix: b_prefix.map(|_| CharPrefix::Binary),
|
||||
content: s,
|
||||
}));
|
||||
}
|
||||
Char::AsciiEscape(nb) => (
|
||||
nb,
|
||||
@ -566,13 +563,10 @@ fn char_lit(i: &str) -> Result<(&str, CharLit<'_>), ParseErr<'_>> {
|
||||
return Err(nom::Err::Failure(ErrorContext::new(err2, start)));
|
||||
}
|
||||
|
||||
Ok((
|
||||
i,
|
||||
CharLit {
|
||||
prefix: b_prefix.map(|_| CharPrefix::Binary),
|
||||
content: s,
|
||||
},
|
||||
))
|
||||
Ok((i, CharLit {
|
||||
prefix: b_prefix.map(|_| CharPrefix::Binary),
|
||||
content: s,
|
||||
}))
|
||||
}
|
||||
|
||||
/// Represents the different kinds of char declarations:
|
||||
@ -1161,13 +1155,10 @@ mod test {
|
||||
// Check with `b` prefix.
|
||||
assert_eq!(
|
||||
char_lit("b'a'").unwrap(),
|
||||
(
|
||||
"",
|
||||
crate::CharLit {
|
||||
prefix: Some(crate::CharPrefix::Binary),
|
||||
content: "a"
|
||||
}
|
||||
)
|
||||
("", crate::CharLit {
|
||||
prefix: Some(crate::CharPrefix::Binary),
|
||||
content: "a"
|
||||
})
|
||||
);
|
||||
|
||||
// Should fail.
|
||||
@ -1185,23 +1176,17 @@ mod test {
|
||||
fn test_str_lit() {
|
||||
assert_eq!(
|
||||
str_lit(r#"b"hello""#).unwrap(),
|
||||
(
|
||||
"",
|
||||
StrLit {
|
||||
prefix: Some(StrPrefix::Binary),
|
||||
content: "hello"
|
||||
}
|
||||
)
|
||||
("", StrLit {
|
||||
prefix: Some(StrPrefix::Binary),
|
||||
content: "hello"
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
str_lit(r#"c"hello""#).unwrap(),
|
||||
(
|
||||
"",
|
||||
StrLit {
|
||||
prefix: Some(StrPrefix::CLike),
|
||||
content: "hello"
|
||||
}
|
||||
)
|
||||
("", StrLit {
|
||||
prefix: Some(StrPrefix::CLike),
|
||||
content: "hello"
|
||||
})
|
||||
);
|
||||
assert!(str_lit(r#"d"hello""#).is_err());
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ use nom::sequence::{delimited, pair, preceded, tuple};
|
||||
|
||||
use crate::memchr_splitter::{Splitter1, Splitter2, Splitter3};
|
||||
use crate::{
|
||||
filter, identifier, is_ws, keyword, not_ws, skip_till, str_lit_without_prefix, ws,
|
||||
ErrorContext, Expr, Filter, ParseResult, State, Target, WithSpan,
|
||||
ErrorContext, Expr, Filter, ParseResult, State, Target, WithSpan, filter, identifier, is_ws,
|
||||
keyword, not_ws, skip_till, str_lit_without_prefix, ws,
|
||||
};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@ -409,14 +409,11 @@ impl<'a> CondTest<'a> {
|
||||
ws(|i| Expr::parse(i, s.level.get())),
|
||||
)(i)?;
|
||||
let contains_bool_lit_or_is_defined = expr.contains_bool_lit_or_is_defined();
|
||||
Ok((
|
||||
i,
|
||||
Self {
|
||||
target,
|
||||
expr,
|
||||
contains_bool_lit_or_is_defined,
|
||||
},
|
||||
))
|
||||
Ok((i, Self {
|
||||
target,
|
||||
expr,
|
||||
contains_bool_lit_or_is_defined,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@ -1414,7 +1411,7 @@ fn is_rust_keyword(ident: &str) -> bool {
|
||||
|
||||
#[cfg(test)]
|
||||
mod kws_tests {
|
||||
use super::{is_rust_keyword, KWS, KWS_EXTRA, MAX_REPL_LEN};
|
||||
use super::{KWS, KWS_EXTRA, MAX_REPL_LEN, is_rust_keyword};
|
||||
|
||||
fn ensure_utf8_inner(entry: &[&[[u8; MAX_REPL_LEN]]]) {
|
||||
for kws in entry {
|
||||
|
@ -6,8 +6,8 @@ use nom::multi::separated_list1;
|
||||
use nom::sequence::{pair, preceded, tuple};
|
||||
|
||||
use crate::{
|
||||
bool_lit, char_lit, identifier, keyword, num_lit, path_or_identifier, str_lit, ws, CharLit,
|
||||
ErrorContext, Num, ParseErr, ParseResult, PathOrIdentifier, State, StrLit, WithSpan,
|
||||
CharLit, ErrorContext, Num, ParseErr, ParseResult, PathOrIdentifier, State, StrLit, WithSpan,
|
||||
bool_lit, char_lit, identifier, keyword, num_lit, path_or_identifier, str_lit, ws,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
|
@ -112,13 +112,9 @@ fn test_parse_numbers() {
|
||||
fn test_parse_var() {
|
||||
let s = Syntax::default();
|
||||
|
||||
assert_eq!(
|
||||
Ast::from_str("{{ foo }}", None, &s).unwrap().nodes,
|
||||
vec![Node::Expr(
|
||||
Ws(None, None),
|
||||
WithSpan::no_span(Expr::Var("foo"))
|
||||
)],
|
||||
);
|
||||
assert_eq!(Ast::from_str("{{ foo }}", None, &s).unwrap().nodes, vec![
|
||||
Node::Expr(Ws(None, None), WithSpan::no_span(Expr::Var("foo")))
|
||||
],);
|
||||
assert_eq!(
|
||||
Ast::from_str("{{ foo_bar }}", None, &s).unwrap().nodes,
|
||||
vec![Node::Expr(
|
||||
@ -127,26 +123,18 @@ fn test_parse_var() {
|
||||
)],
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
Ast::from_str("{{ none }}", None, &s).unwrap().nodes,
|
||||
vec![Node::Expr(
|
||||
Ws(None, None),
|
||||
WithSpan::no_span(Expr::Var("none"))
|
||||
)],
|
||||
);
|
||||
assert_eq!(Ast::from_str("{{ none }}", None, &s).unwrap().nodes, vec![
|
||||
Node::Expr(Ws(None, None), WithSpan::no_span(Expr::Var("none")))
|
||||
],);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_const() {
|
||||
let s = Syntax::default();
|
||||
|
||||
assert_eq!(
|
||||
Ast::from_str("{{ FOO }}", None, &s).unwrap().nodes,
|
||||
vec![Node::Expr(
|
||||
Ws(None, None),
|
||||
WithSpan::no_span(Expr::Path(vec!["FOO"]))
|
||||
)],
|
||||
);
|
||||
assert_eq!(Ast::from_str("{{ FOO }}", None, &s).unwrap().nodes, vec![
|
||||
Node::Expr(Ws(None, None), WithSpan::no_span(Expr::Path(vec!["FOO"])))
|
||||
],);
|
||||
assert_eq!(
|
||||
Ast::from_str("{{ FOO_BAR }}", None, &s).unwrap().nodes,
|
||||
vec![Node::Expr(
|
||||
@ -155,26 +143,18 @@ fn test_parse_const() {
|
||||
)],
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
Ast::from_str("{{ NONE }}", None, &s).unwrap().nodes,
|
||||
vec![Node::Expr(
|
||||
Ws(None, None),
|
||||
WithSpan::no_span(Expr::Path(vec!["NONE"]))
|
||||
)],
|
||||
);
|
||||
assert_eq!(Ast::from_str("{{ NONE }}", None, &s).unwrap().nodes, vec![
|
||||
Node::Expr(Ws(None, None), WithSpan::no_span(Expr::Path(vec!["NONE"])))
|
||||
],);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_path() {
|
||||
let s = Syntax::default();
|
||||
|
||||
assert_eq!(
|
||||
Ast::from_str("{{ None }}", None, &s).unwrap().nodes,
|
||||
vec![Node::Expr(
|
||||
Ws(None, None),
|
||||
WithSpan::no_span(Expr::Path(vec!["None"]))
|
||||
)],
|
||||
);
|
||||
assert_eq!(Ast::from_str("{{ None }}", None, &s).unwrap().nodes, vec![
|
||||
Node::Expr(Ws(None, None), WithSpan::no_span(Expr::Path(vec!["None"])))
|
||||
],);
|
||||
assert_eq!(
|
||||
Ast::from_str("{{ Some(123) }}", None, &s).unwrap().nodes,
|
||||
vec![Node::Expr(
|
||||
@ -328,41 +308,36 @@ fn test_rust_macro() {
|
||||
WithSpan::no_span(Expr::RustMacro(vec!["alloc", "vec"], "1, 2, 3")),
|
||||
)],
|
||||
);
|
||||
assert_eq!(
|
||||
Ast::from_str("{{a!()}}", None, &syntax).unwrap().nodes,
|
||||
[Node::Expr(
|
||||
assert_eq!(Ast::from_str("{{a!()}}", None, &syntax).unwrap().nodes, [
|
||||
Node::Expr(
|
||||
Ws(None, None),
|
||||
WithSpan::no_span(Expr::RustMacro(vec!["a"], ""))
|
||||
)],
|
||||
);
|
||||
assert_eq!(
|
||||
Ast::from_str("{{a !()}}", None, &syntax).unwrap().nodes,
|
||||
[Node::Expr(
|
||||
)
|
||||
],);
|
||||
assert_eq!(Ast::from_str("{{a !()}}", None, &syntax).unwrap().nodes, [
|
||||
Node::Expr(
|
||||
Ws(None, None),
|
||||
WithSpan::no_span(Expr::RustMacro(vec!["a"], ""))
|
||||
)],
|
||||
);
|
||||
assert_eq!(
|
||||
Ast::from_str("{{a! ()}}", None, &syntax).unwrap().nodes,
|
||||
[Node::Expr(
|
||||
)
|
||||
],);
|
||||
assert_eq!(Ast::from_str("{{a! ()}}", None, &syntax).unwrap().nodes, [
|
||||
Node::Expr(
|
||||
Ws(None, None),
|
||||
WithSpan::no_span(Expr::RustMacro(vec!["a"], ""))
|
||||
)],
|
||||
);
|
||||
assert_eq!(
|
||||
Ast::from_str("{{a ! ()}}", None, &syntax).unwrap().nodes,
|
||||
[Node::Expr(
|
||||
)
|
||||
],);
|
||||
assert_eq!(Ast::from_str("{{a ! ()}}", None, &syntax).unwrap().nodes, [
|
||||
Node::Expr(
|
||||
Ws(None, None),
|
||||
WithSpan::no_span(Expr::RustMacro(vec!["a"], ""))
|
||||
)],
|
||||
);
|
||||
assert_eq!(
|
||||
Ast::from_str("{{A!()}}", None, &syntax).unwrap().nodes,
|
||||
[Node::Expr(
|
||||
)
|
||||
],);
|
||||
assert_eq!(Ast::from_str("{{A!()}}", None, &syntax).unwrap().nodes, [
|
||||
Node::Expr(
|
||||
Ws(None, None),
|
||||
WithSpan::no_span(Expr::RustMacro(vec!["A"], ""))
|
||||
)],
|
||||
);
|
||||
)
|
||||
],);
|
||||
assert_eq!(
|
||||
&*Ast::from_str("{{a.b.c!( hello )}}", None, &syntax)
|
||||
.unwrap_err()
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::hint::black_box;
|
||||
use std::iter::repeat;
|
||||
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use criterion::{Criterion, criterion_group, criterion_main};
|
||||
use rinja::Template;
|
||||
|
||||
criterion_main!(benches);
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::collections::HashSet;
|
||||
use std::iter::FusedIterator;
|
||||
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use criterion::{Criterion, black_box, criterion_group, criterion_main};
|
||||
|
||||
criterion_main!(benches);
|
||||
criterion_group!(benches, functions);
|
||||
|
Loading…
x
Reference in New Issue
Block a user