diff --git a/src/main.rs b/src/main.rs index 5c5e605c15..a84a80f2fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -286,7 +286,7 @@ fn inner_main() -> Result { } // Extract settings for internal use. - let autofix = configuration.fix; + let fix_enabled: bool = configuration.fix; let settings = Settings::from_configuration(configuration); if cli.show_files { @@ -294,12 +294,18 @@ fn inner_main() -> Result { return Ok(ExitCode::SUCCESS); } + // Initialize the cache. + let mut cache_enabled: bool = !cli.no_cache; + #[cfg(not(target_family = "wasm"))] - cache::init()?; + if cache_enabled && cache::init().is_err() { + eprintln!("Unable to initialize cache; disabling..."); + cache_enabled = false; + } let printer = Printer::new(&cli.format, &log_level); if cli.watch { - if autofix { + if fix_enabled { eprintln!("Warning: --fix is not enabled in watch mode."); } @@ -319,7 +325,7 @@ fn inner_main() -> Result { printer.clear_screen()?; printer.write_to_user("Starting linter in watch mode...\n"); - let messages = run_once(&cli.files, &settings, !cli.no_cache, false)?; + let messages = run_once(&cli.files, &settings, cache_enabled, false)?; printer.write_continuously(&messages)?; // Configure the file watcher. @@ -337,7 +343,7 @@ fn inner_main() -> Result { printer.clear_screen()?; printer.write_to_user("File change detected...\n"); - let messages = run_once(&cli.files, &settings, !cli.no_cache, false)?; + let messages = run_once(&cli.files, &settings, cache_enabled, false)?; printer.write_continuously(&messages)?; } } @@ -362,15 +368,15 @@ fn inner_main() -> Result { let messages = if is_stdin { let filename = cli.stdin_filename.unwrap_or_else(|| "-".to_string()); let path = Path::new(&filename); - run_once_stdin(&settings, path, autofix)? + run_once_stdin(&settings, path, fix_enabled)? } else { - run_once(&cli.files, &settings, !cli.no_cache, autofix)? + run_once(&cli.files, &settings, cache_enabled, fix_enabled)? }; // Always try to print violations (the printer itself may suppress output), // unless we're writing fixes via stdin (in which case, the transformed // source code goes to stdout). - if !(is_stdin && autofix) { + if !(is_stdin && fix_enabled) { printer.write_once(&messages)?; }