Skip to content

Commit

Permalink
refactor(diagnostics): s/warning/warn
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed May 18, 2024
1 parent f13fe8a commit c9d84af
Show file tree
Hide file tree
Showing 344 changed files with 537 additions and 568 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_diagnostics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl OxcDiagnostic {
}

#[must_use]
pub fn warning<T: Into<String>>(message: T) -> Self {
pub fn warn<T: Into<String>>(message: T) -> Self {
Self {
inner: Box::new(OxcDiagnosticInner {
message: message.into(),
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_diagnostics/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl DiagnosticService {
// Skip large output and print only once
if err_str.lines().any(|line| line.len() >= 400) {
let minified_diagnostic = Error::new(
OxcDiagnostic::warning("File is too long to fit on the screen")
OxcDiagnostic::warn("File is too long to fit on the screen")
.with_help(format!("{path:?} seems like a minified file")),
);
err_str = format!("{minified_diagnostic:?}");
Expand Down
26 changes: 13 additions & 13 deletions crates/oxc_linter/src/fixer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,55 +127,55 @@ mod test {
use super::{Fix, FixResult, Fixer, Message};

fn insert_at_end() -> OxcDiagnostic {
OxcDiagnostic::warning("End")
OxcDiagnostic::warn("End")
}

fn insert_at_start() -> OxcDiagnostic {
OxcDiagnostic::warning("Start")
OxcDiagnostic::warn("Start")
}

fn insert_at_middle() -> OxcDiagnostic {
OxcDiagnostic::warning("Multiply")
OxcDiagnostic::warn("Multiply")
}

fn replace_id() -> OxcDiagnostic {
OxcDiagnostic::warning("foo")
OxcDiagnostic::warn("foo")
}

fn replace_var() -> OxcDiagnostic {
OxcDiagnostic::warning("let")
OxcDiagnostic::warn("let")
}

fn replace_num() -> OxcDiagnostic {
OxcDiagnostic::warning("5")
OxcDiagnostic::warn("5")
}

fn remove_start() -> OxcDiagnostic {
OxcDiagnostic::warning("removestart")
OxcDiagnostic::warn("removestart")
}

fn remove_middle(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::warning("removemiddle").with_labels([span0.into()])
OxcDiagnostic::warn("removemiddle").with_labels([span0.into()])
}

fn remove_end() -> OxcDiagnostic {
OxcDiagnostic::warning("removeend")
OxcDiagnostic::warn("removeend")
}

fn reverse_range() -> OxcDiagnostic {
OxcDiagnostic::warning("reversed range")
OxcDiagnostic::warn("reversed range")
}

fn no_fix(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::warning("nofix").with_labels([span0.into()])
OxcDiagnostic::warn("nofix").with_labels([span0.into()])
}

fn no_fix_1(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::warning("nofix1").with_labels([span0.into()])
OxcDiagnostic::warn("nofix1").with_labels([span0.into()])
}

fn no_fix_2(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::warning("nofix2").with_labels([span0.into()])
OxcDiagnostic::warn("nofix2").with_labels([span0.into()])
}

const TEST_CODE: &str = "var answer = 6 * 7;";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ use crate::{
};

fn expect_return(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::warning(format!(
OxcDiagnostic::warn(format!(
"eslint(array-callback-return): Missing return on some path for array method {x0:?}"
))
.with_help(format!("Array method {x0:?} needs to have valid return on all code paths"))
.with_labels([span1.into()])
}

fn expect_no_return(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::warning(format!(
OxcDiagnostic::warn(format!(
"eslint(array-callback-return): Unexpected return for array method {x0:?}"
))
.with_help(format!("Array method {x0:?} expects no useless return from the function"))
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/default_case_last.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use oxc_span::Span;
use crate::{context::LintContext, rule::Rule, AstNode};

fn default_case_last_diagnostic(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::warning(
OxcDiagnostic::warn(
"eslint(default-case-last): Enforce default clauses in switch statements to be last",
)
.with_labels([LabeledSpan::new_with_span(
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/default_param_last.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use oxc_span::Span;
use crate::{context::LintContext, rule::Rule, AstNode};

fn default_param_last_diagnostic(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::warning("eslint(default-param-last): Default parameters should be last")
OxcDiagnostic::warn("eslint(default-param-last): Default parameters should be last")
.with_help("Enforce default parameters to be last.")
.with_labels([span0.into()])
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/eqeqeq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use oxc_syntax::operator::{BinaryOperator, UnaryOperator};
use crate::{context::LintContext, fixer::Fix, rule::Rule, AstNode};

fn eqeqeq_diagnostic(x0: &str, x1: &str, span2: Span) -> OxcDiagnostic {
OxcDiagnostic::warning(format!("eslint(eqeqeq): Expected {x1} and instead saw {x0}"))
OxcDiagnostic::warn(format!("eslint(eqeqeq): Expected {x1} and instead saw {x0}"))
.with_help(format!("Prefer {x1} operator"))
.with_labels([span2.into()])
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/for_direction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use oxc_syntax::operator::{AssignmentOperator, BinaryOperator, UnaryOperator, Up
use crate::{context::LintContext, rule::Rule, AstNode};

fn for_direction_diagnostic(span0: Span, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::warning("eslint(for-direction): The update clause in this loop moves the variable in the wrong direction")
OxcDiagnostic::warn("eslint(for-direction): The update clause in this loop moves the variable in the wrong direction")
.with_help("Use while loop for intended infinite loop")
.with_labels([LabeledSpan::new_with_span(Some("This test moves in the wrong direction".into()), span0), LabeledSpan::new_with_span(Some("with this update".into()), span1)])
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/getter_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use oxc_span::Span;
use crate::{context::LintContext, rule::Rule, AstNode};

fn getter_return_diagnostic(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::warning("eslint(getter-return): Expected to always return a value in getter.")
OxcDiagnostic::warn("eslint(getter-return): Expected to always return a value in getter.")
.with_help("Return a value from all code paths in getter.")
.with_labels([span0.into()])
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/guard_for_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use oxc_span::{GetSpan, Span};
use crate::{context::LintContext, rule::Rule, AstNode};

fn guard_for_in_diagnostic(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::warning("eslint(guard-for-in): Require `for-in` loops to include an `if` statement")
OxcDiagnostic::warn("eslint(guard-for-in): Require `for-in` loops to include an `if` statement")
.with_help("The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.")
.with_labels([span0.into()])
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/max_classes_per_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use oxc_span::Span;
use crate::{context::LintContext, rule::Rule};

fn max_classes_per_file_diagnostic(total: usize, max: usize, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::warning(format!(
OxcDiagnostic::warn(format!(
"eslint(max-classes-per-file): File has too many classes ({total}). Maximum allowed is {max}",
))
.with_help("Reduce the number of classes in this file")
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/max_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use oxc_span::Span;
use crate::{context::LintContext, rule::Rule};

fn max_lines_diagnostic(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::warning(format!("eslint(max-lines): {x0:?}"))
OxcDiagnostic::warn(format!("eslint(max-lines): {x0:?}"))
.with_help("Reduce the number of lines in this file")
.with_labels([span1.into()])
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/max_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde_json::Value;
use crate::{context::LintContext, rule::Rule, AstNode};

fn max_params_diagnostic(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::warning(format!("eslint(max-params): {x0:?}"))
OxcDiagnostic::warn(format!("eslint(max-params): {x0:?}"))
.with_help(
"This rule enforces a maximum number of parameters allowed in function definitions.",
)
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_array_constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use oxc_span::Span;
use crate::{context::LintContext, rule::Rule, AstNode};

fn no_array_constructor_diagnostic(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::warning("eslint(no-array-constructor): Disallow `Array` constructors")
OxcDiagnostic::warn("eslint(no-array-constructor): Disallow `Array` constructors")
.with_help("Use array literal instead")
.with_labels([span0.into()])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use oxc_span::Span;
use crate::{context::LintContext, rule::Rule, AstNode};

fn no_async_promise_executor_diagnostic(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::warning(
OxcDiagnostic::warn(
"eslint(no-async-promise-executor): Promise executor functions should not be `async`.",
)
.with_labels([span0.into()])
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_await_in_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use oxc_span::Span;
use crate::{context::LintContext, rule::Rule, AstNode};

fn no_await_in_loop_diagnostic(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::warning("eslint(no-await-in-loop): Unexpected `await` inside a loop.")
OxcDiagnostic::warn("eslint(no-await-in-loop): Unexpected `await` inside a loop.")
.with_labels([span0.into()])
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_bitwise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use oxc_syntax::operator::BinaryOperator;
use crate::{context::LintContext, rule::Rule, AstNode};

fn no_bitwise_diagnostic(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::warning(format!("eslint(no-bitwise): Unexpected use of {x0:?}"))
OxcDiagnostic::warn(format!("eslint(no-bitwise): Unexpected use of {x0:?}"))
.with_help("bitwise operators are not allowed, maybe you mistyped `&&` or `||`")
.with_labels([span1.into()])
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_caller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use oxc_span::Span;
use crate::{context::LintContext, rule::Rule, AstNode};

fn no_caller_diagnostic(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::warning("eslint(no-caller): Disallow the use of arguments.caller or arguments.callee")
OxcDiagnostic::warn("eslint(no-caller): Disallow the use of arguments.caller or arguments.callee")
.with_help("'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them")
.with_labels([span0.into()])
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_case_declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use oxc_span::Span;
use crate::{context::LintContext, rule::Rule, AstNode};

fn no_case_declarations_diagnostic(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::warning(
OxcDiagnostic::warn(
"eslint(no-case-declarations): Unexpected lexical declaration in case block.",
)
.with_labels([span0.into()])
Expand Down
12 changes: 5 additions & 7 deletions crates/oxc_linter/src/rules/eslint/no_class_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ use oxc_span::Span;
use crate::{context::LintContext, rule::Rule};

fn no_class_assign_diagnostic(x0: &str, span1: Span, span2: Span) -> OxcDiagnostic {
OxcDiagnostic::warning(format!(
"eslint(no-class-assign): Unexpected re-assignment of class {x0}"
))
.with_labels([
LabeledSpan::new_with_span(Some(format!("{x0} is declared as class here")), span1),
LabeledSpan::new_with_span(Some(format!("{x0} is re-assigned here")), span2),
])
OxcDiagnostic::warn(format!("eslint(no-class-assign): Unexpected re-assignment of class {x0}"))
.with_labels([
LabeledSpan::new_with_span(Some(format!("{x0} is declared as class here")), span1),
LabeledSpan::new_with_span(Some(format!("{x0} is re-assigned here")), span2),
])
}

#[derive(Debug, Default, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_compare_neg_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use oxc_syntax::operator::{BinaryOperator, UnaryOperator};
use crate::{context::LintContext, rule::Rule, AstNode};

fn no_compare_neg_zero_diagnostic(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::warning(format!(
OxcDiagnostic::warn(format!(
"eslint(no-compare-neg-zero): Do not use the {x0} operator to compare against -0."
))
.with_help("Use Object.is(x, -0) to test equality with -0 and use 0 for other cases")
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_cond_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use oxc_span::{GetSpan, Span};
use crate::{context::LintContext, rule::Rule, AstNode};

fn no_cond_assign_diagnostic(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::warning(
OxcDiagnostic::warn(
"eslint(no-cond-assign): Expected a conditional expression and instead saw an assignment",
)
.with_help("Consider wrapping the assignment in additional parentheses")
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use oxc_span::Span;
use crate::{context::LintContext, rule::Rule, AstNode};

fn no_console_diagnostic(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::warning("eslint(no-console): Unexpected console statement.")
OxcDiagnostic::warn("eslint(no-console): Unexpected console statement.")
.with_labels([span0.into()])
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_const_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use oxc_span::Span;
use crate::{context::LintContext, rule::Rule};

fn no_const_assign_diagnostic(x0: &str, span1: Span, span2: Span) -> OxcDiagnostic {
OxcDiagnostic::warning(format!(
OxcDiagnostic::warn(format!(
"eslint(no-const-assign): Unexpected re-assignment of const variable {x0}"
))
.with_labels([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,29 @@ declare_oxc_lint!(
);

fn constant_short_circuit(x0: &str, x1: &str, span2: Span) -> OxcDiagnostic {
OxcDiagnostic::warning(format!("eslint(no-constant-binary-expression): Unexpected constant {x0:?} on the left-hand side of a {x1:?} expression"))
OxcDiagnostic::warn(format!("eslint(no-constant-binary-expression): Unexpected constant {x0:?} on the left-hand side of a {x1:?} expression"))
.with_help("This expression always evaluates to the constant on the left-hand side")
.with_labels([span2.into()])
}

fn constant_binary_operand(x0: &str, x1: &str, span2: Span) -> OxcDiagnostic {
OxcDiagnostic::warning(
OxcDiagnostic::warn(
"eslint(no-constant-binary-expression): Unexpected constant binary expression",
)
.with_help(format!("This compares constantly with the {x0}-hand side of the {x1}"))
.with_labels([span2.into()])
}

fn constant_always_new(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::warning(
OxcDiagnostic::warn(
"eslint(no-constant-binary-expression): Unexpected comparison to newly constructed object",
)
.with_help("These two values can never be equal")
.with_labels([span0.into()])
}

fn constant_both_always_new(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::warning("eslint(no-constant-binary-expression): Unexpected comparison of two newly constructed objects").with_help("These two values can never be equal").with_labels([span0.into()])
OxcDiagnostic::warn("eslint(no-constant-binary-expression): Unexpected comparison of two newly constructed objects").with_help("These two values can never be equal").with_labels([span0.into()])
}

impl Rule for NoConstantBinaryExpression {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use oxc_span::{GetSpan, Span};
use crate::{ast_util::IsConstant, context::LintContext, rule::Rule, AstNode};

fn no_constant_condition_diagnostic(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::warning("eslint(no-constant-condition): Unexpected constant condition")
OxcDiagnostic::warn("eslint(no-constant-condition): Unexpected constant condition")
.with_help("Constant expression as a test condition is not allowed")
.with_labels([span0.into()])
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_continue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

fn no_continue_diagnostic(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::warning("eslint(no-continue): Unexpected use of `continue` statement.")
OxcDiagnostic::warn("eslint(no-continue): Unexpected use of `continue` statement.")
.with_help("Do not use the `continue` statement.")
.with_labels([span0.into()])
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_control_regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use regex::{Matches, Regex};
use crate::{ast_util::extract_regex_flags, context::LintContext, rule::Rule, AstNode};

fn no_control_regex_diagnostic(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::warning("eslint(no-control-regex): Unexpected control character(s)")
OxcDiagnostic::warn("eslint(no-control-regex): Unexpected control character(s)")
.with_help(format!("Unexpected control character(s) in regular expression: \"{x0}\""))
.with_labels([span1.into()])
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_debugger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use oxc_span::Span;
use crate::{context::LintContext, fixer::Fix, rule::Rule, AstNode};

fn no_debugger_diagnostic(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::warning("eslint(no-debugger): `debugger` statement is not allowed")
OxcDiagnostic::warn("eslint(no-debugger): `debugger` statement is not allowed")
.with_labels([span0.into()])
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_delete_var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use oxc_syntax::operator::UnaryOperator;
use crate::{context::LintContext, rule::Rule, AstNode};

fn no_delete_var_diagnostic(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::warning("eslint(no-delete-var): variables should not be deleted")
OxcDiagnostic::warn("eslint(no-delete-var): variables should not be deleted")
.with_labels([span0.into()])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn no_dupe_class_members_diagnostic(
span1: Span,
span2: Span,
) -> OxcDiagnostic {
OxcDiagnostic::warning(format!("eslint(no-dupe-class-members): Duplicate class member: {x0:?}"))
OxcDiagnostic::warn(format!("eslint(no-dupe-class-members): Duplicate class member: {x0:?}"))
.with_help("The last declaration overwrites previous ones, remove one of them or rename if both should be retained")
.with_labels([LabeledSpan::new_with_span(Some(format!("{x0:?} is previously declared here")), span1), LabeledSpan::new_with_span(Some(format!("{x0:?} is re-declared here")), span2)])
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_dupe_else_if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use oxc_syntax::operator::LogicalOperator;
use crate::{ast_util::calculate_hash, context::LintContext, rule::Rule, AstNode};

fn no_dupe_else_if_diagnostic(span0: Span, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::warning("eslint(no-dupe-else-if): duplicate conditions in if-else-if chains")
OxcDiagnostic::warn("eslint(no-dupe-else-if): duplicate conditions in if-else-if chains")
.with_help("This branch can never execute. Its condition is a duplicate or covered by previous conditions in the if-else-if chain")
.with_labels([span0.into(), span1.into()])
}
Expand Down
Loading

0 comments on commit c9d84af

Please sign in to comment.