Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions crates/oxc_semantic/tests/integration/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use oxc_semantic::{dot::DebugDot, Semantic, SemanticBuilder, SemanticBuilderRetu
use oxc_span::SourceType;
pub use symbol_tester::SymbolTester;

#[must_use]
pub struct SemanticTester<'a> {
allocator: Allocator,
source_type: SourceType,
Expand Down Expand Up @@ -57,26 +58,22 @@ impl<'a> SemanticTester<'a> {
}

/// Set the [`SourceType`] to TypeScript (or JavaScript, using `false`)
#[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
#[must_use]
pub fn with_jsx(mut self, yes: bool) -> Self {
self.source_type = self.source_type.with_jsx(yes);
self
}

#[must_use]
pub fn with_module(mut self, yes: bool) -> Self {
self.source_type = self.source_type.with_module(yes);
self
}

#[must_use]
pub fn with_cfg(mut self, yes: bool) -> Self {
self.cfg = yes;
self
Expand All @@ -94,7 +91,6 @@ impl<'a> SemanticTester<'a> {
/// // Not allowed in TS
/// 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 {
self.expect_errors = yes;
self
Expand Down
11 changes: 1 addition & 10 deletions crates/oxc_semantic/tests/integration/util/symbol_tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use oxc_span::CompactStr;

use super::{Expect, SemanticTester};

#[must_use]
pub struct SymbolTester<'a> {
parent: &'a SemanticTester<'a>,
/// Reference to semantic analysis results, from [`SemanticTester`]
Expand Down Expand Up @@ -94,7 +95,6 @@ impl<'a> SymbolTester<'a> {
}

/// Checks if the resolved symbol contains all flags in `flags`, using [`SymbolFlags::contains()`]
#[must_use]
pub fn contains_flags(mut self, flags: SymbolFlags) -> Self {
self.test_result = match self.test_result {
Ok(symbol_id) => {
Expand All @@ -113,7 +113,6 @@ impl<'a> SymbolTester<'a> {
self
}

#[must_use]
pub fn intersects_flags(mut self, flags: SymbolFlags) -> Self {
self.test_result = match self.test_result {
Ok(symbol_id) => {
Expand All @@ -132,22 +131,18 @@ impl<'a> SymbolTester<'a> {
self
}

#[must_use]
pub fn has_number_of_reads(self, ref_count: usize) -> Self {
self.has_number_of_references_where(ref_count, Reference::is_read)
}

#[must_use]
pub fn has_number_of_writes(self, ref_count: usize) -> Self {
self.has_number_of_references_where(ref_count, Reference::is_write)
}

#[must_use]
pub fn has_number_of_references(self, ref_count: usize) -> Self {
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
where
F: FnMut(&Reference) -> bool,
Expand Down Expand Up @@ -176,7 +171,6 @@ impl<'a> SymbolTester<'a> {
}

#[allow(clippy::wrong_self_convention)]
#[must_use]
pub fn is_exported(mut self) -> Self {
self.test_result = match self.test_result {
Ok(symbol_id) => {
Expand All @@ -195,7 +189,6 @@ impl<'a> SymbolTester<'a> {
}

#[allow(clippy::wrong_self_convention)]
#[must_use]
pub fn is_not_exported(mut self) -> Self {
self.test_result = match self.test_result {
Ok(symbol_id) => {
Expand All @@ -214,7 +207,6 @@ impl<'a> SymbolTester<'a> {
}

#[allow(clippy::wrong_self_convention)]
#[must_use]
pub fn is_in_scope(mut self, expected_flags: ScopeFlags) -> Self {
let target_name: &str = self.target_symbol_name.as_ref();
self.test_result = match self.test_result {
Expand All @@ -235,7 +227,6 @@ impl<'a> SymbolTester<'a> {
}

#[allow(clippy::wrong_self_convention)]
#[must_use]
pub fn is_not_in_scope(mut self, excluded_flags: ScopeFlags) -> Self {
let target_name: &str = self.target_symbol_name.as_ref();
self.test_result = match self.test_result {
Expand Down