Skip to content

chore: Upgrade to rustfmt 0.8.6 #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
verbose = false
disable_all_formatting = false
skip_children = false
max_width = 100
error_on_line_overflow = true
tab_spaces = 4
fn_call_width = 60
struct_lit_width = 18
struct_variant_width = 35
force_explicit_abi = true
newline_style = "Unix"
fn_brace_style = "SameLineWhere"
item_brace_style = "SameLineWhere"
control_style = "Legacy"
control_brace_style = "AlwaysSameLine"
impl_empty_single_line = true
trailing_comma = "Vertical"
fn_empty_single_line = true
fn_single_line = false
fn_return_indent = "WithArgs"
fn_args_paren_newline = true
fn_args_density = "Tall"
fn_args_layout = "Visual"
array_layout = "Visual"
array_width = 60
type_punctuation_density = "Wide"
where_style = "Legacy"
where_density = "CompressedIfEmpty"
where_layout = "Vertical"
where_pred_indent = "Visual"
generics_indent = "Visual"
struct_lit_style = "Block"
struct_lit_multiline_style = "PreferSingle"
fn_call_style = "Visual"
report_todo = "Never"
report_fixme = "Never"
chain_indent = "Block"
chain_one_line_max = 60
chain_split_single_child = false
reorder_imports = false
reorder_imports_in_group = false
reorder_imported_names = false
single_line_if_else_max_width = 50
format_strings = false
force_format_strings = false
take_source_hints = false
hard_tabs = false
wrap_comments = false
comment_width = 80
normalize_comments = false
wrap_match_arms = true
match_block_trailing_comma = false
indent_match_arms = true
closure_block_indent_threshold = 7
space_before_type_annotation = false
space_after_type_annotation_colon = true
space_before_struct_lit_field_colon = false
space_after_struct_lit_field_colon = true
space_before_bound = false
space_after_bound_colon = true
spaces_around_ranges = false
spaces_within_angle_brackets = false
spaces_within_square_brackets = false
spaces_within_parens = false
use_try_shorthand = false
write_mode = "Replace"
condense_wildcard_suffixes = false
combine_control_expr = false
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ matrix:
script:
- cargo +nightly-2017-10-09 clippy --features "cli serde_yaml serde_json" -- -D warnings
- rust: stable
env: RUSTFMT=0.8.3
env: RUSTFMT=0.8.6
install:
- if [[ `rustfmt --version` != $RUSTFMT* ]] ; then travis_wait cargo install rustfmt --force --vers $RUSTFMT; fi
- export PATH=$HOME/.cargo/bin:$PATH
Expand Down
12 changes: 6 additions & 6 deletions benches/liquid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ fn bench_parse_variable(b: &mut test::Bencher) {
#[bench]
fn bench_render_variable(b: &mut test::Bencher) {
let options = liquid::LiquidOptions::with_known_blocks();
let template =
liquid::parse(VARIABLE_ONLY, options).expect("Benchmark template parsing failed");
let template = liquid::parse(VARIABLE_ONLY, options)
.expect("Benchmark template parsing failed");

let data: liquid::Object =
serde_yaml::from_str(VARIABLE_ONLY_OBJECT).expect("Benchmark object parsing failed");
let data: liquid::Object = serde_yaml::from_str(VARIABLE_ONLY_OBJECT)
.expect("Benchmark object parsing failed");

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

let data: liquid::Object =
serde_yaml::from_str(ITERATE_OBJECT).expect("Benchmark object parsing failed");
let data: liquid::Object = serde_yaml::from_str(ITERATE_OBJECT)
.expect("Benchmark object parsing failed");

b.iter(|| {
let mut context = liquid::Context::with_values(data.clone());
Expand Down
14 changes: 5 additions & 9 deletions src/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,9 @@ pub fn strip_html(input: &Value, args: &[Value]) -> FilterResult {

let input = input.to_string();

let result = MATCHERS
.iter()
.fold(input,
|acc, matcher| matcher.replace_all(&acc, "").into_owned());
let result = MATCHERS.iter().fold(input, |acc, matcher| {
matcher.replace_all(&acc, "").into_owned()
});
Ok(Str(result))
}

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

let input = input.to_string();
Ok(Str(input
.chars()
.filter(|c| *c != '\n' && *c != '\r')
.collect()))
Ok(Str(input.chars().filter(|c| *c != '\n' && *c != '\r').collect()))
}

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

Expand Down
13 changes: 5 additions & 8 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ pub fn tokenize(text: &str) -> Result<Vec<Element>> {
blocks.push(Tag(try!(granularize(caps.get(1).map(|x| x.as_str()).unwrap_or(""))),
block.to_owned()));
} else if let Some(caps) = EXPRESSION.captures(block) {
blocks.push(Expression(try!(granularize(caps.get(1)
.map(|x| x.as_str())
.unwrap_or(""))),
block.to_owned()));
blocks
.push(Expression(try!(granularize(caps.get(1).map(|x| x.as_str()).unwrap_or(""))),
block.to_owned()));
} else {
blocks.push(Raw(block.to_owned()));
}
Expand Down Expand Up @@ -141,13 +140,11 @@ pub fn granularize(block: &str) -> Result<Vec<Token>> {
}
x if NUMBER_LITERAL.is_match(x) => {
NumberLiteral(x.parse::<f32>()
.expect(&format!("Could not parse {:?} as float",
x)))
.expect(&format!("Could not parse {:?} as float", x)))
}
x if BOOLEAN_LITERAL.is_match(x) => {
BooleanLiteral(x.parse::<bool>()
.expect(&format!("Could not parse {:?} as bool",
x)))
.expect(&format!("Could not parse {:?} as bool", x)))
}
x if IDENTIFIER.is_match(x) => Identifier(x.to_owned()),
x => return Err(Error::Lexer(format!("{} is not a valid identifier", x))),
Expand Down
17 changes: 6 additions & 11 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,17 @@ impl Output {

// apply all specified filters
for filter in &self.filters {
let f = try!(context
.get_filter(&filter.name)
.ok_or_else(|| {
Error::Render(format!("Filter {} not implemented",
&filter.name))
}));
let f = try!(context.get_filter(&filter.name).ok_or_else(|| {
Error::Render(format!("Filter {} not implemented", &filter.name))
}));

let mut arguments = Vec::new();
for arg in &filter.arguments {
match *arg {
Argument::Var(ref x) => {
let val = try!(context.get_val(&*x.name())
.cloned()
.ok_or_else(|| {
Error::Render(format!("undefined variable {}", x.name()))
}));
let val = try!(context.get_val(&*x.name()).cloned().ok_or_else(|| {
Error::Render(format!("undefined variable {}", x.name()))
}));
arguments.push(val);
}
Argument::Val(ref x) => arguments.push(x.clone()),
Expand Down
26 changes: 15 additions & 11 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,19 @@ mod test {
let tokens = granularize("abc | def:'1',2,'3' | blabla").unwrap();

let result = parse_output(&tokens);
assert_eq!(result.unwrap(),
Output::new(Argument::Var(Variable::new("abc")),
vec![FilterPrototype::new("def",
vec![
Argument::Val(Value::str("1")),
Argument::Val(Value::Num(2.0)),
Argument::Val(Value::str("3")),
]),
FilterPrototype::new("blabla", vec![])]));
assert_eq!(
result.unwrap(),
Output::new(
Argument::Var(Variable::new("abc")),
vec![FilterPrototype::new(
"def",
vec![Argument::Val(Value::str("1")),
Argument::Val(Value::Num(2.0)),
Argument::Val(Value::str("3"))]
),
FilterPrototype::new("blabla", vec![])],
)
);
}

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

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

// note that we need an options block that has been initilaised with
// the supported block list; otherwise the split_tag function won't know
Expand Down
5 changes: 1 addition & 4 deletions src/tags/comment_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ mod test {
&[],
&vec![Expression(vec![], "This is a test".to_string())],
&options);
assert_eq!(comment
.unwrap()
.render(&mut Default::default())
.unwrap(),
assert_eq!(comment.unwrap().render(&mut Default::default()).unwrap(),
None);
}
}
6 changes: 3 additions & 3 deletions src/tags/cycle_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ mod test {
"{% cycle 'a': 'one', 'two', 'three' %}\n",
"{% cycle 'b': 'one', 'two', 'three' %}\n",
"{% cycle 'b': 'one', 'two', 'three' %}\n")
.to_owned();
.to_owned();

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

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

let t = parse(&text, Default::default()).unwrap();
let mut context = Context::new();
Expand Down
19 changes: 11 additions & 8 deletions src/tags/for_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ impl Renderable for For {
for (i, v) in slice.iter().enumerate() {
helper_vars.insert("index0".to_owned(), Value::Num(i as f32));
helper_vars.insert("index".to_owned(), Value::Num((i + 1) as f32));
helper_vars.insert("rindex0".to_owned(),
Value::Num((range_len - i - 1) as f32));
helper_vars
.insert("rindex0".to_owned(), Value::Num((range_len - i - 1) as f32));
helper_vars.insert("rindex".to_owned(), Value::Num((range_len - i) as f32));
helper_vars.insert("first".to_owned(), Value::Bool(i == 0));
helper_vars.insert("last".to_owned(), Value::Bool(i == (range_len - 1)));
Expand Down Expand Up @@ -293,7 +293,7 @@ mod test {
">>1:2>>2:0:6,2:1:7,2:2:8,2:3:9,>>2>>\n",
">>2:3>>3:0:6,3:1:7,3:2:8,3:3:9,>>3>>\n",
">>3:4>>4:0:6,4:1:7,4:2:8,4:3:9,>>4>>\n")
.to_owned()));
.to_owned()));
}

#[test]
Expand Down Expand Up @@ -428,17 +428,20 @@ mod test {
"value: {{v}}, ",
"first: {{forloop.first}}, ",
"last: {{forloop.last}}\n"))
.unwrap(),
.unwrap(),
&options);

let mut data: Context = Default::default();
assert_eq!(for_tag.unwrap().render(&mut data).unwrap(),
Some(concat!(
assert_eq!(
for_tag.unwrap().render(&mut data).unwrap(),
Some(
concat!(
"length: 3, index: 1, index0: 0, rindex: 3, rindex0: 2, value: 100, first: true, last: false\n",
"length: 3, index: 2, index0: 1, rindex: 2, rindex0: 1, value: 101, first: false, last: false\n",
"length: 3, index: 3, index0: 2, rindex: 1, rindex0: 0, value: 102, first: false, last: true\n",
)
.to_owned()));
).to_owned(),
)
);
}


Expand Down
16 changes: 8 additions & 8 deletions src/tags/if_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ mod test {
fn number_comparison() {
let a = parse("{% if 6 < 7 %}if true{% endif %}",
LiquidOptions::default())
.unwrap()
.render(&mut Context::new());
.unwrap()
.render(&mut Context::new());
assert_eq!(a.unwrap(), Some("if true".to_owned()));

let b = parse("{% if 7 < 6 %}if true{% else %}if false{% endif %}",
LiquidOptions::default())
.unwrap()
.render(&mut Context::new());
.unwrap()
.render(&mut Context::new());
assert_eq!(b.unwrap(), Some("if false".to_owned()));
}

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

// "one" == "two"
let b = parse("{% if \"one\" == \"two\" %}if true{% endif %}",
LiquidOptions::default())
.unwrap()
.render(&mut Context::new());
.unwrap()
.render(&mut Context::new());
assert_eq!(b.unwrap(), Some("".to_owned()));
}

Expand Down
6 changes: 3 additions & 3 deletions src/tags/interrupt_tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ mod test {
Some(concat!("enter-0; 6, 7, break, exit-0\n",
"enter-1; 6, 7, break, exit-1\n",
"enter-2; 6, 7, break, exit-2\n")
.to_owned()));
.to_owned()));
}

#[test]
Expand All @@ -108,7 +108,7 @@ mod test {
"enter-2;continue-2\n",
"enter-3;exit-3\n",
"enter-4;exit-4\n")
.to_owned()));
.to_owned()));
}

#[test]
Expand All @@ -130,7 +130,7 @@ mod test {
Some(concat!("enter-0; 6, 7, continue, 9, exit-0\n",
"enter-1; 6, 7, continue, 9, exit-1\n",
"enter-2; 6, 7, continue, 9, exit-2\n")
.to_owned()));
.to_owned()));
}


Expand Down
Loading