Skip to content

Commit 24a8c14

Browse files
gaurav-rk9connorshea
authored andcommitted
docs(linter/rules): correct arrow body style options in documentation (#16509)
Comment fix (https://eslint.org/docs/latest/rules/arrow-body-style) --------- Signed-off-by: GRK <[email protected]> Co-authored-by: Connor Shea <[email protected]>
1 parent 514c724 commit 24a8c14

File tree

145 files changed

+1421
-991
lines changed

Some content is hidden

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

145 files changed

+1421
-991
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/oxlint/src-js/generated/deserialize.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ function deserializeIdentifierName(pos) {
201201
__proto__: NodeProto,
202202
type: "Identifier",
203203
decorators: null,
204-
name: deserializeStr(pos + 8),
204+
name: deserializeIdent(pos + 8),
205205
optional: null,
206206
typeAnnotation: null,
207207
start,
@@ -223,7 +223,7 @@ function deserializeIdentifierReference(pos) {
223223
__proto__: NodeProto,
224224
type: "Identifier",
225225
decorators: null,
226-
name: deserializeStr(pos + 8),
226+
name: deserializeIdent(pos + 8),
227227
optional: null,
228228
typeAnnotation: null,
229229
start,
@@ -245,7 +245,7 @@ function deserializeBindingIdentifier(pos) {
245245
__proto__: NodeProto,
246246
type: "Identifier",
247247
decorators: null,
248-
name: deserializeStr(pos + 8),
248+
name: deserializeIdent(pos + 8),
249249
optional: null,
250250
typeAnnotation: null,
251251
start,
@@ -267,7 +267,7 @@ function deserializeLabelIdentifier(pos) {
267267
__proto__: NodeProto,
268268
type: "Identifier",
269269
decorators: null,
270-
name: deserializeStr(pos + 8),
270+
name: deserializeIdent(pos + 8),
271271
optional: null,
272272
typeAnnotation: null,
273273
start,
@@ -2649,7 +2649,7 @@ function deserializePrivateIdentifier(pos) {
26492649
return {
26502650
__proto__: NodeProto,
26512651
type: "PrivateIdentifier",
2652-
name: deserializeStr(pos + 8),
2652+
name: deserializeIdent(pos + 8),
26532653
start,
26542654
end,
26552655
range: [start, end],
@@ -3685,7 +3685,7 @@ function deserializeJSXIdentifier(pos) {
36853685
return {
36863686
__proto__: NodeProto,
36873687
type: "JSXIdentifier",
3688-
name: deserializeStr(pos + 8),
3688+
name: deserializeIdent(pos + 8),
36893689
start,
36903690
end,
36913691
range: [start, end],

crates/oxc_allocator/src/clone_in.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
use std::{alloc::Layout, cell::Cell, hash::Hash, ptr::NonNull, slice};
1+
use std::{
2+
alloc::Layout,
3+
cell::Cell,
4+
hash::{BuildHasher, Hash},
5+
ptr::NonNull,
6+
slice,
7+
};
28

3-
use crate::{Allocator, Box, HashMap, Vec};
9+
use crate::{Allocator, Box, HashMapImpl, Vec};
410

511
/// A trait to explicitly clone an object into an arena allocator.
612
///
@@ -207,13 +213,14 @@ where
207213
}
208214
}
209215

210-
impl<'new_alloc, K, V, CK, CV> CloneIn<'new_alloc> for HashMap<'_, K, V>
216+
impl<'new_alloc, K, V, CK, CV, H> CloneIn<'new_alloc> for HashMapImpl<'_, K, V, H>
211217
where
212218
K: CloneIn<'new_alloc, Cloned = CK>,
213219
V: CloneIn<'new_alloc, Cloned = CV>,
214220
CK: Hash + Eq,
221+
H: BuildHasher + Default,
215222
{
216-
type Cloned = HashMap<'new_alloc, CK, CV>;
223+
type Cloned = HashMapImpl<'new_alloc, CK, CV, H>;
217224

218225
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
219226
// Keys in original hash map are guaranteed to be unique.
@@ -223,15 +230,15 @@ where
223230
// `hashbrown::HashMap` also has a faster cloning method in its `Clone` implementation,
224231
// but those APIs are not exposed, and `Clone` doesn't support custom allocators.
225232
// So sadly this is a lot slower than it could be, especially for `Copy` types.
226-
let mut cloned = HashMap::with_capacity_in(self.len(), allocator);
233+
let mut cloned = HashMapImpl::with_capacity_in(self.len(), allocator);
227234
for (key, value) in self {
228235
cloned.insert(key.clone_in(allocator), value.clone_in(allocator));
229236
}
230237
cloned
231238
}
232239

233240
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
234-
let mut cloned = HashMap::with_capacity_in(self.len(), allocator);
241+
let mut cloned = HashMapImpl::with_capacity_in(self.len(), allocator);
235242
for (key, value) in self {
236243
cloned.insert(
237244
key.clone_in_with_semantic_ids(allocator),
@@ -281,7 +288,8 @@ impl_clone_in! {
281288

282289
#[cfg(test)]
283290
mod test {
284-
use super::{Allocator, CloneIn, HashMap, Vec};
291+
use super::{Allocator, CloneIn, Vec};
292+
use crate::HashMap;
285293

286294
#[test]
287295
fn clone_in_boxed_slice() {

crates/oxc_allocator/src/hash_map.rs

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
#![expect(clippy::inline_always)]
99

1010
use std::{
11-
hash::Hash,
11+
hash::{BuildHasher, Hash},
1212
mem::ManuallyDrop,
1313
ops::{Deref, DerefMut},
1414
};
1515

1616
use bumpalo::Bump;
17-
use rustc_hash::FxBuildHasher;
1817

1918
// Re-export additional types from `hashbrown`
2019
pub use hashbrown::{
@@ -27,7 +26,7 @@ pub use hashbrown::{
2726

2827
use crate::Allocator;
2928

30-
type FxHashMap<'alloc, K, V> = hashbrown::HashMap<K, V, FxBuildHasher, &'alloc Bump>;
29+
type InternalHashMap<'alloc, K, V, H> = hashbrown::HashMap<K, V, H, &'alloc Bump>;
3130

3231
/// A hash map without `Drop`, that uses [`FxHasher`] to hash keys, and stores data in arena allocator.
3332
///
@@ -49,7 +48,26 @@ type FxHashMap<'alloc, K, V> = hashbrown::HashMap<K, V, FxBuildHasher, &'alloc B
4948
///
5049
/// [`FxHasher`]: rustc_hash::FxHasher
5150
#[derive(Debug)]
52-
pub struct HashMap<'alloc, K, V>(pub(crate) ManuallyDrop<FxHashMap<'alloc, K, V>>);
51+
pub struct HashMapImpl<'alloc, K, V, H: BuildHasher>(
52+
pub(crate) ManuallyDrop<InternalHashMap<'alloc, K, V, H>>,
53+
);
54+
55+
// Workaround for `FxBuildHasher` not implementing `Debug`.
56+
#[derive(Default, Debug)]
57+
#[expect(missing_docs)] // TODO
58+
pub struct FxBuildHasher;
59+
60+
impl BuildHasher for FxBuildHasher {
61+
type Hasher = rustc_hash::FxHasher;
62+
63+
#[inline(always)]
64+
fn build_hasher(&self) -> Self::Hasher {
65+
rustc_hash::FxHasher::default()
66+
}
67+
}
68+
69+
#[expect(missing_docs)] // TODO
70+
pub type HashMap<'alloc, K, V> = HashMapImpl<'alloc, K, V, FxBuildHasher>;
5371

5472
/// SAFETY: Even though `Bump` is not `Sync`, we can make `HashMap<K, V>` `Sync` if both `K` and `V`
5573
/// are `Sync` because:
@@ -85,12 +103,12 @@ pub struct HashMap<'alloc, K, V>(pub(crate) ManuallyDrop<FxHashMap<'alloc, K, V>
85103
///
86104
/// TODO: Fix these holes.
87105
/// TODO: Remove any other methods that currently allow performing allocations with only a `&self` reference.
88-
unsafe impl<K: Sync, V: Sync> Sync for HashMap<'_, K, V> {}
106+
unsafe impl<K: Sync, V: Sync, H: BuildHasher> Sync for HashMapImpl<'_, K, V, H> {}
89107

90108
// TODO: `IntoIter`, `Drain`, and other consuming iterators provided by `hashbrown` are `Drop`.
91109
// Wrap them in `ManuallyDrop` to prevent that.
92110

93-
impl<'alloc, K, V> HashMap<'alloc, K, V> {
111+
impl<'alloc, K, V, H: BuildHasher + Default> HashMapImpl<'alloc, K, V, H> {
94112
/// Const assertions that `K` and `V` are not `Drop`.
95113
/// Must be referenced in all methods which create a `HashMap`.
96114
const ASSERT_K_AND_V_ARE_NOT_DROP: () = {
@@ -112,7 +130,7 @@ impl<'alloc, K, V> HashMap<'alloc, K, V> {
112130
pub fn new_in(allocator: &'alloc Allocator) -> Self {
113131
const { Self::ASSERT_K_AND_V_ARE_NOT_DROP };
114132

115-
let inner = FxHashMap::with_hasher_in(FxBuildHasher, allocator.bump());
133+
let inner = InternalHashMap::with_hasher_in(H::default(), allocator.bump());
116134
Self(ManuallyDrop::new(inner))
117135
}
118136

@@ -125,7 +143,7 @@ impl<'alloc, K, V> HashMap<'alloc, K, V> {
125143
const { Self::ASSERT_K_AND_V_ARE_NOT_DROP };
126144

127145
let inner =
128-
FxHashMap::with_capacity_and_hasher_in(capacity, FxBuildHasher, allocator.bump());
146+
InternalHashMap::with_capacity_and_hasher_in(capacity, H::default(), allocator.bump());
129147
Self(ManuallyDrop::new(inner))
130148
}
131149

@@ -153,7 +171,8 @@ impl<'alloc, K, V> HashMap<'alloc, K, V> {
153171
// * Positive: Avoids potential large over-allocation for iterators where upper bound may be a large over-estimate
154172
// e.g. filter iterators.
155173
let capacity = iter.size_hint().0;
156-
let map = FxHashMap::with_capacity_and_hasher_in(capacity, FxBuildHasher, allocator.bump());
174+
let map =
175+
InternalHashMap::with_capacity_and_hasher_in(capacity, H::default(), allocator.bump());
157176
// Wrap in `ManuallyDrop` *before* calling `for_each`, so compiler doesn't insert unnecessary code
158177
// to drop the `FxHashMap` in case of a panic in iterator's `next` method
159178
let mut map = ManuallyDrop::new(map);
@@ -202,23 +221,23 @@ impl<'alloc, K, V> HashMap<'alloc, K, V> {
202221
}
203222

204223
// Provide access to all `hashbrown::HashMap`'s methods via deref
205-
impl<'alloc, K, V> Deref for HashMap<'alloc, K, V> {
206-
type Target = FxHashMap<'alloc, K, V>;
224+
impl<'alloc, K, V, H: BuildHasher> Deref for HashMapImpl<'alloc, K, V, H> {
225+
type Target = InternalHashMap<'alloc, K, V, H>;
207226

208227
#[inline]
209228
fn deref(&self) -> &Self::Target {
210229
&self.0
211230
}
212231
}
213232

214-
impl<'alloc, K, V> DerefMut for HashMap<'alloc, K, V> {
233+
impl<'alloc, K, V, H: BuildHasher> DerefMut for HashMapImpl<'alloc, K, V, H> {
215234
#[inline]
216-
fn deref_mut(&mut self) -> &mut FxHashMap<'alloc, K, V> {
235+
fn deref_mut(&mut self) -> &mut InternalHashMap<'alloc, K, V, H> {
217236
&mut self.0
218237
}
219238
}
220239

221-
impl<'alloc, K, V> IntoIterator for HashMap<'alloc, K, V> {
240+
impl<'alloc, K, V, H: BuildHasher> IntoIterator for HashMapImpl<'alloc, K, V, H> {
222241
type IntoIter = IntoIter<K, V, &'alloc Bump>;
223242
type Item = (K, V);
224243

@@ -235,8 +254,8 @@ impl<'alloc, K, V> IntoIterator for HashMap<'alloc, K, V> {
235254
}
236255
}
237256

238-
impl<'alloc, 'i, K, V> IntoIterator for &'i HashMap<'alloc, K, V> {
239-
type IntoIter = <&'i FxHashMap<'alloc, K, V> as IntoIterator>::IntoIter;
257+
impl<'alloc, 'i, K, V, H: BuildHasher> IntoIterator for &'i HashMapImpl<'alloc, K, V, H> {
258+
type IntoIter = <&'i InternalHashMap<'alloc, K, V, H> as IntoIterator>::IntoIter;
240259
type Item = (&'i K, &'i V);
241260

242261
/// Creates an iterator over the entries of a `HashMap` in arbitrary order.
@@ -250,8 +269,8 @@ impl<'alloc, 'i, K, V> IntoIterator for &'i HashMap<'alloc, K, V> {
250269
}
251270
}
252271

253-
impl<'alloc, 'i, K, V> IntoIterator for &'i mut HashMap<'alloc, K, V> {
254-
type IntoIter = <&'i mut FxHashMap<'alloc, K, V> as IntoIterator>::IntoIter;
272+
impl<'alloc, 'i, K, V, H: BuildHasher> IntoIterator for &'i mut HashMapImpl<'alloc, K, V, H> {
273+
type IntoIter = <&'i mut InternalHashMap<'alloc, K, V, H> as IntoIterator>::IntoIter;
255274
type Item = (&'i K, &'i mut V);
256275

257276
/// Creates an iterator over the entries of a `HashMap` in arbitrary order
@@ -266,21 +285,23 @@ impl<'alloc, 'i, K, V> IntoIterator for &'i mut HashMap<'alloc, K, V> {
266285
}
267286
}
268287

269-
impl<K, V> PartialEq for HashMap<'_, K, V>
288+
impl<K, V, H> PartialEq for HashMapImpl<'_, K, V, H>
270289
where
271290
K: Eq + Hash,
272291
V: PartialEq,
292+
H: BuildHasher,
273293
{
274294
#[inline(always)]
275295
fn eq(&self, other: &Self) -> bool {
276296
self.0.eq(&other.0)
277297
}
278298
}
279299

280-
impl<K, V> Eq for HashMap<'_, K, V>
300+
impl<K, V, H> Eq for HashMapImpl<'_, K, V, H>
281301
where
282302
K: Eq + Hash,
283303
V: Eq,
304+
H: BuildHasher,
284305
{
285306
}
286307

crates/oxc_allocator/src/hash_set.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ use std::{
1414
};
1515

1616
use bumpalo::Bump;
17-
use rustc_hash::FxBuildHasher;
1817

1918
// Re-export additional types from `hashbrown`
2019
pub use hashbrown::hash_set::{
2120
Difference, Drain, Entry, ExtractIf, Intersection, IntoIter, Iter, SymmetricDifference, Union,
2221
};
2322

24-
use crate::{Allocator, HashMap};
23+
use crate::{Allocator, HashMap, hash_map::FxBuildHasher};
2524

2625
type FxHashSet<'alloc, T> = hashbrown::HashSet<T, FxBuildHasher, &'alloc Bump>;
2726

crates/oxc_allocator/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub use bitset::BitSet;
6969
pub use boxed::Box;
7070
pub use clone_in::CloneIn;
7171
pub use convert::{FromIn, IntoIn};
72-
pub use hash_map::HashMap;
72+
pub use hash_map::{FxBuildHasher, HashMap, HashMapImpl};
7373
pub use hash_set::HashSet;
7474
#[cfg(feature = "pool")]
7575
pub use pool::*;

crates/oxc_ast/src/ast/js.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use std::cell::Cell;
2525
use oxc_allocator::{Box, CloneIn, Dummy, GetAddress, TakeIn, UnstableAddress, Vec};
2626
use oxc_ast_macros::ast;
2727
use oxc_estree::ESTree;
28-
use oxc_span::{Atom, ContentEq, GetSpan, GetSpanMut, SourceType, Span};
28+
use oxc_span::{Atom, ContentEq, GetSpan, GetSpanMut, Ident, SourceType, Span};
2929
use oxc_syntax::{
3030
operator::{
3131
AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator, UpdateOperator,
@@ -234,7 +234,7 @@ pub use match_expression;
234234
pub struct IdentifierName<'a> {
235235
pub span: Span,
236236
#[estree(json_safe)]
237-
pub name: Atom<'a>,
237+
pub name: Ident<'a>,
238238
}
239239

240240
/// `x` inside `func` in `const x = 0; function func() { console.log(x); }`
@@ -253,8 +253,9 @@ pub struct IdentifierName<'a> {
253253
pub struct IdentifierReference<'a> {
254254
pub span: Span,
255255
/// The name of the identifier being referenced.
256+
// pub name: Atom<'a>,
256257
#[estree(json_safe)]
257-
pub name: Atom<'a>,
258+
pub name: Ident<'a>,
258259
/// Reference ID
259260
///
260261
/// Identifies what identifier this refers to, and how it is used. This is
@@ -283,7 +284,7 @@ pub struct BindingIdentifier<'a> {
283284
pub span: Span,
284285
/// The identifier name being bound.
285286
#[estree(json_safe)]
286-
pub name: Atom<'a>,
287+
pub name: Ident<'a>,
287288
/// Unique identifier for this binding.
288289
///
289290
/// This gets initialized during [`semantic analysis`] in the bind step. If
@@ -309,7 +310,7 @@ pub struct BindingIdentifier<'a> {
309310
pub struct LabelIdentifier<'a> {
310311
pub span: Span,
311312
#[estree(json_safe)]
312-
pub name: Atom<'a>,
313+
pub name: Ident<'a>,
313314
}
314315

315316
/// `this` in `return this.prop;`
@@ -2285,7 +2286,7 @@ pub enum MethodDefinitionKind {
22852286
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree, UnstableAddress)]
22862287
pub struct PrivateIdentifier<'a> {
22872288
pub span: Span,
2288-
pub name: Atom<'a>,
2289+
pub name: Ident<'a>,
22892290
}
22902291

22912292
/// Class Static Block

0 commit comments

Comments
 (0)