From 395d4efcf94a26353d766f2596f0e932bcc36dfe Mon Sep 17 00:00:00 2001
From: Michael Aaron Murphy <mmstickman@gmail.com>
Date: Sun, 17 Mar 2019 05:02:36 +0000
Subject: [PATCH] Require cargo fmt

---
 .gitlab-ci.yml                    |  6 ++++
 Makefile                          |  3 ++
 members/ranges/src/parse.rs       |  9 +++--
 src/lib/parser/quotes.rs          |  2 +-
 src/lib/parser/statement/parse.rs | 57 +++++++++++++++----------------
 5 files changed, 44 insertions(+), 33 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index dc63a97c..6d656420 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -10,6 +10,12 @@ cache:
     - cargo/
     - target/
 
+format:
+  script:
+    - rustup default nightly
+    - rustup component add rustfmt
+    - cargo +nightly fmt --all -- --check
+
 linux:
   image: 'rust:1.31.0'
   script:
diff --git a/Makefile b/Makefile
index 491a7dae..0db018dc 100644
--- a/Makefile
+++ b/Makefile
@@ -40,6 +40,9 @@ clean:
 distclean: clean
 	rm -rf vendor vendor.tar.xz .cargo git_revision.txt
 
+format:
+	cargo +nightly fmt --all
+
 tests:
 	cargo +$(TOOLCHAIN) test $(ARGSV)
 	TOOLCHAIN=$(TOOLCHAIN) bash examples/run_examples.sh
diff --git a/members/ranges/src/parse.rs b/members/ranges/src/parse.rs
index bf746a7d..6503d830 100644
--- a/members/ranges/src/parse.rs
+++ b/members/ranges/src/parse.rs
@@ -97,8 +97,13 @@ fn count_minimum_digits(a: &str) -> usize {
     0
 }
 
-fn finish(inclusive: bool, start_str: &str, end_str: &str, step: isize) -> Option<Box<Iterator<Item = small::String>>> {
-    if let (Ok(start), Ok(end)) = (start_str.parse::<isize>(), end_str.parse::<isize>())  {
+fn finish(
+    inclusive: bool,
+    start_str: &str,
+    end_str: &str,
+    step: isize,
+) -> Option<Box<Iterator<Item = small::String>>> {
+    if let (Ok(start), Ok(end)) = (start_str.parse::<isize>(), end_str.parse::<isize>()) {
         let step = if step == 1 && start >= end { -step } else { step };
         let nb_digits = usize::max(count_minimum_digits(start_str), count_minimum_digits(end_str));
         numeric_range(start, end, step, inclusive, nb_digits)
diff --git a/src/lib/parser/quotes.rs b/src/lib/parser/quotes.rs
index e85c0625..d3275de5 100644
--- a/src/lib/parser/quotes.rs
+++ b/src/lib/parser/quotes.rs
@@ -177,7 +177,7 @@ impl<I: Iterator<Item = u8>> Terminator<I> {
                             .filter(|&c| ![b' ', b'\n'].contains(c))
                             .is_none() =>
                         {
-                            return self.inner.find(|&c| c == b'\n')
+                            return self.inner.find(|&c| c == b'\n');
                         }
                         b'\\' => {
                             if self.inner.peek() == Some(&b'\n') {
diff --git a/src/lib/parser/statement/parse.rs b/src/lib/parser/statement/parse.rs
index 8a68a3bf..c1c81114 100644
--- a/src/lib/parser/statement/parse.rs
+++ b/src/lib/parser/statement/parse.rs
@@ -38,16 +38,18 @@ pub(crate) fn parse(code: &str) -> Statement {
             eprintln!("ion: syntax error: incomplete control flow statement");
             Statement::Error(FAILURE)
         }
-        "let" => {
-            Statement::Let(LocalAction::List)
-        }
+        "let" => Statement::Let(LocalAction::List),
         _ if cmd.starts_with("let ") => {
             // Split the let expression and ensure that the statement is valid.
             let (keys, op, vals) = assignment_lexer(cmd[4..].trim_start());
             match vals {
                 Some(vals) => {
                     // If the values exist, then the keys and operator also exists.
-                    Statement::Let(LocalAction::Assign(keys.unwrap().into(), op.unwrap(), vals.into()))
+                    Statement::Let(LocalAction::Assign(
+                        keys.unwrap().into(),
+                        op.unwrap(),
+                        vals.into(),
+                    ))
                 }
                 None => {
                     if op.is_none() {
@@ -59,16 +61,18 @@ pub(crate) fn parse(code: &str) -> Statement {
                 }
             }
         }
-        "export" => {
-            Statement::Export(ExportAction::List)
-        }
+        "export" => Statement::Export(ExportAction::List),
         _ if cmd.starts_with("export ") => {
             // Split the let expression and ensure that the statement is valid.
             let (keys, op, vals) = assignment_lexer(cmd[7..].trim_start());
             match vals {
                 Some(vals) => {
                     // If the values exist, then the keys and operator also exists.
-                    Statement::Export(ExportAction::Assign(keys.unwrap().into(), op.unwrap(), vals.into()))
+                    Statement::Export(ExportAction::Assign(
+                        keys.unwrap().into(),
+                        op.unwrap(),
+                        vals.into(),
+                    ))
                 }
                 None => {
                     if keys.is_none() {
@@ -82,19 +86,17 @@ pub(crate) fn parse(code: &str) -> Statement {
                 }
             }
         }
-        _ if cmd.starts_with("if ") => {
-            Statement::If {
-                expression: vec![parse(cmd[3..].trim_start())],
-                success:    Vec::new(),
-                else_if:    Vec::new(),
-                failure:    Vec::new(),
-                mode:       0,
-            }
-        }
+        _ if cmd.starts_with("if ") => Statement::If {
+            expression: vec![parse(cmd[3..].trim_start())],
+            success:    Vec::new(),
+            else_if:    Vec::new(),
+            failure:    Vec::new(),
+            mode:       0,
+        },
         "else" => Statement::Else,
         _ if cmd.starts_with("else") => {
             let cmd = cmd[4..].trim_start();
-            if !cmd.is_empty() && cmd.starts_with("if ")  {
+            if !cmd.is_empty() && cmd.starts_with("if ") {
                 Statement::ElseIf(ElseIf {
                     expression: vec![parse(cmd[3..].trim_start())],
                     success:    Vec::new(),
@@ -161,10 +163,7 @@ pub(crate) fn parse(code: &str) -> Statement {
             Statement::Case(Case { value, binding, conditional, statements: Vec::new() })
         }
         _ if cmd.starts_with("match ") => {
-            Statement::Match {
-                expression: cmd[6..].trim_start().into(),
-                cases:      Vec::new(),
-            }
+            Statement::Match { expression: cmd[6..].trim_start().into(), cases: Vec::new() }
         }
         _ if cmd.starts_with("fn ") => {
             let cmd = cmd[3..].trim_start();
@@ -181,14 +180,12 @@ pub(crate) fn parse(code: &str) -> Statement {
 
             let (args, description) = parse_function(&cmd[pos..]);
             match collect_arguments(args) {
-                Ok(args) => {
-                    Statement::Function {
-                        description: description.map(small::String::from),
-                        name: name.into(),
-                        args,
-                        statements: Vec::new(),
-                    }
-                }
+                Ok(args) => Statement::Function {
+                    description: description.map(small::String::from),
+                    name: name.into(),
+                    args,
+                    statements: Vec::new(),
+                },
                 Err(why) => {
                     eprintln!("ion: function argument error: {}", why);
                     Statement::Error(FAILURE)
-- 
GitLab