Skip to content

add option to ignore out of line modules #719

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 1 commit into from
Dec 23, 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
2 changes: 2 additions & 0 deletions src/bin/rustfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ fn lookup_and_read_project_file(input_file: &Path) -> io::Result<(PathBuf, Strin

fn update_config(config: &mut Config, matches: &Matches) {
config.verbose = matches.opt_present("verbose");
config.skip_children = matches.opt_present("skip-children");
}

fn execute() -> i32 {
Expand All @@ -90,6 +91,7 @@ fn execute() -> i32 {
"write-mode",
"mode to write in (not usable when piping from stdin)",
"[replace|overwrite|display|diff|coverage]");
opts.optflag("", "skip-children", "don't reformat child modules");

opts.optflag("",
"config-help",
Expand Down
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ macro_rules! create_config {

create_config! {
verbose: bool, false, "Use verbose output";
skip_children: bool, false, "Don't reformat out of line modules";
max_width: usize, 100, "Maximum width of each line";
ideal_width: usize, 80, "Ideal width of each line";
tab_spaces: usize, 4, "Number of spaces per tab";
Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,15 @@ impl fmt::Display for FormatReport {
// Formatting which depends on the AST.
fn fmt_ast(krate: &ast::Crate,
parse_session: &ParseSess,
main_file: &Path,
config: &Config,
mode: WriteMode)
-> FileMap {
let mut file_map = FileMap::new();
for (path, module) in modules::list_files(krate, parse_session.codemap()) {
if config.skip_children && path.as_path() != main_file {
continue;
}
let path = path.to_str().unwrap();
if config.verbose {
println!("Formatting {}", path);
Expand Down Expand Up @@ -431,7 +435,7 @@ pub fn format(file: &Path, config: &Config, mode: WriteMode) -> FileMap {
let emitter = Box::new(EmitterWriter::new(Box::new(Vec::new()), None));
parse_session.span_diagnostic.handler = Handler::with_emitter(false, emitter);

let mut file_map = fmt_ast(&krate, &parse_session, config, mode);
let mut file_map = fmt_ast(&krate, &parse_session, file, config, mode);

// For some reason, the codemap does not include terminating
// newlines so we must add one on for each file. This is sad.
Expand Down