Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion cli/tools/lint/mod.rs
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}
Copy link
Member

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


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()),
Expand Down Expand Up @@ -218,7 +236,7 @@ async fn lint_files(

futures.push({
let has_error = has_error.clone();
let linter = create_linter(lint_rules.rules);
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The 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 run_parallelized

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thank you for checking that.
I think it needs to add more test code though.
Making a seperate PR for that would be better?

let linter = get_linter(lint_rules.clone());
let reporter_lock = reporter_lock.clone();
let incremental_cache = incremental_cache.clone();
let fix = lint_options.fix;
Expand Down