Skip to content

Commit

Permalink
style(all): replace #[allow] with #[expect] (#8930)
Browse files Browse the repository at this point in the history
Replace `#[allow]` with `#[expect]` through the whole codebase.

This also surfaced many places where the `#[allow]` attributes were outdated/pointless and could be removed entirely.

Only places `#[allow]` remains are:

1. In generated code and macros, where lint errors may or may not be triggered depending on the generated code.
2. A few places where clippy malfunctions. These use e.g. `#[allow(unused, clippy::allow_attributes)]`.
  • Loading branch information
overlookmotel committed Feb 7, 2025
1 parent 4a86467 commit a4a8e7d
Show file tree
Hide file tree
Showing 212 changed files with 282 additions and 346 deletions.
5 changes: 2 additions & 3 deletions apps/oxlint/src/command/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pub struct OutputOptions {
}

/// Enable Plugins
#[allow(clippy::struct_field_names)]
#[expect(clippy::struct_field_names)]
#[derive(Debug, Default, Clone, Bpaf)]
pub struct EnablePlugins {
/// Disable react plugin, which is turned on by default
Expand Down Expand Up @@ -270,7 +270,6 @@ pub struct EnablePlugins {
/// changing default behavior if they're not explicitly passed by the user. This scheme is a bit
/// convoluted, but needed due to architectural constraints imposed by `bpaf`.
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
#[allow(clippy::enum_variant_names)]
pub enum OverrideToggle {
/// Override the option to enabled
Enable,
Expand Down Expand Up @@ -439,7 +438,7 @@ mod lint_options {
}

#[test]
#[allow(clippy::similar_names)]
#[expect(clippy::similar_names)]
fn multiple_paths() {
let temp_dir = tempfile::tempdir().expect("Could not create a temp dir");
let file_foo = temp_dir.path().join("foo.js");
Expand Down
2 changes: 1 addition & 1 deletion apps/oxlint/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct MiscOptions {
pub print_config: bool,
}

#[allow(clippy::ptr_arg)]
#[expect(clippy::ptr_arg)]
fn validate_paths(paths: &Vec<PathBuf>) -> bool {
if paths.is_empty() {
true
Expand Down
1 change: 0 additions & 1 deletion apps/oxlint/src/output_formatter/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ impl DiagnosticReporter for JsonReporter {
}

/// <https://github.com/fregante/eslint-formatters/tree/ae1fd9748596447d1fd09625c33d9e7ba9a3d06d/packages/eslint-formatter-json>
#[allow(clippy::print_stdout)]
fn format_json(diagnostics: &mut Vec<Error>) -> String {
let handler = JSONReportHandler::new();
let messages = diagnostics
Expand Down
1 change: 0 additions & 1 deletion apps/oxlint/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub enum CliRunResult {
}

impl Termination for CliRunResult {
#[allow(clippy::print_stdout, clippy::print_stderr)]
fn report(self) -> ExitCode {
match self {
Self::None
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc/examples/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::print_stdout)]
#![expect(clippy::print_stdout)]

use std::{env, io, path::Path};

Expand Down
1 change: 0 additions & 1 deletion crates/oxc/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ pub trait CompilerInterface {
self.after_isolated_declarations(ret);
}

#[allow(clippy::too_many_arguments)]
fn transform<'a>(
&self,
options: &TransformOptions,
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_allocator/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<T> Box<'_, T> {
/// # SAFETY
/// Safe to create, but must never be dereferenced, as does not point to a valid `T`.
/// Only purpose is for mocking types without allocating for const assertions.
#[allow(unsafe_code, clippy::missing_safety_doc)]
#[expect(unsafe_code, clippy::missing_safety_doc)]
pub const unsafe fn dangling() -> Self {
const { Self::ASSERT_T_IS_NOT_DROP };

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_allocator/src/convert.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::inline_always)]
#![expect(clippy::inline_always)]

use crate::{Allocator, Box};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(missing_docs)] // FIXME
#![expect(missing_docs)] // FIXME

// NB: `#[span]`, `#[scope(...)]`,`#[visit(...)]` and `#[generate_derive(...)]` do NOT do anything to the code.
// They are purely markers for codegen used in `tasks/ast_tools` and `crates/oxc_traverse/scripts`. See docs in those crates.
Expand Down
4 changes: 1 addition & 3 deletions crates/oxc_ast/src/ast/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,6 @@ macro_rules! shared_enum_variants {
#[inline]
pub fn $as_child(&self) -> Option<&$child<'a>> {
if self.$is_child() {
#[allow(unsafe_code)]
// SAFETY: Transmute is safe because discriminants + types are identical between
// `$parent` and `$child` for $child variants
Some(unsafe { &*std::ptr::from_ref(self).cast::<$child>() })
Expand All @@ -904,7 +903,6 @@ macro_rules! shared_enum_variants {
#[inline]
pub fn $as_child_mut(&mut self) -> Option<&mut $child<'a>> {
if self.$is_child() {
#[allow(unsafe_code)]
// SAFETY: Transmute is safe because discriminants + types are identical between
// `$parent` and `$child` for $child variants
Some(unsafe { &mut *std::ptr::from_mut(self).cast::<$child>() })
Expand Down Expand Up @@ -966,7 +964,7 @@ pub(crate) use shared_enum_variants;
/// <https://doc.rust-lang.org/std/mem/fn.discriminant.html>
macro_rules! discriminant {
($ty:ident :: $variant:ident) => {{
#[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
#[expect(clippy::undocumented_unsafe_blocks)]
unsafe {
let t = std::mem::ManuallyDrop::new($ty::$variant(oxc_allocator::Box::dangling()));
*(std::ptr::addr_of!(t).cast::<u8>())
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/ast/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! - [AST Spec](https://github.com/typescript-eslint/typescript-eslint/tree/v8.9.0/packages/ast-spec)
//! - [Archived TypeScript spec](https://github.com/microsoft/TypeScript/blob/3c99d50da5a579d9fa92d02664b1b66d4ff55944/doc/spec-ARCHIVED.md)
#![allow(missing_docs)] // FIXME
#![expect(missing_docs)] // FIXME

// NB: `#[span]`, `#[scope(...)]`,`#[visit(...)]` and `#[generate_derive(...)]` do NOT do anything to the code.
// They are purely markers for codegen used in `tasks/ast_tools` and `crates/oxc_traverse/scripts`. See docs in those crates.
Expand Down
9 changes: 1 addition & 8 deletions crates/oxc_ast/src/ast_builder_impl.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
#![allow(
clippy::fn_params_excessive_bools,
clippy::must_use_candidate, // must_use_candidate is too annoying for this file
clippy::too_many_arguments,
clippy::unused_self,
)]
#![warn(missing_docs)]

use std::{borrow::Cow, mem};
Expand All @@ -16,7 +10,6 @@ use crate::{ast::*, AstBuilder};

/// Type that can be used in any AST builder method call which requires an `IntoIn<'a, Anything<'a>>`.
/// Pass `NONE` instead of `None::<Anything<'a>>`.
#[allow(clippy::upper_case_acronyms)]
pub struct NONE;

impl<'a, T> FromIn<'a, NONE> for Option<Box<'a, T>> {
Expand Down Expand Up @@ -105,7 +98,7 @@ impl<'a> AstBuilder<'a> {
/// This method is completely unsound and should not be used.
/// We need to remove all uses of it. Please don't add any more!
/// <https://github.com/oxc-project/oxc/issues/3483>
#[allow(clippy::missing_safety_doc)]
#[expect(clippy::missing_safety_doc)]
#[inline]
pub unsafe fn copy<T>(self, src: &T) -> T {
// SAFETY: Not safe (see above)
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/ast_impl/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<'a> JSXElementName<'a> {
}
}

#[allow(missing_docs)]
#[expect(missing_docs)]
pub fn get_identifier_name(&self) -> Option<Atom<'a>> {
match self {
Self::Identifier(id) => Some(id.as_ref().name),
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/ast_impl/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl NumericLiteral<'_> {
/// port from [closure compiler](https://github.com/google/closure-compiler/blob/a4c880032fba961f7a6c06ef99daa3641810bfdd/src/com/google/javascript/jscomp/base/JSCompDoubles.java#L113)
///
/// <https://262.ecma-international.org/5.1/#sec-9.5>
#[allow(clippy::cast_possible_truncation)] // for `as i32`
#[expect(clippy::cast_possible_truncation)] // for `as i32`
pub fn ecmascript_to_int32(num: f64) -> i32 {
// Fast path for most common case. Also covers -0.0
let int32_value = num as i32;
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_ast/src/ast_kind_impl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(missing_docs)] // FIXME
#![expect(missing_docs)] // FIXME
use oxc_span::Atom;
use oxc_syntax::scope::ScopeId;

Expand Down Expand Up @@ -172,7 +172,6 @@ impl<'a> AstKind<'a> {
}

impl AstKind<'_> {
#[allow(clippy::match_same_arms)]
/// Get the AST kind name with minimal details. Particularly useful for
/// when debugging an iteration over an AST.
///
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

//! AST node factories
#![allow(
#![expect(
clippy::default_trait_access,
clippy::too_many_arguments,
clippy::fn_params_excessive_bools
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/generated/ast_kind.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Auto-generated code, DO NOT EDIT DIRECTLY!
// To edit this generated file you have to edit `tasks/ast_tools/src/generators/ast_kind.rs`

#![allow(missing_docs)]
#![expect(missing_docs)]
// FIXME (in ast_tools/src/generators/ast_kind.rs)

use std::ptr;
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/generated/derive_get_address.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Auto-generated code, DO NOT EDIT DIRECTLY!
// To edit this generated file you have to edit `tasks/ast_tools/src/derives/get_address.rs`

#![allow(clippy::match_same_arms)]
#![expect(clippy::match_same_arms)]

use oxc_allocator::{Address, GetAddress};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/generated/derive_get_span.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Auto-generated code, DO NOT EDIT DIRECTLY!
// To edit this generated file you have to edit `tasks/ast_tools/src/derives/get_span.rs`

#![allow(clippy::match_same_arms)]
#![expect(clippy::match_same_arms)]

use oxc_span::{GetSpan, Span};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/generated/derive_get_span_mut.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Auto-generated code, DO NOT EDIT DIRECTLY!
// To edit this generated file you have to edit `tasks/ast_tools/src/derives/get_span.rs`

#![allow(clippy::match_same_arms)]
#![expect(clippy::match_same_arms)]

use oxc_span::{GetSpanMut, Span};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/generated/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! * [visitor pattern](https://rust-unofficial.github.io/patterns/patterns/behavioural/visitor.html)
//! * [rustc visitor](https://github.com/rust-lang/rust/blob/1.82.0/compiler/rustc_ast/src/visit.rs)
#![allow(unused_variables, clippy::semicolon_if_nothing_returned)]
#![expect(unused_variables, clippy::semicolon_if_nothing_returned)]

use std::cell::Cell;

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/generated/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! * [visitor pattern](https://rust-unofficial.github.io/patterns/patterns/behavioural/visitor.html)
//! * [rustc visitor](https://github.com/rust-lang/rust/blob/1.82.0/compiler/rustc_ast/src/visit.rs)
#![allow(unused_variables, clippy::semicolon_if_nothing_returned)]
#![expect(unused_variables, clippy::semicolon_if_nothing_returned)]

use std::cell::Cell;

Expand Down
7 changes: 2 additions & 5 deletions crates/oxc_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
//! [tsc]: <https://github.com/microsoft/TypeScript>
//! [`Traverse`]: <https://github.com/oxc-project/oxc/tree/main/crates/oxc_traverse>
// TODO: I'm not sure if it is a but or intentional but clippy needs this allowed both on this
// module and the generated one.
#![allow(clippy::self_named_module_files)]
#![warn(missing_docs)]

#[cfg(feature = "serialize")]
Expand All @@ -57,7 +54,7 @@ mod trivia;
pub mod utf8_to_utf16;

mod generated {
#![allow(missing_docs)]
#![expect(missing_docs)]
#[cfg(debug_assertions)]
pub mod assert_layouts;
pub mod ast_builder;
Expand All @@ -75,7 +72,7 @@ mod generated {
}

pub mod visit {
#![allow(missing_docs)]
#![expect(missing_docs)]
pub use crate::generated::{visit::*, visit_mut::*};
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/trivia.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Trivias such as comments and irregular whitespaces
#![allow(missing_docs)] // FIXME
#![expect(missing_docs)] // FIXME

use std::{
iter::FusedIterator,
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/utf8_to_utf16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Utf8ToUtf16 {
}
}

#[allow(clippy::cast_possible_truncation)]
#[expect(clippy::cast_possible_truncation)]
fn build_table(&mut self, source_text: &str) {
// Translation from UTF-8 byte offset to UTF-16 char offset:
//
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_cfg/src/builder/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<'a> Ctx<'a> {
}

pub trait CtxCursor {
#![allow(clippy::return_self_not_must_use)]
#![expect(clippy::return_self_not_must_use)]
/// Marks the break jump position in the current context.
fn mark_break(self, jmp_pos: BlockNodeId) -> Self;
/// Marks the continue jump position in the current context.
Expand Down Expand Up @@ -87,9 +87,9 @@ impl CtxCursor for QueryCtx<'_, '_> {
impl<'a, 'c> QueryCtx<'a, 'c> {
/// Creates a new `Ctx` with the given `CtxFlags` and returns a `RefCtxCursor` to it.
#[inline]
#[allow(clippy::wrong_self_convention, clippy::new_ret_no_self)]
#[expect(clippy::wrong_self_convention, clippy::new_ret_no_self)]
pub fn new(self, flags: CtxFlags) -> RefCtxCursor<'a, 'c> {
#![allow(unsafe_code)]
#![expect(unsafe_code)]
self.0.ctx_stack.push(Ctx::new(self.1, flags));
// SAFETY: we just pushed this `Ctx` into the stack.
let ctx = unsafe { self.0.ctx_stack.last_mut().unwrap_unchecked() };
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_cfg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub type BlockNodeId = petgraph::stable_graph::NodeIndex;
pub struct BasicBlockId(NonMaxU32);

impl Idx for BasicBlockId {
#[allow(clippy::cast_possible_truncation)]
#[expect(clippy::cast_possible_truncation)]
fn from_usize(idx: usize) -> Self {
assert!(idx < u32::MAX as usize);
// SAFETY: We just checked `idx` is valid for `NonMaxU32`
Expand Down
19 changes: 10 additions & 9 deletions crates/oxc_cfg/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,16 @@ macro_rules! try_control {
};
($e:expr, $p:stmt, $q:stmt) => {
match $e {
x =>
{
#[allow(clippy::redundant_else)]
if x.should_break() {
return x;
} else if x.should_prune() {
$p
} else {
$q
x => {
#[allow(clippy::redundant_else, clippy::allow_attributes)]
{
if x.should_break() {
return x;
} else if x.should_prune() {
$p
} else {
$q
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_codegen/examples/codegen.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::print_stdout)]
#![expect(clippy::print_stdout)]
use std::path::Path;

use oxc_allocator::Allocator;
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_codegen/examples/sourcemap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::print_stdout)]
#![expect(clippy::print_stdout)]
use std::{env, path::Path};

use base64::{prelude::BASE64_STANDARD, Engine};
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_codegen/src/code_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ mod test {
}

#[test]
#[allow(clippy::byte_char_slices)]
#[expect(clippy::byte_char_slices)]
fn print_ascii_byte() {
let mut code = CodeBuffer::new();
code.print_ascii_byte(b'f');
Expand All @@ -519,7 +519,7 @@ mod test {
}

#[test]
#[allow(clippy::byte_char_slices)]
#[expect(clippy::byte_char_slices)]
fn print_byte_unchecked() {
let mut code = CodeBuffer::new();
// SAFETY: These bytes are all ASCII
Expand All @@ -535,7 +535,7 @@ mod test {
}

#[test]
#[allow(clippy::byte_char_slices)]
#[expect(clippy::byte_char_slices)]
fn print_ascii_bytes() {
let mut code = CodeBuffer::new();
code.print_ascii_bytes([b'f', b'o', b'o']);
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_codegen/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(missing_docs)] // FIXME
#![expect(missing_docs)] // FIXME
use bitflags::bitflags;

bitflags! {
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ impl<'a> Codegen<'a> {

// `get_minified_number` from terser
// https://github.com/terser/terser/blob/c5315c3fd6321d6b2e076af35a70ef532f498505/lib/output.js#L2418
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss, clippy::cast_possible_wrap)]
#[expect(clippy::cast_possible_truncation, clippy::cast_sign_loss, clippy::cast_possible_wrap)]
fn get_minified_number(num: f64, buffer: &mut ryu_js::Buffer) -> Cow<'_, str> {
use cow_utils::CowUtils;

Expand Down
Loading

0 comments on commit a4a8e7d

Please sign in to comment.