]> git.lizzy.rs Git - rust.git/commitdiff
add option to ignore out of line modules
authorAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 23 Dec 2015 14:25:49 +0000 (17:25 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 23 Dec 2015 14:25:49 +0000 (17:25 +0300)
src/bin/rustfmt.rs
src/config.rs
src/lib.rs

index 1b54d0d4d06ab4b237c8f63803aa7872f53eb46c..3e369e1ef234edbeddf5c58a112fa8cc378af0d3 100644 (file)
@@ -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 {
@@ -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",
index 4c919191dbdce5c7bb39145f7c23d3066b54b019..804ace83c6d47ab2c6b3e5c24157cafb0dc6704d 100644 (file)
@@ -259,6 +259,7 @@ fn default() -> 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";
index 0ee5f71a35568312bd7e757e3217ce5418aebe5c..bae42ed44fdc7c704769e9715302234496f0dd55 100644 (file)
@@ -298,11 +298,15 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
 // 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);
@@ -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.