Skip to content

Commit

Permalink
feat(linter/react): add the rules_of_hooks rule.
Browse files Browse the repository at this point in the history
This one sounds like something straight out of `Mortal Kombat`!
  • Loading branch information
rzvxa committed Apr 22, 2024
1 parent 18679fd commit 5804a32
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crates/oxc_linter/src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ mod react {
pub mod no_unknown_property;
pub mod react_in_jsx_scope;
pub mod require_render_return;
pub mod rules_of_hooks;
pub mod void_dom_elements_no_children;
}

Expand Down Expand Up @@ -622,6 +623,7 @@ oxc_macros::declare_all_lint_rules! {
react::no_is_mounted,
react::no_unknown_property,
react::require_render_return,
react::rules_of_hooks,
react::void_dom_elements_no_children,
react_perf::jsx_no_jsx_as_prop,
react_perf::jsx_no_new_array_as_prop,
Expand Down
39 changes: 39 additions & 0 deletions crates/oxc_linter/src/rules/react/rules_of_hooks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use oxc_diagnostics::{
miette::{self, Diagnostic},
thiserror::Error,
};
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

use crate::{context::LintContext, rule::Rule, AstNode};

#[derive(Debug, Error, Diagnostic)]
#[error("eslint-plugin-react-hooks(rules-of-hooks): TODO")]
#[diagnostic(severity(warning), help("TODO"))]
struct RulesOfHooksDiagnostic(#[label] pub Span);

#[derive(Debug, Default, Clone)]
pub struct RulesOfHooks;

declare_oxc_lint!(
/// ### What it does
///
/// TODO
RulesOfHooks,
correctness
);

impl Rule for RulesOfHooks {
fn run<'a>(&self, _: &AstNode<'a>, _: &LintContext<'a>) {}
}

#[test]
fn test() {
use crate::tester::Tester;

let pass = vec![("<App />;", None)];

let fail = vec![];

Tester::new(RulesOfHooks::NAME, pass, fail).test_and_snapshot();
}
5 changes: 5 additions & 0 deletions crates/oxc_linter/src/snapshots/rules_of_hooks.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/oxc_linter/src/tester.rs
expression: rules_of_hooks
---

0 comments on commit 5804a32

Please sign in to comment.