Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(linter): disable react/rules-of-hooks for vue and svelte files #8165

Merged
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
10 changes: 8 additions & 2 deletions crates/oxc_linter/src/rules/react/rules_of_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
context::LintContext,
rule::Rule,
utils::{is_react_component_or_hook_name, is_react_function_call, is_react_hook},
AstNode,
AstNode, FrameworkFlags,
};

mod diagnostics {
Expand Down Expand Up @@ -99,7 +99,7 @@ pub struct RulesOfHooks;
declare_oxc_lint!(
/// ### What it does
///
/// This enforcecs the Rules of Hooks
/// This enforces the Rules of Hooks
///
/// <https://reactjs.org/docs/hooks-rules.html>
///
Expand All @@ -108,6 +108,12 @@ declare_oxc_lint!(
);

impl Rule for RulesOfHooks {
fn should_run(&self, ctx: &crate::rules::ContextHost) -> bool {
// disable this rule in vue/nuxt and svelte(kit) files
// top level useFunction are very common
!ctx.frameworks().contains(FrameworkFlags::SvelteKit | FrameworkFlags::Nuxt)
}

fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
let AstKind::CallExpression(call) = node.kind() else { return };

Expand Down
Loading