]> git.lizzy.rs Git - rust.git/blobdiff - src/config.rs
Implement match_arm_forces_newline option (#2039)
[rust.git] / src / config.rs
index 2fe6d3ea6b633beca3381222e3c2ac4dba8a0400..8c200302c5b0894bb017e22c812231752ba782d6 100644 (file)
 
 extern crate toml;
 
+use std::{env, fs};
 use std::cell::Cell;
-use std::fs;
 use std::fs::File;
-use std::env;
 use std::io::{Error, ErrorKind, Read};
 use std::path::{Path, PathBuf};
 
 use file_lines::FileLines;
-use lists::{SeparatorTactic, ListTactic};
+use lists::{ListTactic, SeparatorPlace, SeparatorTactic};
+use Summary;
 
 macro_rules! configuration_option_enum{
     ($e:ident: $( $x:ident ),+ $(,)*) => {
@@ -273,6 +273,23 @@ pub fn $i(&self) -> bool {
         }
 
         impl Config {
+            pub fn version_meets_requirement(&self, error_summary: &mut Summary) -> bool {
+                if self.was_set().required_version() {
+                    let version = env!("CARGO_PKG_VERSION");
+                    let required_version = self.required_version();
+                    if version != required_version {
+                        println!(
+                            "Error: rustfmt version ({}) doesn't match the required version ({})",
+                            version,
+                            required_version,
+                        );
+                        error_summary.add_formatting_error();
+                        return false;
+                    }
+                }
+
+                true
+            }
 
             $(
             pub fn $i(&self) -> $ty {
@@ -307,7 +324,7 @@ pub fn from_toml(toml: &str) -> Result<Config, String> {
                     let table = parsed
                         .as_table()
                         .ok_or(String::from("Parsed config was not table"))?;
-                    for (key, _) in table {
+                    for key in table.keys() {
                         match &**key {
                             $(
                                 stringify!($i) => (),
@@ -502,6 +519,7 @@ pub fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
          via the --file-lines option";
     max_width: usize, 100, "Maximum width of each line";
     error_on_line_overflow: bool, true, "Error if unable to get all lines within max_width";
+    error_on_line_overflow_comments: bool, true, "Error if unable to get comments within max_width";
     tab_spaces: usize, 4, "Number of spaces per tab";
     fn_call_width: usize, 60,
         "Maximum width of the args of a function call before falling back to vertical formatting";
@@ -519,6 +537,7 @@ pub fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
     impl_empty_single_line: bool, true, "Put empty-body implementations on a single line";
     trailing_comma: SeparatorTactic, SeparatorTactic::Vertical,
         "How to handle trailing commas for lists";
+    trailing_semicolon: bool, true, "Add trailing semicolon after break, continue and return";
     fn_empty_single_line: bool, true, "Put empty-body functions on a single line";
     fn_single_line: bool, false, "Put single-expression functions on a single line";
     fn_return_indent: ReturnIndent, ReturnIndent::WithArgs,
@@ -539,7 +558,7 @@ pub fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
     // 1. Should we at least try to put the where clause on the same line as the rest of the
     // function decl?
     // 2. Currently options `Tall` and `Vertical` produce the same output.
-    where_density: Density, Density::CompressedIfEmpty, "Density of a where clause";
+    where_density: Density, Density::Vertical, "Density of a where clause";
     where_layout: ListTactic, ListTactic::Vertical, "Element layout inside a where clause";
     where_pred_indent: IndentStyle, IndentStyle::Visual,
         "Indentation style of a where predicate";
@@ -556,9 +575,13 @@ pub fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
     chain_one_line_max: usize, 60, "Maximum length of a chain to fit on a single line";
     chain_split_single_child: bool, false, "Split a chain with a single child if its length \
                                             exceeds `chain_one_line_max`";
+    imports_indent: IndentStyle, IndentStyle::Visual, "Indent of imports";
+    imports_layout: ListTactic, ListTactic::Mixed, "Item layout inside a import block";
+    reorder_extern_crates: bool, true, "Reorder extern crate statements alphabetically";
+    reorder_extern_crates_in_group: bool, true, "Reorder extern crate statements in group";
     reorder_imports: bool, false, "Reorder import statements alphabetically";
     reorder_imports_in_group: bool, false, "Reorder import statements in group";
-    reorder_imported_names: bool, false,
+    reorder_imported_names: bool, true,
         "Reorder lists of names in import statements alphabetically";
     single_line_if_else_max_width: usize, 50, "Maximum line length for single line if-else \
                                                 expressions. A value of zero means always break \
@@ -574,8 +597,12 @@ pub fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
                                   the same line with the pattern of arms";
     match_block_trailing_comma: bool, false,
         "Put a trailing comma after a block based match arm (non-block arms are not affected)";
+    match_arm_forces_newline: bool, false,
+        "Force match arm bodies to be in a new lines";
     indent_match_arms: bool, true, "Indent match arms instead of keeping them at the same \
                                     indentation level as the match keyword";
+    match_pattern_separator_break_point: SeparatorPlace, SeparatorPlace::Back,
+        "Put a match sub-patterns' separator in front or back.";
     closure_block_indent_threshold: isize, 7, "How many lines a closure must have before it is \
                                                block indented. -1 means never use block indent.";
     space_before_type_annotation: bool, false,
@@ -594,13 +621,29 @@ pub fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
     spaces_within_square_brackets: bool, false, "Put spaces within non-empty square brackets";
     spaces_within_parens: bool, false, "Put spaces within non-empty parentheses";
     use_try_shorthand: bool, false, "Replace uses of the try! macro by the ? shorthand";
-    write_mode: WriteMode, WriteMode::Replace,
-        "What Write Mode to use when none is supplied: Replace, Overwrite, Display, Diff, Coverage";
+    write_mode: WriteMode, WriteMode::Overwrite,
+        "What Write Mode to use when none is supplied: \
+         Replace, Overwrite, Display, Plain, Diff, Coverage";
     condense_wildcard_suffixes: bool, false, "Replace strings of _ wildcards by a single .. in \
                                               tuple patterns";
-    combine_control_expr: bool, true, "Combine control expressions with funciton calls.";
+    combine_control_expr: bool, true, "Combine control expressions with function calls.";
     struct_field_align_threshold: usize, 0, "Align struct fields if their diffs fits within \
-                                             threshold."
+                                             threshold.";
+    remove_blank_lines_at_start_or_end_of_block: bool, true,
+        "Remove blank lines at start or end of a block";
+    attributes_on_same_line_as_field: bool, true,
+        "Try to put attributes on the same line as fields.";
+    attributes_on_same_line_as_variant: bool, true,
+        "Try to put attributes on the same line as variants in enum declarations.";
+    multiline_closure_forces_block: bool, false,
+        "Force multiline closure bodies to be wrapped in a block";
+    multiline_match_arm_forces_block: bool, false,
+        "Force multiline match arm bodies to be wrapped in a block";
+    merge_derives: bool, true, "Merge multiple `#[derive(...)]` into a single one";
+    binop_separator: SeparatorPlace, SeparatorPlace::Front,
+        "Where to put a binary operator when a binary expression goes multiline.";
+    required_version: String, env!("CARGO_PKG_VERSION").to_owned(),
+        "Require a specific version of rustfmt."
 }
 
 #[cfg(test)]