Skip to content

Commit 0f49d8d

Browse files
authored
Merge pull request #135 from epage/fix/fmt
chore: Upgrade to rustfmt 0.8.6
2 parents ab258e9 + 1126c57 commit 0f49d8d

17 files changed

+217
-145
lines changed

.rustfmt.toml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
verbose = false
2+
disable_all_formatting = false
3+
skip_children = false
4+
max_width = 100
5+
error_on_line_overflow = true
6+
tab_spaces = 4
7+
fn_call_width = 60
8+
struct_lit_width = 18
9+
struct_variant_width = 35
10+
force_explicit_abi = true
11+
newline_style = "Unix"
12+
fn_brace_style = "SameLineWhere"
13+
item_brace_style = "SameLineWhere"
14+
control_style = "Legacy"
15+
control_brace_style = "AlwaysSameLine"
16+
impl_empty_single_line = true
17+
trailing_comma = "Vertical"
18+
fn_empty_single_line = true
19+
fn_single_line = false
20+
fn_return_indent = "WithArgs"
21+
fn_args_paren_newline = true
22+
fn_args_density = "Tall"
23+
fn_args_layout = "Visual"
24+
array_layout = "Visual"
25+
array_width = 60
26+
type_punctuation_density = "Wide"
27+
where_style = "Legacy"
28+
where_density = "CompressedIfEmpty"
29+
where_layout = "Vertical"
30+
where_pred_indent = "Visual"
31+
generics_indent = "Visual"
32+
struct_lit_style = "Block"
33+
struct_lit_multiline_style = "PreferSingle"
34+
fn_call_style = "Visual"
35+
report_todo = "Never"
36+
report_fixme = "Never"
37+
chain_indent = "Block"
38+
chain_one_line_max = 60
39+
chain_split_single_child = false
40+
reorder_imports = false
41+
reorder_imports_in_group = false
42+
reorder_imported_names = false
43+
single_line_if_else_max_width = 50
44+
format_strings = false
45+
force_format_strings = false
46+
take_source_hints = false
47+
hard_tabs = false
48+
wrap_comments = false
49+
comment_width = 80
50+
normalize_comments = false
51+
wrap_match_arms = true
52+
match_block_trailing_comma = false
53+
indent_match_arms = true
54+
closure_block_indent_threshold = 7
55+
space_before_type_annotation = false
56+
space_after_type_annotation_colon = true
57+
space_before_struct_lit_field_colon = false
58+
space_after_struct_lit_field_colon = true
59+
space_before_bound = false
60+
space_after_bound_colon = true
61+
spaces_around_ranges = false
62+
spaces_within_angle_brackets = false
63+
spaces_within_square_brackets = false
64+
spaces_within_parens = false
65+
use_try_shorthand = false
66+
write_mode = "Replace"
67+
condense_wildcard_suffixes = false
68+
combine_control_expr = false

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ matrix:
1414
script:
1515
- cargo +nightly-2017-10-09 clippy --features "cli serde_yaml serde_json" -- -D warnings
1616
- rust: stable
17-
env: RUSTFMT=0.8.3
17+
env: RUSTFMT=0.8.6
1818
install:
1919
- if [[ `rustfmt --version` != $RUSTFMT* ]] ; then travis_wait cargo install rustfmt --force --vers $RUSTFMT; fi
2020
- export PATH=$HOME/.cargo/bin:$PATH

benches/liquid.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ fn bench_parse_variable(b: &mut test::Bencher) {
5252
#[bench]
5353
fn bench_render_variable(b: &mut test::Bencher) {
5454
let options = liquid::LiquidOptions::with_known_blocks();
55-
let template =
56-
liquid::parse(VARIABLE_ONLY, options).expect("Benchmark template parsing failed");
55+
let template = liquid::parse(VARIABLE_ONLY, options)
56+
.expect("Benchmark template parsing failed");
5757

58-
let data: liquid::Object =
59-
serde_yaml::from_str(VARIABLE_ONLY_OBJECT).expect("Benchmark object parsing failed");
58+
let data: liquid::Object = serde_yaml::from_str(VARIABLE_ONLY_OBJECT)
59+
.expect("Benchmark object parsing failed");
6060

6161
b.iter(|| {
6262
let mut context = liquid::Context::with_values(data.clone());
@@ -106,8 +106,8 @@ fn bench_render_template(b: &mut test::Bencher) {
106106
let options = liquid::LiquidOptions::with_known_blocks();
107107
let template = liquid::parse(ITERATE, options).expect("Benchmark template parsing failed");
108108

109-
let data: liquid::Object =
110-
serde_yaml::from_str(ITERATE_OBJECT).expect("Benchmark object parsing failed");
109+
let data: liquid::Object = serde_yaml::from_str(ITERATE_OBJECT)
110+
.expect("Benchmark object parsing failed");
111111

112112
b.iter(|| {
113113
let mut context = liquid::Context::with_values(data.clone());

src/filters.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,9 @@ pub fn strip_html(input: &Value, args: &[Value]) -> FilterResult {
428428

429429
let input = input.to_string();
430430

431-
let result = MATCHERS
432-
.iter()
433-
.fold(input,
434-
|acc, matcher| matcher.replace_all(&acc, "").into_owned());
431+
let result = MATCHERS.iter().fold(input, |acc, matcher| {
432+
matcher.replace_all(&acc, "").into_owned()
433+
});
435434
Ok(Str(result))
436435
}
437436

@@ -440,10 +439,7 @@ pub fn strip_newlines(input: &Value, args: &[Value]) -> FilterResult {
440439
try!(check_args_len(args, 0, 0));
441440

442441
let input = input.to_string();
443-
Ok(Str(input
444-
.chars()
445-
.filter(|c| *c != '\n' && *c != '\r')
446-
.collect()))
442+
Ok(Str(input.chars().filter(|c| *c != '\n' && *c != '\r').collect()))
447443
}
448444

449445
pub fn join(input: &Value, args: &[Value]) -> FilterResult {
@@ -1142,7 +1138,7 @@ mod tests {
11421138
let args = &[tos!("%Y-%m-%d %H:%M:%S %z"), Num(0f32)];
11431139
let desired_result = FilterError::InvalidType("Invalid date format: input contains \
11441140
invalid characters"
1145-
.to_owned());
1141+
.to_owned());
11461142
assert_eq!(failed!(date_in_tz, input, args), desired_result);
11471143
}
11481144

src/lexer.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ pub fn tokenize(text: &str) -> Result<Vec<Element>> {
6464
blocks.push(Tag(try!(granularize(caps.get(1).map(|x| x.as_str()).unwrap_or(""))),
6565
block.to_owned()));
6666
} else if let Some(caps) = EXPRESSION.captures(block) {
67-
blocks.push(Expression(try!(granularize(caps.get(1)
68-
.map(|x| x.as_str())
69-
.unwrap_or(""))),
70-
block.to_owned()));
67+
blocks
68+
.push(Expression(try!(granularize(caps.get(1).map(|x| x.as_str()).unwrap_or(""))),
69+
block.to_owned()));
7170
} else {
7271
blocks.push(Raw(block.to_owned()));
7372
}
@@ -141,13 +140,11 @@ pub fn granularize(block: &str) -> Result<Vec<Token>> {
141140
}
142141
x if NUMBER_LITERAL.is_match(x) => {
143142
NumberLiteral(x.parse::<f32>()
144-
.expect(&format!("Could not parse {:?} as float",
145-
x)))
143+
.expect(&format!("Could not parse {:?} as float", x)))
146144
}
147145
x if BOOLEAN_LITERAL.is_match(x) => {
148146
BooleanLiteral(x.parse::<bool>()
149-
.expect(&format!("Could not parse {:?} as bool",
150-
x)))
147+
.expect(&format!("Could not parse {:?} as bool", x)))
151148
}
152149
x if IDENTIFIER.is_match(x) => Identifier(x.to_owned()),
153150
x => return Err(Error::Lexer(format!("{} is not a valid identifier", x))),

src/output.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,17 @@ impl Output {
6060

6161
// apply all specified filters
6262
for filter in &self.filters {
63-
let f = try!(context
64-
.get_filter(&filter.name)
65-
.ok_or_else(|| {
66-
Error::Render(format!("Filter {} not implemented",
67-
&filter.name))
68-
}));
63+
let f = try!(context.get_filter(&filter.name).ok_or_else(|| {
64+
Error::Render(format!("Filter {} not implemented", &filter.name))
65+
}));
6966

7067
let mut arguments = Vec::new();
7168
for arg in &filter.arguments {
7269
match *arg {
7370
Argument::Var(ref x) => {
74-
let val = try!(context.get_val(&*x.name())
75-
.cloned()
76-
.ok_or_else(|| {
77-
Error::Render(format!("undefined variable {}", x.name()))
78-
}));
71+
let val = try!(context.get_val(&*x.name()).cloned().ok_or_else(|| {
72+
Error::Render(format!("undefined variable {}", x.name()))
73+
}));
7974
arguments.push(val);
8075
}
8176
Argument::Val(ref x) => arguments.push(x.clone()),

src/parser.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,19 @@ mod test {
266266
let tokens = granularize("abc | def:'1',2,'3' | blabla").unwrap();
267267

268268
let result = parse_output(&tokens);
269-
assert_eq!(result.unwrap(),
270-
Output::new(Argument::Var(Variable::new("abc")),
271-
vec![FilterPrototype::new("def",
272-
vec![
273-
Argument::Val(Value::str("1")),
274-
Argument::Val(Value::Num(2.0)),
275-
Argument::Val(Value::str("3")),
276-
]),
277-
FilterPrototype::new("blabla", vec![])]));
269+
assert_eq!(
270+
result.unwrap(),
271+
Output::new(
272+
Argument::Var(Variable::new("abc")),
273+
vec![FilterPrototype::new(
274+
"def",
275+
vec![Argument::Val(Value::str("1")),
276+
Argument::Val(Value::Num(2.0)),
277+
Argument::Val(Value::str("3"))]
278+
),
279+
FilterPrototype::new("blabla", vec![])],
280+
)
281+
);
278282
}
279283

280284
#[test]
@@ -331,7 +335,7 @@ mod test {
331335
// top level, which is where it should split.
332336
let tokens = tokenize("{% comment %}A{%endcomment%} bunch of {{text}} with {{no}} \
333337
else tag")
334-
.unwrap();
338+
.unwrap();
335339

336340
// note that we need an options block that has been initilaised with
337341
// the supported block list; otherwise the split_tag function won't know
@@ -360,7 +364,7 @@ mod test {
360364
"{% endfor %}",
361365
"{% else %}",
362366
"trailing tags"))
363-
.unwrap();
367+
.unwrap();
364368

365369
// note that we need an options block that has been initilaised with
366370
// the supported block list; otherwise the split_tag function won't know

src/tags/comment_block.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ mod test {
3535
&[],
3636
&vec![Expression(vec![], "This is a test".to_string())],
3737
&options);
38-
assert_eq!(comment
39-
.unwrap()
40-
.render(&mut Default::default())
41-
.unwrap(),
38+
assert_eq!(comment.unwrap().render(&mut Default::default()).unwrap(),
4239
None);
4340
}
4441
}

src/tags/cycle_tag.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ mod test {
103103
"{% cycle 'a': 'one', 'two', 'three' %}\n",
104104
"{% cycle 'b': 'one', 'two', 'three' %}\n",
105105
"{% cycle 'b': 'one', 'two', 'three' %}\n")
106-
.to_owned();
106+
.to_owned();
107107

108108
let t = parse(&text, Default::default()).unwrap();
109109
let mut context = Context::new();
@@ -122,7 +122,7 @@ mod test {
122122
"{% cycle 'one', 'two', 'three' %}\n",
123123
"{% cycle 'one', 'two', 'three' %}\n",
124124
"{% cycle 'one', 'two', 'three' %}\n")
125-
.to_owned();
125+
.to_owned();
126126

127127
let t = parse(&text, Default::default()).unwrap();
128128
let mut context = Context::new();
@@ -142,7 +142,7 @@ mod test {
142142
"{% cycle alpha, beta, gamma %}\n",
143143
"{% cycle alpha, beta, gamma %}\n",
144144
"{% cycle alpha, beta, gamma %}\n")
145-
.to_owned();
145+
.to_owned();
146146

147147
let t = parse(&text, Default::default()).unwrap();
148148
let mut context = Context::new();

src/tags/for_block.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ impl Renderable for For {
8888
for (i, v) in slice.iter().enumerate() {
8989
helper_vars.insert("index0".to_owned(), Value::Num(i as f32));
9090
helper_vars.insert("index".to_owned(), Value::Num((i + 1) as f32));
91-
helper_vars.insert("rindex0".to_owned(),
92-
Value::Num((range_len - i - 1) as f32));
91+
helper_vars
92+
.insert("rindex0".to_owned(), Value::Num((range_len - i - 1) as f32));
9393
helper_vars.insert("rindex".to_owned(), Value::Num((range_len - i) as f32));
9494
helper_vars.insert("first".to_owned(), Value::Bool(i == 0));
9595
helper_vars.insert("last".to_owned(), Value::Bool(i == (range_len - 1)));
@@ -293,7 +293,7 @@ mod test {
293293
">>1:2>>2:0:6,2:1:7,2:2:8,2:3:9,>>2>>\n",
294294
">>2:3>>3:0:6,3:1:7,3:2:8,3:3:9,>>3>>\n",
295295
">>3:4>>4:0:6,4:1:7,4:2:8,4:3:9,>>4>>\n")
296-
.to_owned()));
296+
.to_owned()));
297297
}
298298

299299
#[test]
@@ -428,17 +428,20 @@ mod test {
428428
"value: {{v}}, ",
429429
"first: {{forloop.first}}, ",
430430
"last: {{forloop.last}}\n"))
431-
.unwrap(),
431+
.unwrap(),
432432
&options);
433433

434434
let mut data: Context = Default::default();
435-
assert_eq!(for_tag.unwrap().render(&mut data).unwrap(),
436-
Some(concat!(
435+
assert_eq!(
436+
for_tag.unwrap().render(&mut data).unwrap(),
437+
Some(
438+
concat!(
437439
"length: 3, index: 1, index0: 0, rindex: 3, rindex0: 2, value: 100, first: true, last: false\n",
438440
"length: 3, index: 2, index0: 1, rindex: 2, rindex0: 1, value: 101, first: false, last: false\n",
439441
"length: 3, index: 3, index0: 2, rindex: 1, rindex0: 0, value: 102, first: false, last: true\n",
440-
)
441-
.to_owned()));
442+
).to_owned(),
443+
)
444+
);
442445
}
443446

444447

src/tags/if_block.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,14 @@ mod test {
144144
fn number_comparison() {
145145
let a = parse("{% if 6 < 7 %}if true{% endif %}",
146146
LiquidOptions::default())
147-
.unwrap()
148-
.render(&mut Context::new());
147+
.unwrap()
148+
.render(&mut Context::new());
149149
assert_eq!(a.unwrap(), Some("if true".to_owned()));
150150

151151
let b = parse("{% if 7 < 6 %}if true{% else %}if false{% endif %}",
152152
LiquidOptions::default())
153-
.unwrap()
154-
.render(&mut Context::new());
153+
.unwrap()
154+
.render(&mut Context::new());
155155
assert_eq!(b.unwrap(), Some("if false".to_owned()));
156156
}
157157

@@ -160,15 +160,15 @@ mod test {
160160
// "one" == "one" then "if true" else "if false"
161161
let a = parse("{% if \"one\" == \"one\" %}if true{% endif %}",
162162
LiquidOptions::default())
163-
.unwrap()
164-
.render(&mut Context::new());
163+
.unwrap()
164+
.render(&mut Context::new());
165165
assert_eq!(a.unwrap(), Some("if true".to_owned()));
166166

167167
// "one" == "two"
168168
let b = parse("{% if \"one\" == \"two\" %}if true{% endif %}",
169169
LiquidOptions::default())
170-
.unwrap()
171-
.render(&mut Context::new());
170+
.unwrap()
171+
.render(&mut Context::new());
172172
assert_eq!(b.unwrap(), Some("".to_owned()));
173173
}
174174

src/tags/interrupt_tags.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ mod test {
8888
Some(concat!("enter-0; 6, 7, break, exit-0\n",
8989
"enter-1; 6, 7, break, exit-1\n",
9090
"enter-2; 6, 7, break, exit-2\n")
91-
.to_owned()));
91+
.to_owned()));
9292
}
9393

9494
#[test]
@@ -108,7 +108,7 @@ mod test {
108108
"enter-2;continue-2\n",
109109
"enter-3;exit-3\n",
110110
"enter-4;exit-4\n")
111-
.to_owned()));
111+
.to_owned()));
112112
}
113113

114114
#[test]
@@ -130,7 +130,7 @@ mod test {
130130
Some(concat!("enter-0; 6, 7, continue, 9, exit-0\n",
131131
"enter-1; 6, 7, continue, 9, exit-1\n",
132132
"enter-2; 6, 7, continue, 9, exit-2\n")
133-
.to_owned()));
133+
.to_owned()));
134134
}
135135

136136

0 commit comments

Comments
 (0)