mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 18:38:33 +00:00
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
This commit is contained in:
parent
ef78d317f0
commit
763f05e74d
63 changed files with 1601 additions and 955 deletions
|
@ -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(),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue