Skip to content

Block indent large closures and field/method chains #960

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 9 commits into from
Apr 27, 2016
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
18 changes: 18 additions & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Make sure you double check the diffs after running this script - with great
# power comes great responsibility.
# We deliberately avoid reformatting files with rustfmt comment directives.

cargo build

target/debug/rustfmt --write-mode=overwrite src/lib.rs
target/debug/rustfmt --write-mode=overwrite src/bin/rustfmt.rs
target/debug/rustfmt --write-mode=overwrite src/bin/cargo-fmt.rs
target/debug/rustfmt --write-mode=overwrite tests/system.rs

for filename in tests/target/*.rs; do
if ! grep -q "rustfmt-" "$filename"; then
target/debug/rustfmt --write-mode=overwrite $filename
fi
done
24 changes: 12 additions & 12 deletions src/bin/cargo-fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ fn format_crate(verbosity: Verbosity) -> Result<ExitStatus, std::io::Error> {

// Currently only bin and lib files get formatted
let files: Vec<_> = targets.into_iter()
.filter(|t| t.kind.is_lib() | t.kind.is_bin())
.inspect(|t| {
if verbosity == Verbosity::Verbose {
println!("[{:?}] {:?}", t.kind, t.path)
}
})
.map(|t| t.path)
.collect();
.filter(|t| t.kind.is_lib() | t.kind.is_bin())
.inspect(|t| {
if verbosity == Verbosity::Verbose {
println!("[{:?}] {:?}", t.kind, t.path)
}
})
.map(|t| t.path)
.collect();

format_files(&files, &get_fmt_args(), verbosity)
}
Expand Down Expand Up @@ -201,9 +201,9 @@ fn format_files(files: &Vec<PathBuf>,
println!("");
}
let mut command = try!(Command::new("rustfmt")
.stdout(stdout)
.args(files)
.args(fmt_args)
.spawn());
.stdout(stdout)
.args(files)
.args(fmt_args)
.spawn());
command.wait()
}
23 changes: 10 additions & 13 deletions src/bin/rustfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
Operation::Stdin { input, config_path } => {
// try to read config from local directory
let (mut config, _) = match_cli_path_or_file(config_path, &env::current_dir().unwrap())
.expect("Error resolving config");
.expect("Error resolving config");

// write_mode is always Plain for Stdin.
config.write_mode = WriteMode::Plain;
Expand All @@ -205,8 +205,7 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
// Load the config path file if provided
if let Some(config_file) = config_path {
let (cfg_tmp, path_tmp) = resolve_config(config_file.as_ref())
.expect(&format!("Error resolving config for {:?}",
config_file));
.expect(&format!("Error resolving config for {:?}", config_file));
config = cfg_tmp;
path = path_tmp;
};
Expand All @@ -219,9 +218,7 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
// Check the file directory if the config-path could not be read or not provided
if path.is_none() {
let (config_tmp, path_tmp) = resolve_config(file.parent().unwrap())
.expect(&format!("Error resolving config \
for {}",
file.display()));
.expect(&format!("Error resolving config for {}", file.display()));
if let Some(path) = path_tmp.as_ref() {
println!("Using rustfmt config file {} for {}",
path.display(),
Expand Down Expand Up @@ -301,13 +298,13 @@ fn determine_operation(matches: &Matches) -> FmtResult<Operation> {

// Read the config_path and convert to parent dir if a file is provided.
let config_path: Option<PathBuf> = matches.opt_str("config-path")
.map(PathBuf::from)
.and_then(|dir| {
if dir.is_file() {
return dir.parent().map(|v| v.into());
}
Some(dir)
});
.map(PathBuf::from)
.and_then(|dir| {
if dir.is_file() {
return dir.parent().map(|v| v.into());
}
Some(dir)
});

// if no file argument is supplied, read from stdin
if matches.free.is_empty() {
Expand Down
Loading