summaryrefslogtreecommitdiff
path: root/cli/tools/lint
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2024-05-30 02:09:16 +0200
committerGitHub <noreply@github.com>2024-05-30 00:09:16 +0000
commite084fe10a98556d4630b54bdda2ce23b3b5b8a60 (patch)
treefe9d25aadc1fdf3884ead22f90595f1f9e1f3e55 /cli/tools/lint
parent13723f267eb87f8c28ef0769cdf7e233b971326e (diff)
feat(lint): add `no-boolean-literal-for-arguments` rule and enable `no-unused-vars` for jsx files (#24034)
* https://github.com/denoland/deno_lint/pull/1271 * https://github.com/denoland/deno_lint/pull/1277 --------- Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/tools/lint')
-rw-r--r--cli/tools/lint/mod.rs31
1 files changed, 26 insertions, 5 deletions
diff --git a/cli/tools/lint/mod.rs b/cli/tools/lint/mod.rs
index aeb919976..7253c99b2 100644
--- a/cli/tools/lint/mod.rs
+++ b/cli/tools/lint/mod.rs
@@ -17,6 +17,7 @@ use deno_core::parking_lot::Mutex;
use deno_core::serde_json;
use deno_graph::FastCheckDiagnostic;
use deno_lint::diagnostic::LintDiagnostic;
+use deno_lint::linter::LintConfig;
use deno_lint::linter::LintFileOptions;
use deno_lint::linter::Linter;
use deno_lint::linter::LinterBuilder;
@@ -79,6 +80,7 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
let factory = CliFactory::from_flags(flags)?;
let cli_options = factory.cli_options();
let lint_options = cli_options.resolve_lint_options(lint_flags)?;
+ let lint_config = cli_options.resolve_lint_config()?;
let files =
collect_lint_files(cli_options, lint_options.files.clone())
.and_then(|files| {
@@ -105,7 +107,7 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
files
};
- lint_files(factory, lint_options, lint_paths).await?;
+ lint_files(factory, lint_options, lint_config, lint_paths).await?;
Ok(())
})
},
@@ -116,6 +118,7 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
let cli_options = factory.cli_options();
let is_stdin = lint_flags.is_stdin();
let lint_options = cli_options.resolve_lint_options(lint_flags)?;
+ let lint_config = cli_options.resolve_lint_config()?;
let files = &lint_options.files;
let success = if is_stdin {
let reporter_kind = lint_options.reporter_kind;
@@ -125,7 +128,7 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
cli_options.maybe_config_file().as_ref(),
)?;
let file_path = cli_options.initial_cwd().join(STDIN_FILE_NAME);
- let r = lint_stdin(&file_path, lint_rules.rules);
+ let r = lint_stdin(&file_path, lint_rules.rules, lint_config);
let success = handle_lint_result(
&file_path.to_string_lossy(),
r,
@@ -143,7 +146,7 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
}
})?;
debug!("Found {} files", target_files.len());
- lint_files(factory, lint_options, target_files).await?
+ lint_files(factory, lint_options, lint_config, target_files).await?
};
if !success {
std::process::exit(1);
@@ -156,6 +159,7 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
async fn lint_files(
factory: CliFactory,
lint_options: LintOptions,
+ lint_config: LintConfig,
paths: Vec<PathBuf>,
) -> Result<bool, AnyError> {
let caches = factory.caches()?;
@@ -221,6 +225,7 @@ async fn lint_files(
let linter = create_linter(lint_rules.rules);
let reporter_lock = reporter_lock.clone();
let incremental_cache = incremental_cache.clone();
+ let lint_config = lint_config.clone();
let fix = lint_options.fix;
deno_core::unsync::spawn(async move {
run_parallelized(paths, {
@@ -232,7 +237,7 @@ async fn lint_files(
return Ok(());
}
- let r = lint_file(&linter, &file_path, file_text, fix);
+ let r = lint_file(&linter, &file_path, file_text, lint_config, fix);
if let Ok((file_source, file_diagnostics)) = &r {
if file_diagnostics.is_empty() {
// update the incremental cache if there were no diagnostics
@@ -335,19 +340,28 @@ fn lint_file(
linter: &Linter,
file_path: &Path,
source_code: String,
+ config: LintConfig,
fix: bool,
) -> Result<(ParsedSource, Vec<LintDiagnostic>), AnyError> {
let specifier = specifier_from_file_path(file_path)?;
let media_type = MediaType::from_specifier(&specifier);
if fix {
- lint_file_and_fix(linter, &specifier, media_type, source_code, file_path)
+ lint_file_and_fix(
+ linter,
+ &specifier,
+ media_type,
+ source_code,
+ file_path,
+ config,
+ )
} else {
linter
.lint_file(LintFileOptions {
specifier,
media_type,
source_code,
+ config,
})
.map_err(AnyError::from)
}
@@ -359,12 +373,14 @@ fn lint_file_and_fix(
media_type: MediaType,
source_code: String,
file_path: &Path,
+ config: LintConfig,
) -> Result<(ParsedSource, Vec<LintDiagnostic>), deno_core::anyhow::Error> {
// initial lint
let (source, diagnostics) = linter.lint_file(LintFileOptions {
specifier: specifier.clone(),
media_type,
source_code,
+ config: config.clone(),
})?;
// Try applying fixes repeatedly until the file has none left or
@@ -379,6 +395,7 @@ fn lint_file_and_fix(
specifier,
media_type,
linter,
+ config.clone(),
source.text_info(),
&diagnostics,
)?;
@@ -417,6 +434,7 @@ fn apply_lint_fixes_and_relint(
specifier: &ModuleSpecifier,
media_type: MediaType,
linter: &Linter,
+ config: LintConfig,
text_info: &SourceTextInfo,
diagnostics: &[LintDiagnostic],
) -> Result<Option<(ParsedSource, Vec<LintDiagnostic>)>, AnyError> {
@@ -428,6 +446,7 @@ fn apply_lint_fixes_and_relint(
specifier: specifier.clone(),
source_code: new_text,
media_type,
+ config,
})
.map(Some)
.context(
@@ -479,6 +498,7 @@ fn apply_lint_fixes(
fn lint_stdin(
file_path: &Path,
lint_rules: Vec<&'static dyn LintRule>,
+ config: LintConfig,
) -> Result<(ParsedSource, Vec<LintDiagnostic>), AnyError> {
let mut source_code = String::new();
if stdin().read_to_string(&mut source_code).is_err() {
@@ -492,6 +512,7 @@ fn lint_stdin(
specifier: specifier_from_file_path(file_path)?,
source_code: source_code.clone(),
media_type: MediaType::TypeScript,
+ config,
})
.map_err(AnyError::from)
}