Skip to content

Format if expressions & loops #147

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 5 commits into from
Jul 24, 2015
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
8 changes: 5 additions & 3 deletions src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ pub fn rewrite_comment(orig: &str, block_style: bool, width: usize, offset: usiz
let s = orig.trim();

// Edge case: block comments. Let's not trim their lines (for now).
let opener = if block_style { "/* " } else { "// " };
let closer = if block_style { " */" } else { "" };
let line_start = if block_style { " * " } else { "// " };
let (opener, closer, line_start) = if block_style {
("/* ", " */", " * ")
} else {
("// ", "", "// ")
};

let max_chars = width.checked_sub(closer.len()).unwrap_or(1)
.checked_sub(opener.len()).unwrap_or(1);
Expand Down
13 changes: 13 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ use {NewlineStyle, BraceStyle, ReturnIndent, StructLitStyle};
use lists::SeparatorTactic;
use issues::ReportTactic;

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum BlockIndentStyle {
// Same level as parent.
Inherit,
// One level deeper than parent.
Tabbed,
// Aligned with block open.
Visual,
}

impl_enum_decodable!(BlockIndentStyle, Inherit, Tabbed, Visual);

#[derive(RustcDecodable, Clone)]
pub struct Config {
pub max_width: usize,
Expand All @@ -31,6 +43,7 @@ pub struct Config {
pub report_todo: ReportTactic,
pub report_fixme: ReportTactic,
pub reorder_imports: bool, // Alphabetically, case sensitive.
pub expr_indent_style: BlockIndentStyle,
}

impl Config {
Expand Down
1 change: 1 addition & 0 deletions src/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ enum_trailing_comma = true
report_todo = "Always"
report_fixme = "Never"
reorder_imports = false
expr_indent_style = "Tabbed"
Loading