diff options
author | Zheyu Zhang <zheyuzhang03@gmail.com> | 2022-02-01 00:39:39 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-31 17:39:39 +0100 |
commit | 5490cfed2000a063ef0baec500ab7d539203067c (patch) | |
tree | d121da8ad8274de65f77fbced5f452ecb1d7881a /cli/tools/lint.rs | |
parent | 3e566bb457663cec57602e564f73ded817e426a8 (diff) |
feat(cli): add "--no-clear-screen" flag (#13454)
This commit adds "--no-clear-screen" flag which can be used
with "--watch" flag to disable clearing of terminal screen on
each file change.
Diffstat (limited to 'cli/tools/lint.rs')
-rw-r--r-- | cli/tools/lint.rs | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/cli/tools/lint.rs b/cli/tools/lint.rs index b103550e2..74c5540fc 100644 --- a/cli/tools/lint.rs +++ b/cli/tools/lint.rs @@ -8,9 +8,10 @@ //! the same functions as ops available in JS runtime. use crate::config_file::LintConfig; use crate::file_watcher::ResolutionResult; -use crate::flags::LintFlags; +use crate::flags::{Flags, LintFlags}; use crate::fmt_errors; use crate::fs_util::{collect_files, is_supported_ext, specifier_to_file_path}; +use crate::proc_state::ProcState; use crate::tools::fmt::run_parallelized; use crate::{colors, file_watcher}; use deno_ast::MediaType; @@ -48,11 +49,7 @@ fn create_reporter(kind: LintReporterKind) -> Box<dyn LintReporter + Send> { } } -pub async fn lint( - maybe_lint_config: Option<LintConfig>, - lint_flags: LintFlags, - watch: bool, -) -> Result<(), AnyError> { +pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> { let LintFlags { maybe_rules_tags, maybe_rules_include, @@ -69,6 +66,13 @@ pub async fn lint( let mut include_files = args.clone(); let mut exclude_files = ignore.clone(); + let ps = ProcState::build(flags.clone()).await?; + let maybe_lint_config = if let Some(config_file) = &ps.maybe_config_file { + config_file.to_lint_config()? + } else { + None + }; + if let Some(lint_config) = maybe_lint_config.as_ref() { if include_files.is_empty() { include_files = lint_config @@ -166,13 +170,21 @@ pub async fn lint( Ok(()) }; - if watch { + if flags.watch.is_some() { if args.len() == 1 && args[0].to_string_lossy() == "-" { return Err(generic_error( "Lint watch on standard input is not supported.", )); } - file_watcher::watch_func(resolver, operation, "Lint").await?; + file_watcher::watch_func( + resolver, + operation, + file_watcher::PrintConfig { + job_name: "Lint".to_string(), + clear_screen: !flags.no_clear_screen, + }, + ) + .await?; } else { if args.len() == 1 && args[0].to_string_lossy() == "-" { let reporter_lock = |