Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ working directory: fixtures/eslint_and_typescript_alias_rules
: ^^^^
5 |
`----
help: Use a named constant instead of a magic number to make the code more readable and maintainable.

Found 0 warnings and 1 error.
Finished in <variable>ms on 1 file with 1 rules using 1 threads.
Expand All @@ -32,6 +33,7 @@ working directory: fixtures/eslint_and_typescript_alias_rules
: ^^^^
5 |
`----
help: Use a named constant instead of a magic number to make the code more readable and maintainable.

Found 0 warnings and 1 error.
Finished in <variable>ms on 1 file with 1 rules using 1 threads.
Expand Down
8 changes: 6 additions & 2 deletions crates/oxc_linter/src/rules/eslint/no_magic_numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ enum NoMagicNumberReportReason {
}

fn must_use_const_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Number constants declarations must use 'const'.").with_label(span)
OxcDiagnostic::warn("Number constants declarations must use 'const'.")
.with_help("Use 'const' instead of 'let' or 'var' to declare number constants to make their immutability explicit.")
.with_label(span)
}

fn no_magic_number_diagnostic(span: Span, raw: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("No magic number: {raw}")).with_label(span)
OxcDiagnostic::warn(format!("No magic number: {raw}"))
.with_help("Use a named constant instead of a magic number to make the code more readable and maintainable.")
.with_label(span)
}

#[derive(Debug, Default, Clone)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,33 @@ use crate::{
};

fn surrogate_pair_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unexpected surrogate pair in character class.").with_label(span)
OxcDiagnostic::warn("Unexpected surrogate pair in character class.")
.with_help("Add the Unicode flag 'u' to the regular expression or use Unicode code point escapes (e.g., \\u{1F44D}) instead of surrogate pairs.")
.with_label(span)
}

fn combining_class_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unexpected combining class in character class.").with_label(span)
OxcDiagnostic::warn("Unexpected combining class in character class.")
.with_help("Replace the character with its normalized form (NFC) or use Unicode code point escapes instead of combining sequences.")
.with_label(span)
}

fn emoji_modifiers_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unexpected emoji modifier in character class.").with_label(span)
OxcDiagnostic::warn("Unexpected emoji modifier in character class.")
.with_help("Use Unicode code point escapes (e.g., \\u{1F3FB} for the light skin tone modifier) instead of emoji modifier sequences in character classes.")
.with_label(span)
}

fn regional_indicator_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unexpected regional indicator in character class.").with_label(span)
OxcDiagnostic::warn("Unexpected regional indicator in character class.")
.with_help("Use Unicode code point escapes (e.g., \\u{1F1EF} for the regional indicator symbol for 'J') instead of regional indicator symbol pairs in character classes.")
.with_label(span)
}

fn zwj_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unexpected joined character sequence in character class.").with_label(span)
OxcDiagnostic::warn("Unexpected joined character sequence in character class.")
.with_help("Use Unicode code point escapes (e.g., \\u{1F468}\\u200D\\u{1F469} for '👨‍👩') instead of zero-width joiner sequences in character classes.")
.with_label(span)
}

#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
Expand Down
11 changes: 7 additions & 4 deletions crates/oxc_linter/src/rules/eslint/no_redeclare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ use crate::{
};

fn no_redeclare_diagnostic(name: &str, decl_span: Span, re_decl_span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("'{name}' is already defined.")).with_labels([
decl_span.label(format!("'{name}' is already defined.")),
re_decl_span.label("It can not be redeclared here."),
])
OxcDiagnostic::warn(format!("'{name}' is already defined."))
.with_help("Use a different variable name or remove the duplicate declaration.")
.with_labels([
decl_span.label(format!("'{name}' is already defined.")),
re_decl_span.label("It can not be redeclared here."),
])
}

fn no_redeclare_as_builtin_in_diagnostic(name: &str, span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("'{name}' is already defined as a built-in global variable."))
.with_help("Use a different variable name to avoid shadowing the built-in global.")
.with_label(span)
}

Expand Down
5 changes: 4 additions & 1 deletion crates/oxc_linter/src/rules/eslint/radix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use serde::{Deserialize, Serialize};
use crate::{AstNode, context::LintContext, rule::Rule};

fn missing_parameters(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Missing parameters.").with_label(span)
OxcDiagnostic::warn("Missing parameters.")
.with_help("Add parameters for parsing numbers, e.g., `parseInt('10', 10)`.")
.with_label(span)
}

fn missing_radix(span: Span) -> OxcDiagnostic {
Expand All @@ -22,6 +24,7 @@ fn missing_radix(span: Span) -> OxcDiagnostic {

fn invalid_radix(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Invalid radix parameter, must be an integer between 2 and 36.")
.with_help("The radix parameter should be an integer between 2 and 36, or a variable that is not `undefined`.")
.with_label(span)
}

Expand Down
Loading
Loading