Skip to content

Commit 1fa3381

Browse files
committed
refactor(semantic)!: rename AstNode to Node and AstNodes to Nodes
1 parent 5bace1a commit 1fa3381

File tree

368 files changed

+952
-979
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

368 files changed

+952
-979
lines changed

crates/oxc_linter/src/ast_util.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use oxc_ast::{ast::BindingIdentifier, AstKind};
2-
use oxc_semantic::{AstNode, IsGlobalReference, NodeId, SymbolId};
2+
use oxc_semantic::{IsGlobalReference, Node, NodeId, SymbolId};
33
use oxc_span::{GetSpan, Span};
44
use oxc_syntax::operator::{AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator};
55

@@ -181,9 +181,9 @@ impl<'a, 'b> IsConstant<'a, 'b> for SpreadElement<'a> {
181181
/// Return the innermost `Function` or `ArrowFunctionExpression` Node
182182
/// enclosing the specified node
183183
pub fn get_enclosing_function<'a, 'b>(
184-
node: &'b AstNode<'a>,
184+
node: &'b Node<'a>,
185185
ctx: &'b LintContext<'a>,
186-
) -> Option<&'b AstNode<'a>> {
186+
) -> Option<&'b Node<'a>> {
187187
let mut current_node = node;
188188
loop {
189189
if matches!(current_node.kind(), AstKind::Program(_)) {
@@ -204,7 +204,7 @@ pub fn is_nth_argument<'a>(call: &CallExpression<'a>, arg: &Argument<'a>, n: usi
204204
}
205205

206206
/// Jump to the outer most of chained parentheses if any
207-
pub fn outermost_paren<'a, 'b>(node: &'b AstNode<'a>, ctx: &'b LintContext<'a>) -> &'b AstNode<'a> {
207+
pub fn outermost_paren<'a, 'b>(node: &'b Node<'a>, ctx: &'b LintContext<'a>) -> &'b Node<'a> {
208208
let mut node = node;
209209

210210
loop {
@@ -222,20 +222,20 @@ pub fn outermost_paren<'a, 'b>(node: &'b AstNode<'a>, ctx: &'b LintContext<'a>)
222222
}
223223

224224
pub fn outermost_paren_parent<'a, 'b>(
225-
node: &'b AstNode<'a>,
225+
node: &'b Node<'a>,
226226
ctx: &'b LintContext<'a>,
227-
) -> Option<&'b AstNode<'a>> {
227+
) -> Option<&'b Node<'a>> {
228228
ctx.nodes()
229229
.iter_parents(node.id())
230230
.skip(1)
231231
.find(|parent| !matches!(parent.kind(), AstKind::ParenthesizedExpression(_)))
232232
}
233233

234234
pub fn nth_outermost_paren_parent<'a, 'b>(
235-
node: &'b AstNode<'a>,
235+
node: &'b Node<'a>,
236236
ctx: &'b LintContext<'a>,
237237
n: usize,
238-
) -> Option<&'b AstNode<'a>> {
238+
) -> Option<&'b Node<'a>> {
239239
ctx.nodes()
240240
.iter_parents(node.id())
241241
.skip(1)
@@ -247,7 +247,7 @@ pub fn nth_outermost_paren_parent<'a, 'b>(
247247
pub fn iter_outer_expressions<'a, 'ctx>(
248248
ctx: &'ctx LintContext<'a>,
249249
node_id: NodeId,
250-
) -> impl Iterator<Item = &'ctx AstNode<'a>> + 'ctx {
250+
) -> impl Iterator<Item = &'ctx Node<'a>> + 'ctx {
251251
ctx.nodes().iter_parents(node_id).skip(1).filter(|parent| {
252252
!matches!(
253253
parent.kind(),
@@ -264,7 +264,7 @@ pub fn iter_outer_expressions<'a, 'ctx>(
264264
pub fn get_declaration_of_variable<'a, 'b>(
265265
ident: &IdentifierReference,
266266
ctx: &'b LintContext<'a>,
267-
) -> Option<&'b AstNode<'a>> {
267+
) -> Option<&'b Node<'a>> {
268268
let symbol_id = get_symbol_id_of_variable(ident, ctx)?;
269269
let symbol_table = ctx.semantic().symbols();
270270
Some(ctx.nodes().get_node(symbol_table.get_declaration(symbol_id)))
@@ -391,7 +391,7 @@ pub fn is_global_require_call(call_expr: &CallExpression, ctx: &LintContext) ->
391391
call_expr.callee.is_global_reference_name("require", ctx.symbols())
392392
}
393393

394-
pub fn is_function_node(node: &AstNode) -> bool {
394+
pub fn is_function_node(node: &Node) -> bool {
395395
match node.kind() {
396396
AstKind::Function(f) if f.is_function_declaration() => true,
397397
AstKind::Function(f) if f.is_expression() => true,
@@ -401,7 +401,7 @@ pub fn is_function_node(node: &AstNode) -> bool {
401401
}
402402

403403
pub fn get_function_like_declaration<'b>(
404-
node: &AstNode<'b>,
404+
node: &Node<'b>,
405405
ctx: &LintContext<'b>,
406406
) -> Option<&'b BindingIdentifier<'b>> {
407407
let parent = outermost_paren_parent(node, ctx)?;

crates/oxc_linter/src/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{cell::RefCell, path::Path, rc::Rc, sync::Arc};
33

44
use oxc_cfg::ControlFlowGraph;
55
use oxc_diagnostics::{OxcDiagnostic, Severity};
6-
use oxc_semantic::{AstNodes, JSDocFinder, ScopeTree, Semantic, SymbolTable};
6+
use oxc_semantic::{JSDocFinder, Nodes, ScopeTree, Semantic, SymbolTable};
77
use oxc_span::{GetSpan, SourceType, Span};
88
use oxc_syntax::module_record::ModuleRecord;
99

@@ -349,7 +349,7 @@ impl<'a> LintContext<'a> {
349349
/// AST nodes
350350
///
351351
/// Shorthand for `self.semantic().nodes()`.
352-
pub fn nodes(&self) -> &AstNodes<'a> {
352+
pub fn nodes(&self) -> &Nodes<'a> {
353353
self.semantic().nodes()
354354
}
355355

crates/oxc_linter/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use std::{io::Write, path::Path, rc::Rc, sync::Arc};
2525
use config::LintConfig;
2626
use options::LintOptions;
2727
use oxc_diagnostics::Error;
28-
use oxc_semantic::{AstNode, Semantic};
28+
use oxc_semantic::{Node, Semantic};
2929

3030
pub use crate::{
3131
config::OxlintConfig,

crates/oxc_linter/src/rule.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77

88
use oxc_semantic::SymbolId;
99

10-
use crate::{context::LintContext, AllowWarnDeny, AstNode, FixKind, RuleEnum};
10+
use crate::{context::LintContext, AllowWarnDeny, FixKind, Node, RuleEnum};
1111

1212
pub trait Rule: Sized + Default + fmt::Debug {
1313
/// Initialize from eslint json configuration
@@ -18,7 +18,7 @@ pub trait Rule: Sized + Default + fmt::Debug {
1818
/// Visit each AST Node
1919
#[expect(unused_variables)]
2020
#[inline]
21-
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {}
21+
fn run<'a>(&self, node: &Node<'a>, ctx: &LintContext<'a>) {}
2222

2323
/// Visit each symbol
2424
#[expect(unused_variables)]

crates/oxc_linter/src/rules/eslint/array_callback_return/mod.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
ast_util::{get_enclosing_function, is_nth_argument, outermost_paren},
1515
context::LintContext,
1616
rule::Rule,
17-
AstNode,
17+
Node,
1818
};
1919

2020
fn expect_return(method_name: &str, span: Span) -> OxcDiagnostic {
@@ -76,7 +76,7 @@ impl Rule for ArrayCallbackReturn {
7676
Self { check_for_each, allow_implicit_return }
7777
}
7878

79-
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
79+
fn run<'a>(&self, node: &Node<'a>, ctx: &LintContext<'a>) {
8080
let (function_body, always_explicit_return) = match node.kind() {
8181
// Async, generator, and single expression arrow functions
8282
// always have explicit return value
@@ -135,10 +135,7 @@ impl Rule for ArrayCallbackReturn {
135135
/// Code ported from [eslint](https://github.com/eslint/eslint/blob/main/lib/rules/array-callback-return.js)
136136
/// We're currently on a `Function` or `ArrowFunctionExpression`, findout if it is an argument
137137
/// to the target array methods we're interested in.
138-
pub fn get_array_method_name<'a>(
139-
node: &AstNode<'a>,
140-
ctx: &LintContext<'a>,
141-
) -> Option<&'static str> {
138+
pub fn get_array_method_name<'a>(node: &Node<'a>, ctx: &LintContext<'a>) -> Option<&'static str> {
142139
let mut current_node = node;
143140
while let Some(parent) = ctx.nodes().parent_node(current_node.id()) {
144141
match parent.kind() {

crates/oxc_linter/src/rules/eslint/constructor_super.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use oxc_macros::declare_oxc_lint;
22

33
// use oxc_span::Span;
4-
use crate::{context::LintContext, rule::Rule, AstNode};
4+
use crate::{context::LintContext, rule::Rule, Node};
55

66
// #[derive(Debug, Error, Diagnostic)]
77
// #[error("Expected to call 'super()'.")]
@@ -38,7 +38,7 @@ declare_oxc_lint!(
3838
);
3939

4040
impl Rule for ConstructorSuper {
41-
fn run<'a>(&self, _node: &AstNode<'a>, _ctx: &LintContext<'a>) {}
41+
fn run<'a>(&self, _node: &Node<'a>, _ctx: &LintContext<'a>) {}
4242
}
4343

4444
#[test]

crates/oxc_linter/src/rules/eslint/default_case.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use oxc_macros::declare_oxc_lint;
44
use oxc_span::Span;
55
use regex::{Regex, RegexBuilder};
66

7-
use crate::{context::LintContext, rule::Rule, AstNode};
7+
use crate::{context::LintContext, rule::Rule, Node};
88

99
fn default_case_diagnostic(span: Span) -> OxcDiagnostic {
1010
OxcDiagnostic::warn("Require default cases in switch statements.")
@@ -62,7 +62,7 @@ impl Rule for DefaultCase {
6262
Self(Box::new(cfg))
6363
}
6464

65-
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
65+
fn run<'a>(&self, node: &Node<'a>, ctx: &LintContext<'a>) {
6666
if let AstKind::SwitchStatement(switch) = node.kind() {
6767
let cases = &switch.cases;
6868

crates/oxc_linter/src/rules/eslint/default_case_last.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use oxc_diagnostics::OxcDiagnostic;
33
use oxc_macros::declare_oxc_lint;
44
use oxc_span::Span;
55

6-
use crate::{context::LintContext, rule::Rule, AstNode};
6+
use crate::{context::LintContext, rule::Rule, Node};
77

88
fn default_case_last_diagnostic(span: Span) -> OxcDiagnostic {
99
OxcDiagnostic::warn("Enforce default clauses in switch statements to be last")
@@ -51,7 +51,7 @@ declare_oxc_lint!(
5151
);
5252

5353
impl Rule for DefaultCaseLast {
54-
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
54+
fn run<'a>(&self, node: &Node<'a>, ctx: &LintContext<'a>) {
5555
let AstKind::SwitchStatement(switch) = node.kind() else {
5656
return;
5757
};

crates/oxc_linter/src/rules/eslint/default_param_last.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use oxc_diagnostics::OxcDiagnostic;
33
use oxc_macros::declare_oxc_lint;
44
use oxc_span::Span;
55

6-
use crate::{context::LintContext, rule::Rule, AstNode};
6+
use crate::{context::LintContext, rule::Rule, Node};
77

88
fn default_param_last_diagnostic(span: Span) -> OxcDiagnostic {
99
OxcDiagnostic::warn("Default parameters should be last")
@@ -36,7 +36,7 @@ declare_oxc_lint!(
3636
);
3737

3838
impl Rule for DefaultParamLast {
39-
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
39+
fn run<'a>(&self, node: &Node<'a>, ctx: &LintContext<'a>) {
4040
match node.kind() {
4141
AstKind::Function(function) => {
4242
if !function.is_declaration() && !function.is_expression() {

crates/oxc_linter/src/rules/eslint/eqeqeq.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use oxc_macros::declare_oxc_lint;
77
use oxc_span::{GetSpan, Span};
88
use oxc_syntax::operator::{BinaryOperator, UnaryOperator};
99

10-
use crate::{context::LintContext, rule::Rule, AstNode};
10+
use crate::{context::LintContext, rule::Rule, Node};
1111

1212
fn eqeqeq_diagnostic(x0: &str, x1: &str, span2: Span) -> OxcDiagnostic {
1313
OxcDiagnostic::warn(format!("Expected {x1} and instead saw {x0}"))
@@ -57,7 +57,7 @@ impl Rule for Eqeqeq {
5757
}
5858
}
5959

60-
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
60+
fn run<'a>(&self, node: &Node<'a>, ctx: &LintContext<'a>) {
6161
let AstKind::BinaryExpression(binary_expr) = node.kind() else {
6262
return;
6363
};

crates/oxc_linter/src/rules/eslint/for_direction.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use oxc_macros::declare_oxc_lint;
1010
use oxc_span::{GetSpan, Span};
1111
use oxc_syntax::operator::{AssignmentOperator, BinaryOperator, UnaryOperator, UpdateOperator};
1212

13-
use crate::{context::LintContext, rule::Rule, AstNode};
13+
use crate::{context::LintContext, rule::Rule, Node};
1414

1515
fn for_direction_diagnostic(span: Span, span1: Span) -> OxcDiagnostic {
1616
OxcDiagnostic::warn("The update clause in this loop moves the variable in the wrong direction")
@@ -82,7 +82,7 @@ declare_oxc_lint!(
8282
);
8383

8484
impl Rule for ForDirection {
85-
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
85+
fn run<'a>(&self, node: &Node<'a>, ctx: &LintContext<'a>) {
8686
let AstKind::ForStatement(for_loop) = node.kind() else {
8787
return;
8888
};

crates/oxc_linter/src/rules/eslint/func_names.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use oxc_span::{Atom, GetSpan, Span};
1414
use oxc_syntax::identifier::is_identifier_name;
1515
use phf::phf_set;
1616

17-
use crate::{context::LintContext, rule::Rule, AstNode};
17+
use crate::{context::LintContext, rule::Rule, Node};
1818

1919
fn named_diagnostic(function_name: &str, span: Span) -> OxcDiagnostic {
2020
OxcDiagnostic::warn(format!("Unexpected named {function_name}."))
@@ -43,7 +43,7 @@ enum FuncNamesConfig {
4343
}
4444

4545
impl FuncNamesConfig {
46-
fn is_invalid_function(self, func: &Function, parent_node: &AstNode<'_>) -> bool {
46+
fn is_invalid_function(self, func: &Function, parent_node: &Node<'_>) -> bool {
4747
let func_name = func.name();
4848

4949
match self {
@@ -147,7 +147,7 @@ declare_oxc_lint!(
147147

148148
/// Determines whether the current FunctionExpression node is a get, set, or
149149
/// shorthand method in an object literal or a class.
150-
fn is_object_or_class_method(parent_node: &AstNode) -> bool {
150+
fn is_object_or_class_method(parent_node: &Node) -> bool {
151151
match parent_node.kind() {
152152
AstKind::MethodDefinition(_) => true,
153153
AstKind::ObjectProperty(property) => {
@@ -161,7 +161,7 @@ fn is_object_or_class_method(parent_node: &AstNode) -> bool {
161161

162162
/// Determines whether the current FunctionExpression node has a name that would be
163163
/// inferred from context in a conforming ES6 environment.
164-
fn has_inferred_name<'a>(function: &Function<'a>, parent_node: &AstNode<'a>) -> bool {
164+
fn has_inferred_name<'a>(function: &Function<'a>, parent_node: &Node<'a>) -> bool {
165165
if is_object_or_class_method(parent_node) {
166166
return true;
167167
}
@@ -255,7 +255,7 @@ fn get_property_key_name<'a>(key: &PropertyKey<'a>) -> Option<Cow<'a, str>> {
255255
}
256256
}
257257

258-
fn get_static_property_name<'a>(parent_node: &AstNode<'a>) -> Option<Cow<'a, str>> {
258+
fn get_static_property_name<'a>(parent_node: &Node<'a>) -> Option<Cow<'a, str>> {
259259
let (key, computed) = match parent_node.kind() {
260260
AstKind::PropertyDefinition(definition) => (&definition.key, definition.computed),
261261
AstKind::MethodDefinition(method_definition) => {
@@ -274,7 +274,7 @@ fn get_static_property_name<'a>(parent_node: &AstNode<'a>) -> Option<Cow<'a, str
274274

275275
/// Gets the name and kind of the given function node.
276276
/// @see <https://github.com/eslint/eslint/blob/48117b27e98639ffe7e78a230bfad9a93039fb7f/lib/rules/utils/ast-utils.js#L1762>
277-
fn get_function_name_with_kind<'a>(func: &Function<'a>, parent_node: &AstNode<'a>) -> Cow<'a, str> {
277+
fn get_function_name_with_kind<'a>(func: &Function<'a>, parent_node: &Node<'a>) -> Cow<'a, str> {
278278
let mut tokens: Vec<Cow<'a, str>> = vec![];
279279

280280
match parent_node.kind() {
@@ -370,7 +370,7 @@ impl Rule for FuncNames {
370370
}
371371

372372
fn run_once(&self, ctx: &LintContext<'_>) {
373-
let mut invalid_funcs: Vec<(&Function, &AstNode)> = vec![];
373+
let mut invalid_funcs: Vec<(&Function, &Node)> = vec![];
374374

375375
for node in ctx.nodes().iter() {
376376
match node.kind() {
@@ -480,7 +480,7 @@ impl Rule for FuncNames {
480480
}
481481

482482
fn guess_function_name<'a>(ctx: &LintContext<'a>, parent_id: NodeId) -> Option<Cow<'a, str>> {
483-
for parent_kind in ctx.nodes().iter_parents(parent_id).map(AstNode::kind) {
483+
for parent_kind in ctx.nodes().iter_parents(parent_id).map(Node::kind) {
484484
match parent_kind {
485485
AstKind::ParenthesizedExpression(_)
486486
| AstKind::TSAsExpression(_)

crates/oxc_linter/src/rules/eslint/getter_return.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use oxc_diagnostics::OxcDiagnostic;
1616
use oxc_macros::declare_oxc_lint;
1717
use oxc_span::Span;
1818

19-
use crate::{context::LintContext, rule::Rule, AstNode};
19+
use crate::{context::LintContext, rule::Rule, Node};
2020

2121
fn getter_return_diagnostic(span: Span) -> OxcDiagnostic {
2222
OxcDiagnostic::warn("Expected to always return a value in getter.")
@@ -56,7 +56,7 @@ declare_oxc_lint!(
5656
);
5757

5858
impl Rule for GetterReturn {
59-
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
59+
fn run<'a>(&self, node: &Node<'a>, ctx: &LintContext<'a>) {
6060
// https://eslint.org/docs/latest/rules/getter-return#handled_by_typescript
6161
if ctx.source_type().is_typescript() {
6262
return;
@@ -119,7 +119,7 @@ impl GetterReturn {
119119
}
120120

121121
/// Checks whether it is necessary to check the node
122-
fn is_wanted_node(node: &AstNode, ctx: &LintContext<'_>) -> Option<bool> {
122+
fn is_wanted_node(node: &Node, ctx: &LintContext<'_>) -> Option<bool> {
123123
let parent = ctx.nodes().parent_node(node.id())?;
124124
match parent.kind() {
125125
AstKind::MethodDefinition(mdef) => {
@@ -177,7 +177,7 @@ impl GetterReturn {
177177
Some(false)
178178
}
179179

180-
fn run_diagnostic<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>, span: Span) {
180+
fn run_diagnostic<'a>(&self, node: &Node<'a>, ctx: &LintContext<'a>, span: Span) {
181181
if !Self::is_wanted_node(node, ctx).unwrap_or_default() {
182182
return;
183183
}

crates/oxc_linter/src/rules/eslint/guard_for_in.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use oxc_diagnostics::OxcDiagnostic;
33
use oxc_macros::declare_oxc_lint;
44
use oxc_span::{GetSpan, Span};
55

6-
use crate::{context::LintContext, rule::Rule, AstNode};
6+
use crate::{context::LintContext, rule::Rule, Node};
77

88
fn guard_for_in_diagnostic(span: Span) -> OxcDiagnostic {
99
OxcDiagnostic::warn("Require `for-in` loops to include an `if` statement")
@@ -32,7 +32,7 @@ declare_oxc_lint!(
3232
);
3333

3434
impl Rule for GuardForIn {
35-
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
35+
fn run<'a>(&self, node: &Node<'a>, ctx: &LintContext<'a>) {
3636
if let AstKind::ForInStatement(for_in_statement) = node.kind() {
3737
match &for_in_statement.body {
3838
Statement::EmptyStatement(_) | Statement::IfStatement(_) => return,

0 commit comments

Comments
 (0)