From fc1592bc97bb5cf2509dc965662b600d656aed82 Mon Sep 17 00:00:00 2001 From: Boshen Date: Thu, 25 Jan 2024 20:27:46 +0800 Subject: [PATCH] refactor(semantic): remove all #[dead_code[ from tester --- crates/oxc_semantic/tests/cfg.rs | 3 +-- crates/oxc_semantic/tests/classes.rs | 6 +++--- crates/oxc_semantic/tests/modules.rs | 3 +-- crates/oxc_semantic/tests/scopes.rs | 10 +++++----- crates/oxc_semantic/tests/symbols.rs | 2 +- crates/oxc_semantic/tests/util/class_tester.rs | 1 - crates/oxc_semantic/tests/util/expect.rs | 1 + crates/oxc_semantic/tests/util/mod.rs | 15 ++++----------- crates/oxc_semantic/tests/util/symbol_tester.rs | 3 --- 9 files changed, 16 insertions(+), 28 deletions(-) diff --git a/crates/oxc_semantic/tests/cfg.rs b/crates/oxc_semantic/tests/cfg.rs index dcec66933..0f0b1fdd6 100644 --- a/crates/oxc_semantic/tests/cfg.rs +++ b/crates/oxc_semantic/tests/cfg.rs @@ -3,8 +3,7 @@ mod util; use std::fs; use oxc_span::SourceType; -#[allow(clippy::wildcard_imports)] -use util::*; +pub use util::SemanticTester; #[test] fn test_cfg_files() { diff --git a/crates/oxc_semantic/tests/classes.rs b/crates/oxc_semantic/tests/classes.rs index 13792566c..7d39ff202 100644 --- a/crates/oxc_semantic/tests/classes.rs +++ b/crates/oxc_semantic/tests/classes.rs @@ -1,6 +1,6 @@ mod util; -use util::SemanticTester; +pub use util::SemanticTester; #[test] fn test_class_simple() { @@ -15,7 +15,7 @@ fn test_class_simple() { set b(v) {} get b() {} } - + ", ) .has_class("Foo") @@ -33,7 +33,7 @@ fn test_class_with_ts() { accessor #pap = 1; constructor() {} // this method is skip } - + ", ) .has_class("Foo") diff --git a/crates/oxc_semantic/tests/modules.rs b/crates/oxc_semantic/tests/modules.rs index 928a4795b..abd397e59 100644 --- a/crates/oxc_semantic/tests/modules.rs +++ b/crates/oxc_semantic/tests/modules.rs @@ -1,7 +1,6 @@ mod util; -#[allow(clippy::wildcard_imports)] -use util::*; +pub use util::SemanticTester; #[test] fn test_exports() { diff --git a/crates/oxc_semantic/tests/scopes.rs b/crates/oxc_semantic/tests/scopes.rs index 3ecf4cdb5..dea32f60c 100644 --- a/crates/oxc_semantic/tests/scopes.rs +++ b/crates/oxc_semantic/tests/scopes.rs @@ -1,7 +1,7 @@ mod util; use oxc_semantic::ScopeFlags; -use util::{Expect, SemanticTester}; +pub use util::{Expect, SemanticTester}; #[test] fn test_top_level_strict() { @@ -11,7 +11,7 @@ fn test_top_level_strict() { "use strict"; function foo() { return 1 - } + } "#, ) .has_root_symbol("foo") @@ -24,7 +24,7 @@ fn test_top_level_strict() { r" function foo() { return 1 - } + } ", ) .has_root_symbol("foo") @@ -37,7 +37,7 @@ fn test_top_level_strict() { "use strict"; function foo() { return 1 - } + } "#, ) .with_module(false) @@ -50,7 +50,7 @@ fn test_top_level_strict() { r" function foo() { return 1 - } + } ", ) .with_module(false) diff --git a/crates/oxc_semantic/tests/symbols.rs b/crates/oxc_semantic/tests/symbols.rs index c053da081..c8ea47cdb 100644 --- a/crates/oxc_semantic/tests/symbols.rs +++ b/crates/oxc_semantic/tests/symbols.rs @@ -1,7 +1,7 @@ mod util; use oxc_semantic::SymbolFlags; -use util::SemanticTester; +pub use util::SemanticTester; #[test] fn test_class_simple() { diff --git a/crates/oxc_semantic/tests/util/class_tester.rs b/crates/oxc_semantic/tests/util/class_tester.rs index 8501f9ee7..fca215162 100644 --- a/crates/oxc_semantic/tests/util/class_tester.rs +++ b/crates/oxc_semantic/tests/util/class_tester.rs @@ -10,7 +10,6 @@ pub struct ClassTester<'a> { class_id: ClassId, } -#[allow(dead_code)] // Only used in #[test] impl<'a> ClassTester<'a> { pub(super) fn has_class(semantic: Semantic<'a>, name: &str) -> Self { let class_id = semantic.classes().iter_enumerated().find_map(|(class_id, ast_node_id)| { diff --git a/crates/oxc_semantic/tests/util/expect.rs b/crates/oxc_semantic/tests/util/expect.rs index de49affb6..6c40d81ba 100644 --- a/crates/oxc_semantic/tests/util/expect.rs +++ b/crates/oxc_semantic/tests/util/expect.rs @@ -1,4 +1,5 @@ pub trait Expect { + #[must_use] fn expect(self, expectation: F) -> Self where F: FnOnce(P) -> R; diff --git a/crates/oxc_semantic/tests/util/mod.rs b/crates/oxc_semantic/tests/util/mod.rs index ea6dfdf34..b5e814596 100644 --- a/crates/oxc_semantic/tests/util/mod.rs +++ b/crates/oxc_semantic/tests/util/mod.rs @@ -25,7 +25,6 @@ impl<'a> SemanticTester<'a> { /// Create a new tester for a TypeScript test case. /// /// Use [`SemanticTester::js`] for JavaScript test cases. - #[allow(dead_code)] pub fn ts(source_text: &'static str) -> Self { Self::new(source_text, SourceType::default().with_module(true).with_typescript(true)) } @@ -33,7 +32,6 @@ impl<'a> SemanticTester<'a> { /// Create a new tester for a JavaScript test case. /// /// Use [`SemanticTester::ts`] for TypeScript test cases. - #[allow(dead_code)] pub fn js(source_text: &'static str) -> Self { Self::new(source_text, SourceType::default().with_module(true)) } @@ -43,26 +41,27 @@ impl<'a> SemanticTester<'a> { } /// Set the [`SourceType`] to TypeScript (or JavaScript, using `false`) - #[allow(dead_code)] + #[must_use] pub fn with_typescript(mut self, yes: bool) -> Self { self.source_type = SourceType::default().with_typescript(yes); self } /// Mark the [`SourceType`] as JSX - #[allow(dead_code)] + #[must_use] pub fn with_jsx(mut self, yes: bool) -> Self { self.source_type = self.source_type.with_jsx(yes); self } - #[allow(dead_code)] + #[must_use] pub fn with_module(mut self, yes: bool) -> Self { self.source_type = self.source_type.with_module(yes); self } /// Parse the source text and produce a new [`Semantic`] + /// # Panics #[allow(unstable_name_collisions)] pub fn build(&self) -> Semantic<'_> { let parse = @@ -102,13 +101,11 @@ impl<'a> SemanticTester<'a> { semantic_ret.semantic } - #[allow(dead_code)] pub fn basic_blocks_count(&self) -> usize { let built = self.build(); built.cfg().basic_blocks.len() } - #[allow(dead_code)] pub fn basic_blocks_printed(&self) -> String { let built = self.build(); built @@ -126,7 +123,6 @@ impl<'a> SemanticTester<'a> { .join("\n\n") } - #[allow(dead_code)] pub fn cfg_dot_diagram(&self) -> String { let built = self.build(); format!( @@ -151,7 +147,6 @@ impl<'a> SemanticTester<'a> { /// /// ## Fails /// If no symbol with the given name exists at the top-level scope. - #[allow(dead_code)] pub fn has_root_symbol(&self, name: &str) -> SymbolTester { SymbolTester::new_at_root(self, self.build(), name) } @@ -160,7 +155,6 @@ impl<'a> SemanticTester<'a> { /// /// ## Fails /// If no class with the given name exists. - #[allow(dead_code)] pub fn has_class(&self, name: &str) -> ClassTester { ClassTester::has_class(self.build(), name) } @@ -171,7 +165,6 @@ impl<'a> SemanticTester<'a> { /// 1. No symbol with the given name exists, /// 2. More than one symbol with the given name exists, so a symbol cannot /// be uniquely obtained. - #[allow(dead_code)] pub fn has_some_symbol(&self, name: &str) -> SymbolTester { SymbolTester::new_unique(self, self.build(), name) } diff --git a/crates/oxc_semantic/tests/util/symbol_tester.rs b/crates/oxc_semantic/tests/util/symbol_tester.rs index 983818128..17c319e2b 100644 --- a/crates/oxc_semantic/tests/util/symbol_tester.rs +++ b/crates/oxc_semantic/tests/util/symbol_tester.rs @@ -18,7 +18,6 @@ pub struct SymbolTester<'a> { } impl<'a> SymbolTester<'a> { - #[allow(dead_code)] pub(super) fn new_at_root( parent: &'a SemanticTester, semantic: Semantic<'a>, @@ -36,7 +35,6 @@ impl<'a> SymbolTester<'a> { } } - #[allow(dead_code)] pub(super) fn new_unique( parent: &'a SemanticTester, semantic: Semantic<'a>, @@ -104,7 +102,6 @@ impl<'a> SymbolTester<'a> { self.has_number_of_references_where(ref_count, Reference::is_read) } - #[allow(dead_code)] pub fn has_number_of_writes(self, ref_count: usize) -> Self { self.has_number_of_references_where(ref_count, Reference::is_write) }