refactor(semantic): mark SemanticTester and SymbolTester as must_use (#4430)

This commit is contained in:
DonIsaac 2024-07-24 16:58:11 +00:00
parent 4b274a8e6f
commit 4f5a7cbf3c
2 changed files with 2 additions and 15 deletions

View file

@ -13,6 +13,7 @@ use oxc_semantic::{dot::DebugDot, Semantic, SemanticBuilder, SemanticBuilderRetu
use oxc_span::SourceType; use oxc_span::SourceType;
pub use symbol_tester::SymbolTester; pub use symbol_tester::SymbolTester;
#[must_use]
pub struct SemanticTester<'a> { pub struct SemanticTester<'a> {
allocator: Allocator, allocator: Allocator,
source_type: SourceType, source_type: SourceType,
@ -57,26 +58,22 @@ impl<'a> SemanticTester<'a> {
} }
/// Set the [`SourceType`] to TypeScript (or JavaScript, using `false`) /// Set the [`SourceType`] to TypeScript (or JavaScript, using `false`)
#[must_use]
pub fn with_typescript(mut self, yes: bool) -> Self { pub fn with_typescript(mut self, yes: bool) -> Self {
self.source_type = SourceType::default().with_typescript(yes); self.source_type = SourceType::default().with_typescript(yes);
self self
} }
/// Mark the [`SourceType`] as JSX /// Mark the [`SourceType`] as JSX
#[must_use]
pub fn with_jsx(mut self, yes: bool) -> Self { pub fn with_jsx(mut self, yes: bool) -> Self {
self.source_type = self.source_type.with_jsx(yes); self.source_type = self.source_type.with_jsx(yes);
self self
} }
#[must_use]
pub fn with_module(mut self, yes: bool) -> Self { pub fn with_module(mut self, yes: bool) -> Self {
self.source_type = self.source_type.with_module(yes); self.source_type = self.source_type.with_module(yes);
self self
} }
#[must_use]
pub fn with_cfg(mut self, yes: bool) -> Self { pub fn with_cfg(mut self, yes: bool) -> Self {
self.cfg = yes; self.cfg = yes;
self self
@ -94,7 +91,6 @@ impl<'a> SemanticTester<'a> {
/// // Not allowed in TS /// // Not allowed in TS
/// T::ts("function foo(a, a) { }").expect_errors(true).has_root_symbol("foo").test() /// T::ts("function foo(a, a) { }").expect_errors(true).has_root_symbol("foo").test()
/// ``` /// ```
#[must_use]
pub fn expect_errors(mut self, yes: bool) -> Self { pub fn expect_errors(mut self, yes: bool) -> Self {
self.expect_errors = yes; self.expect_errors = yes;
self self

View file

@ -6,6 +6,7 @@ use oxc_span::CompactStr;
use super::{Expect, SemanticTester}; use super::{Expect, SemanticTester};
#[must_use]
pub struct SymbolTester<'a> { pub struct SymbolTester<'a> {
parent: &'a SemanticTester<'a>, parent: &'a SemanticTester<'a>,
/// Reference to semantic analysis results, from [`SemanticTester`] /// Reference to semantic analysis results, from [`SemanticTester`]
@ -94,7 +95,6 @@ impl<'a> SymbolTester<'a> {
} }
/// Checks if the resolved symbol contains all flags in `flags`, using [`SymbolFlags::contains()`] /// Checks if the resolved symbol contains all flags in `flags`, using [`SymbolFlags::contains()`]
#[must_use]
pub fn contains_flags(mut self, flags: SymbolFlags) -> Self { pub fn contains_flags(mut self, flags: SymbolFlags) -> Self {
self.test_result = match self.test_result { self.test_result = match self.test_result {
Ok(symbol_id) => { Ok(symbol_id) => {
@ -113,7 +113,6 @@ impl<'a> SymbolTester<'a> {
self self
} }
#[must_use]
pub fn intersects_flags(mut self, flags: SymbolFlags) -> Self { pub fn intersects_flags(mut self, flags: SymbolFlags) -> Self {
self.test_result = match self.test_result { self.test_result = match self.test_result {
Ok(symbol_id) => { Ok(symbol_id) => {
@ -132,22 +131,18 @@ impl<'a> SymbolTester<'a> {
self self
} }
#[must_use]
pub fn has_number_of_reads(self, ref_count: usize) -> Self { pub fn has_number_of_reads(self, ref_count: usize) -> Self {
self.has_number_of_references_where(ref_count, Reference::is_read) self.has_number_of_references_where(ref_count, Reference::is_read)
} }
#[must_use]
pub fn has_number_of_writes(self, ref_count: usize) -> Self { pub fn has_number_of_writes(self, ref_count: usize) -> Self {
self.has_number_of_references_where(ref_count, Reference::is_write) self.has_number_of_references_where(ref_count, Reference::is_write)
} }
#[must_use]
pub fn has_number_of_references(self, ref_count: usize) -> Self { pub fn has_number_of_references(self, ref_count: usize) -> Self {
self.has_number_of_references_where(ref_count, |_| true) self.has_number_of_references_where(ref_count, |_| true)
} }
#[must_use]
pub fn has_number_of_references_where<F>(mut self, ref_count: usize, filter: F) -> Self pub fn has_number_of_references_where<F>(mut self, ref_count: usize, filter: F) -> Self
where where
F: FnMut(&Reference) -> bool, F: FnMut(&Reference) -> bool,
@ -176,7 +171,6 @@ impl<'a> SymbolTester<'a> {
} }
#[allow(clippy::wrong_self_convention)] #[allow(clippy::wrong_self_convention)]
#[must_use]
pub fn is_exported(mut self) -> Self { pub fn is_exported(mut self) -> Self {
self.test_result = match self.test_result { self.test_result = match self.test_result {
Ok(symbol_id) => { Ok(symbol_id) => {
@ -195,7 +189,6 @@ impl<'a> SymbolTester<'a> {
} }
#[allow(clippy::wrong_self_convention)] #[allow(clippy::wrong_self_convention)]
#[must_use]
pub fn is_not_exported(mut self) -> Self { pub fn is_not_exported(mut self) -> Self {
self.test_result = match self.test_result { self.test_result = match self.test_result {
Ok(symbol_id) => { Ok(symbol_id) => {
@ -214,7 +207,6 @@ impl<'a> SymbolTester<'a> {
} }
#[allow(clippy::wrong_self_convention)] #[allow(clippy::wrong_self_convention)]
#[must_use]
pub fn is_in_scope(mut self, expected_flags: ScopeFlags) -> Self { pub fn is_in_scope(mut self, expected_flags: ScopeFlags) -> Self {
let target_name: &str = self.target_symbol_name.as_ref(); let target_name: &str = self.target_symbol_name.as_ref();
self.test_result = match self.test_result { self.test_result = match self.test_result {
@ -235,7 +227,6 @@ impl<'a> SymbolTester<'a> {
} }
#[allow(clippy::wrong_self_convention)] #[allow(clippy::wrong_self_convention)]
#[must_use]
pub fn is_not_in_scope(mut self, excluded_flags: ScopeFlags) -> Self { pub fn is_not_in_scope(mut self, excluded_flags: ScopeFlags) -> Self {
let target_name: &str = self.target_symbol_name.as_ref(); let target_name: &str = self.target_symbol_name.as_ref();
self.test_result = match self.test_result { self.test_result = match self.test_result {