Skip to content

Commit

Permalink
feat(linter): react/exhaustive-deps (#7151)
Browse files Browse the repository at this point in the history
Firstly, a massive thanks to @alisnic for starting this (incredibly complicated) lint rule in #2637 !

still a draft. current state:

3x false positives (all todo with refs)

3x false negatives (TS will catch these
13x false negatvies todo with refs
1x false negative TODO

closes  #2637
relates to #2174
  • Loading branch information
camc314 authored and Dunqing committed Nov 18, 2024
1 parent 5d377ec commit 9e3872d
Show file tree
Hide file tree
Showing 7 changed files with 5,750 additions and 1 deletion.
11 changes: 10 additions & 1 deletion crates/oxc_linter/src/ast_util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use oxc_ast::{ast::BindingIdentifier, AstKind};
use oxc_ecmascript::ToBoolean;
use oxc_semantic::{AstNode, IsGlobalReference, NodeId, Semantic, SymbolId};
use oxc_semantic::{AstNode, IsGlobalReference, NodeId, ReferenceId, Semantic, SymbolId};
use oxc_span::{GetSpan, Span};
use oxc_syntax::operator::{AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator};

Expand Down Expand Up @@ -282,6 +282,15 @@ pub fn get_declaration_of_variable<'a, 'b>(
Some(semantic.nodes().get_node(symbol_table.get_declaration(symbol_id)))
}

pub fn get_declaration_from_reference_id<'a, 'b>(
reference_id: ReferenceId,
semantic: &'b Semantic<'a>,
) -> Option<&'b AstNode<'a>> {
let symbol_table = semantic.symbols();
let symbol_id = symbol_table.get_reference(reference_id).symbol_id()?;
Some(semantic.nodes().get_node(symbol_table.get_declaration(symbol_id)))
}

pub fn get_symbol_id_of_variable(
ident: &IdentifierReference,
semantic: &Semantic<'_>,
Expand Down
5 changes: 5 additions & 0 deletions crates/oxc_linter/src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,10 @@ mod node {
pub mod no_new_require;
}

mod react_hooks {
pub mod exhaustive_deps;
}

oxc_macros::declare_all_lint_rules! {
// import::no_deprecated,
// import::no_unused_modules,
Expand Down Expand Up @@ -956,4 +960,5 @@ oxc_macros::declare_all_lint_rules! {
vitest::prefer_to_be_object,
vitest::prefer_to_be_truthy,
vitest::require_local_test_context_for_concurrent_snapshots,
react_hooks::exhaustive_deps,
}
Loading

0 comments on commit 9e3872d

Please sign in to comment.