Skip to content

Commit

Permalink
refactor(linter): jest/prefer-hooks-in-order: improve diagnostic me…
Browse files Browse the repository at this point in the history
…ssages (#6036)

In the previous PR, I added an additional span that allows us to actually point to the prior hook function that the hook should be moved above. I've updated the error messages to hopefully be a little bit more helpful in explaining what to do.
  • Loading branch information
camchenry committed Sep 24, 2024
1 parent c16ae60 commit 1f92d61
Show file tree
Hide file tree
Showing 2 changed files with 341 additions and 140 deletions.
7 changes: 5 additions & 2 deletions crates/oxc_linter/src/rules/jest/prefer_hooks_in_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ use crate::{
};

fn reorder_hooks(hook: (&str, Span), previous_hook: (&str, Span)) -> OxcDiagnostic {
OxcDiagnostic::warn("Prefer having hooks in a consistent order.")
OxcDiagnostic::warn("Test hooks are not in a consistent order.")
.with_help(format!("{:?} hooks should be before any {:?} hooks", hook.0, previous_hook.0))
.with_label(hook.1)
.with_label(
hook.1.label(format!("this should be moved to before the {:?} hook", previous_hook.0)),
)
.and_label(previous_hook.1.label(format!("{:?} hook should be called before this", hook.0)))
}

#[derive(Debug, Default, Clone)]
Expand Down
Loading

0 comments on commit 1f92d61

Please sign in to comment.