Skip to content

Commit c7f43f7

Browse files
committed
wip: skip rules that do not have any relevant node types
1 parent 8e31c70 commit c7f43f7

File tree

8 files changed

+46
-4
lines changed

8 files changed

+46
-4
lines changed

crates/oxc_linter/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub use crate::{
5656
module_record::ModuleRecord,
5757
options::LintOptions,
5858
options::{AllowWarnDeny, InvalidFilterKind, LintFilter, LintFilterKind},
59-
rule::{RuleCategory, RuleFixMeta, RuleMeta},
59+
rule::{RuleCategory, RuleFixMeta, RuleMeta, RuleRunner},
6060
service::{LintService, LintServiceOptions, RuntimeFileSystem},
6161
tsgolint::TsGoLintState,
6262
utils::{read_to_arena_str, read_to_string},

crates/oxc_linter/src/rule.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{fmt, hash::Hash};
55
use schemars::{JsonSchema, SchemaGenerator, schema::Schema};
66
use serde::{Deserialize, Serialize};
77

8-
use oxc_semantic::SymbolId;
8+
use oxc_semantic::{AstTypesBitset, SymbolId};
99

1010
use crate::{
1111
AstNode, FixKind,
@@ -66,6 +66,16 @@ pub trait Rule: Sized + Default + fmt::Debug {
6666
}
6767
}
6868

69+
pub trait RuleRunner: Rule {
70+
/// `AstType`s that rule acts on
71+
const NODE_TYPES: &AstTypesBitset;
72+
/// `true` if codegen can't figure out what node types rule acts on
73+
const ANY_NODE_TYPE: bool;
74+
75+
fn types_info(&self) -> (&'static AstTypesBitset, bool) {
76+
(Self::NODE_TYPES, Self::ANY_NODE_TYPE)
77+
}
78+
}
6979
pub trait RuleMeta {
7080
const NAME: &'static str;
7181

crates/oxc_linter/src/tsgolint.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ impl TsGoLintState {
7777
return Err(format!("Failed to write to tsgolint stdin: {e}"));
7878
}
7979
}
80+
dbg!(&json_input);
8081
// Explicitly drop stdin to send EOF to the child.
8182
drop(stdin);
8283

crates/oxc_macros/src/declare_all_lint_rules.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn declare_all_lint_rules(metadata: AllLintRulesMeta) -> TokenStream {
8282
utils::PossibleJestNode,
8383
AstNode
8484
};
85-
use oxc_semantic::SymbolId;
85+
use oxc_semantic::{AstTypesBitset, SymbolId};
8686

8787
#[derive(Debug, Clone)]
8888
#[expect(clippy::enum_variant_names)]
@@ -183,6 +183,12 @@ pub fn declare_all_lint_rules(metadata: AllLintRulesMeta) -> TokenStream {
183183
#(Self::#struct_names(rule) => #struct_names::IS_TSGOLINT_RULE),*
184184
}
185185
}
186+
187+
fn types_info(&self) -> (&'static AstTypesBitset, bool) {
188+
match self {
189+
#(Self::#struct_names(rule) => #struct_names.types_info()),*
190+
}
191+
}
186192
}
187193

188194
impl std::hash::Hash for RuleEnum {

crates/oxc_macros/src/declare_oxc_lint.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ pub fn declare_oxc_lint(metadata: LintRuleMeta) -> TokenStream {
173173
let import_statement = if used_in_test {
174174
None
175175
} else {
176-
Some(quote! { use crate::{rule::{RuleCategory, RuleMeta, RuleFixMeta}, fixer::FixKind}; })
176+
Some(quote! {
177+
use crate::{rule::{RuleCategory, RuleMeta, RuleFixMeta, RuleRunner}, fixer::FixKind};
178+
use oxc_semantic::AstTypesBitset;
179+
})
177180
};
178181

179182
#[cfg(not(feature = "ruledocs"))]
@@ -223,6 +226,16 @@ pub fn declare_oxc_lint(metadata: LintRuleMeta) -> TokenStream {
223226

224227
#config_schema
225228
}
229+
230+
impl RuleRunner for #name {
231+
const NODE_TYPES: &'static AstTypesBitset = &AstTypesBitset::new();
232+
233+
const ANY_NODE_TYPE: bool = true;
234+
235+
fn types_info(&self) -> (&'static AstTypesBitset, bool) {
236+
(Self::NODE_TYPES, Self::ANY_NODE_TYPE)
237+
}
238+
}
226239
};
227240

228241
TokenStream::from(output)

crates/oxc_semantic/src/ast_types_bitset.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ impl AstTypesBitset {
1616
Self([0; NUM_USIZES])
1717
}
1818

19+
pub const fn from_types(types: &[AstType]) -> Self {
20+
let mut bitset = Self::new();
21+
let mut i = 0;
22+
while i < types.len() {
23+
bitset.set(types[i]);
24+
i += 1;
25+
}
26+
bitset
27+
}
28+
1929
/// Returns `true` if bit is set for provided [`AstType`].
2030
pub const fn has(&self, ty: AstType) -> bool {
2131
let (index, mask) = Self::index_and_mask(ty);

crates/oxc_semantic/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ mod scoping;
3636
mod stats;
3737
mod unresolved_stack;
3838

39+
pub use ast_types_bitset::AstTypesBitset;
3940
pub use builder::{SemanticBuilder, SemanticBuilderReturn};
4041
pub use is_global_reference::IsGlobalReference;
4142
pub use jsdoc::{JSDoc, JSDocFinder, JSDocTag};

vscode

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../vscode

0 commit comments

Comments
 (0)