Skip to content

Commit c308857

Browse files
dosmondcamc314
andauthored
fix(linter/consistent_type_imports): Add missing help and notes to diagnostics (oxc-project#19827)
Added .with_help() and .with_note() to missing diagnostics in the typescript consistent_type_imports.rs file. Part of oxc-project#19121 --------- Co-authored-by: Cameron Clark <cameron.clark@hey.com>
1 parent fd73e84 commit c308857

2 files changed

Lines changed: 89 additions & 48 deletions

File tree

crates/oxc_linter/src/rules/typescript/consistent_type_imports.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use std::{borrow::Cow, error::Error, fmt::Write, ops::Deref};
22

33
use itertools::Itertools;
4+
use schemars::JsonSchema;
5+
use serde::{Deserialize, Serialize};
6+
47
use oxc_ast::{
58
AstKind,
69
ast::{
@@ -12,8 +15,6 @@ use oxc_diagnostics::OxcDiagnostic;
1215
use oxc_macros::declare_oxc_lint;
1316
use oxc_semantic::{Reference, SymbolId};
1417
use oxc_span::{GetSpan, Span};
15-
use schemars::JsonSchema;
16-
use serde::{Deserialize, Serialize};
1718

1819
use crate::{
1920
AstNode,
@@ -23,14 +24,20 @@ use crate::{
2324
};
2425

2526
fn no_import_type_annotations_diagnostic(span: Span) -> OxcDiagnostic {
26-
OxcDiagnostic::warn("`import()` type annotations are forbidden.").with_label(span)
27+
OxcDiagnostic::warn("`import()` type annotations are forbidden.")
28+
.with_help("Replace `import()` type annotations with a regular type import. For example, change `type T = import('module').Type` to `import type { Type } from 'module'; type T = Type`.")
29+
.with_label(span)
2730
}
2831

2932
fn avoid_import_type_diagnostic(span: Span) -> OxcDiagnostic {
30-
OxcDiagnostic::warn("Use an `import` instead of an `import type`.").with_label(span)
33+
OxcDiagnostic::warn("Use an `import` instead of an `import type`.")
34+
.with_help("Replace the `import type` declaration with a regular `import` declaration. For example, `import type { Type } from 'module'` would become `import { Type } from 'module'`.")
35+
.with_label(span)
3136
}
3237
fn type_over_value_diagnostic(span: Span) -> OxcDiagnostic {
3338
OxcDiagnostic::warn("All imports in the declaration are only used as types. Use `import type`.")
39+
.with_help("Replace the `import` declaration with `import type`. For example, change `import { Type } from 'module'` would become `import type { Type } from 'module'`.")
40+
.with_note("Using `import type` for type-only imports helps with tree-shaking, makes it clear that these imports don't affect runtime code, and can improve build performance by allowing bundlers to eliminate unused type imports.")
3441
.with_label(span)
3542
}
3643

0 commit comments

Comments
 (0)