diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-07-25 09:07:59 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-25 09:07:59 -0400 |
commit | 763f05e74dfd0032b238603f625893a52e363591 (patch) | |
tree | c6a71559472755919358afa53eecac206cad80a9 /cli/lsp/analysis.rs | |
parent | ef78d317f084ffe633253acd138a48a425113fa7 (diff) |
fix(unstable): move sloppy-import warnings to lint rule (#24710)
Adds a new `no-sloppy-imports` lint rule and cleans up the lint code.
Closes #22844
Closes https://github.com/denoland/deno_lint/issues/1293
Diffstat (limited to 'cli/lsp/analysis.rs')
-rw-r--r-- | cli/lsp/analysis.rs | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/cli/lsp/analysis.rs b/cli/lsp/analysis.rs index a6a69cbf0..97730ac7e 100644 --- a/cli/lsp/analysis.rs +++ b/cli/lsp/analysis.rs @@ -8,8 +8,8 @@ use super::resolver::LspResolver; use super::tsc; use crate::args::jsr_url; -use crate::tools::lint::create_linter; -use deno_lint::linter::LintConfig; +use crate::tools::lint::CliLinter; +use deno_lint::diagnostic::LintDiagnosticRange; use deno_runtime::fs_util::specifier_to_file_path; use deno_ast::SourceRange; @@ -23,8 +23,6 @@ use deno_core::serde::Serialize; use deno_core::serde_json; use deno_core::serde_json::json; use deno_core::ModuleSpecifier; -use deno_lint::diagnostic::LintDiagnostic; -use deno_lint::rules::LintRule; use deno_runtime::deno_node::NpmResolver; use deno_runtime::deno_node::PathClean; use deno_semver::jsr::JsrPackageNvReference; @@ -149,8 +147,10 @@ impl Reference { } } -fn as_lsp_range_from_diagnostic(diagnostic: &LintDiagnostic) -> Range { - as_lsp_range(diagnostic.range, &diagnostic.text_info) +fn as_lsp_range_from_lint_diagnostic( + diagnostic_range: &LintDiagnosticRange, +) -> Range { + as_lsp_range(diagnostic_range.range, &diagnostic_range.text_info) } fn as_lsp_range( @@ -173,37 +173,39 @@ fn as_lsp_range( pub fn get_lint_references( parsed_source: &deno_ast::ParsedSource, - lint_rules: Vec<&'static dyn LintRule>, - lint_config: LintConfig, + linter: &CliLinter, ) -> Result<Vec<Reference>, AnyError> { - let linter = create_linter(lint_rules); - let lint_diagnostics = linter.lint_with_ast(parsed_source, lint_config); + let lint_diagnostics = linter.lint_with_ast(parsed_source); Ok( lint_diagnostics .into_iter() - .map(|d| Reference { - range: as_lsp_range_from_diagnostic(&d), - category: Category::Lint { - message: d.message, - code: d.code, - hint: d.hint, - quick_fixes: d - .fixes - .into_iter() - .map(|f| DataQuickFix { - description: f.description.to_string(), - changes: f - .changes - .into_iter() - .map(|change| DataQuickFixChange { - range: as_lsp_range(change.range, &d.text_info), - new_text: change.new_text.to_string(), - }) - .collect(), - }) - .collect(), - }, + .filter_map(|d| { + let range = d.range.as_ref()?; + Some(Reference { + range: as_lsp_range_from_lint_diagnostic(range), + category: Category::Lint { + message: d.details.message, + code: d.details.code.to_string(), + hint: d.details.hint, + quick_fixes: d + .details + .fixes + .into_iter() + .map(|f| DataQuickFix { + description: f.description.to_string(), + changes: f + .changes + .into_iter() + .map(|change| DataQuickFixChange { + range: as_lsp_range(change.range, &range.text_info), + new_text: change.new_text.to_string(), + }) + .collect(), + }) + .collect(), + }, + }) }) .collect(), ) |