-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
refactor: redundancy of creating lint instance #23308
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ use deno_lint::linter::Linter; | |
use deno_lint::linter::LinterBuilder; | ||
use deno_lint::rules; | ||
use deno_lint::rules::LintRule; | ||
use lazy_static::lazy_static; | ||
use log::debug; | ||
use log::info; | ||
use serde::Serialize; | ||
|
@@ -34,6 +35,7 @@ use std::path::Path; | |
use std::path::PathBuf; | ||
use std::sync::Arc; | ||
|
||
|
||
use crate::args::CliOptions; | ||
use crate::args::Flags; | ||
use crate::args::LintFlags; | ||
|
@@ -51,10 +53,26 @@ use crate::util::fs::FileCollector; | |
use crate::util::path::is_script_ext; | ||
use crate::util::sync::AtomicFlag; | ||
|
||
|
||
pub mod no_slow_types; | ||
|
||
static STDIN_FILE_NAME: &str = "$deno$stdin.ts"; | ||
|
||
lazy_static! { | ||
static ref LINTER: Mutex<Option<Linter>> = Mutex::new(None); | ||
} | ||
|
||
fn get_linter(lint_rules:LintRule) -> Result<Linter, AnyError> { | ||
let mut linter = LINTER.lock().unwrap(); | ||
if let Some(linter) = &*linter { | ||
return Ok(linter.clone()); | ||
} | ||
|
||
let new_linter = create_linter(lint_rules.rules); | ||
*linter = Some(new_linter.clone()); | ||
Ok(new_linter) | ||
} | ||
|
||
fn create_reporter(kind: LintReporterKind) -> Box<dyn LintReporter + Send> { | ||
match kind { | ||
LintReporterKind::Pretty => Box::new(PrettyLintReporter::new()), | ||
|
@@ -218,7 +236,7 @@ async fn lint_files( | |
|
||
futures.push({ | ||
let has_error = has_error.clone(); | ||
let linter = create_linter(lint_rules.rules); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was only created once. #21876 is out of date and already solved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, sorry @wooseok123, it looks like the previous code below is only creating the linter once for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, thank you for checking that. |
||
let linter = get_linter(lint_rules.clone()); | ||
let reporter_lock = reporter_lock.clone(); | ||
let incremental_cache = incremental_cache.clone(); | ||
let fix = lint_options.fix; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems redundant, you can create it directly in
lint_files
function