Use #[expect(lint)] over #[allow(lint)] where possible (#17822)

This commit is contained in:
Micha Reiser 2025-05-03 21:20:31 +02:00 committed by GitHub
parent 8535af8516
commit fa628018b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
148 changed files with 221 additions and 268 deletions

View file

@ -178,7 +178,6 @@ impl<'fmt, 'ast, 'buf> JoinCommaSeparatedBuilder<'fmt, 'ast, 'buf> {
self
}
#[allow(unused)]
pub(crate) fn entries<T, I, F>(&mut self, entries: I) -> &mut Self
where
T: Ranged,

View file

@ -24,7 +24,7 @@ pub enum Emit {
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
#[allow(clippy::struct_excessive_bools)] // It's only the dev cli anyways
#[expect(clippy::struct_excessive_bools)] // It's only the dev cli anyways
pub struct Cli {
/// Python files to format. If there are none, stdin will be used. `-` as stdin is not supported
pub files: Vec<PathBuf>,

View file

@ -244,7 +244,6 @@ impl<K: std::hash::Hash + Eq, V> MultiMap<K, V> {
}
/// Returns `true` if `key` has any *leading*, *dangling*, or *trailing* parts.
#[allow(unused)]
pub(super) fn has(&self, key: &K) -> bool {
self.index.contains_key(key)
}
@ -542,7 +541,7 @@ impl PartIndex {
// OK because:
// * The `value < u32::MAX` guarantees that the add doesn't overflow.
// * The `+ 1` guarantees that the index is not zero
#[allow(clippy::cast_possible_truncation)]
#[expect(clippy::cast_possible_truncation)]
Self(std::num::NonZeroU32::new((value as u32) + 1).expect("valid value"))
}

View file

@ -106,7 +106,6 @@ impl<'a> PyFormatContext<'a> {
}
/// Returns `true` if preview mode is enabled.
#[allow(unused)]
pub(crate) const fn is_preview(&self) -> bool {
self.options.preview().is_enabled()
}

View file

@ -571,7 +571,7 @@ impl<'a> FlatBinaryExpressionSlice<'a> {
"Operand slice must contain at least one operand"
);
#[allow(unsafe_code)]
#[expect(unsafe_code)]
unsafe {
// SAFETY: `BinaryChainSlice` has the same layout as a slice because it uses `repr(transparent)`
&*(std::ptr::from_ref::<[OperandOrOperator<'a>]>(slice)

View file

@ -523,7 +523,6 @@ impl<'ast> IntoFormat<PyFormatContext<'ast>> for Expr {
/// * The expression contains at least one parenthesized sub expression (optimization to avoid unnecessary work)
///
/// This mimics Black's [`_maybe_split_omitting_optional_parens`](https://github.com/psf/black/blob/d1248ca9beaf0ba526d265f4108836d89cf551b7/src/black/linegen.py#L746-L820)
#[allow(clippy::if_same_then_else)]
pub(crate) fn can_omit_optional_parentheses(expr: &Expr, context: &PyFormatContext) -> bool {
let mut visitor = CanOmitOptionalParenthesesVisitor::new(context);
visitor.visit_subexpression(expr);
@ -679,7 +678,7 @@ impl<'input> CanOmitOptionalParenthesesVisitor<'input> {
// It's impossible for a file smaller or equal to 4GB to contain more than 2^32 comparisons
// because each comparison requires a left operand, and `n` `operands` and right sides.
#[allow(clippy::cast_possible_truncation)]
#[expect(clippy::cast_possible_truncation)]
Expr::BoolOp(ast::ExprBoolOp {
range: _,
op: _,
@ -702,7 +701,7 @@ impl<'input> CanOmitOptionalParenthesesVisitor<'input> {
// It's impossible for a file smaller or equal to 4GB to contain more than 2^32 comparisons
// because each comparison requires a left operand, and `n` `operands` and right sides.
#[allow(clippy::cast_possible_truncation)]
#[expect(clippy::cast_possible_truncation)]
Expr::Compare(ast::ExprCompare {
range: _,
left: _,

View file

@ -14,7 +14,6 @@ pub(crate) fn read_from_stdin() -> Result<String> {
Ok(buffer)
}
#[allow(clippy::print_stdout)]
fn main() -> Result<()> {
let cli: Cli = Cli::parse();

View file

@ -1,7 +1,5 @@
#[allow(unused_imports)]
pub(crate) use crate::{
builders::PyFormatterExtensions, AsFormat, FormatNodeRule, FormattedIterExt as _, IntoFormat,
PyFormatContext, PyFormatter,
};
#[allow(unused_imports)]
pub(crate) use ruff_formatter::prelude::*;

View file

@ -546,7 +546,7 @@ impl NarrowRange<'_> {
Some(SavedLevel { level: saved_level })
}
#[allow(clippy::needless_pass_by_value)]
#[expect(clippy::needless_pass_by_value)]
fn leave_level(&mut self, saved_state: SavedLevel) {
self.level = saved_state.level;
}

View file

@ -170,7 +170,6 @@ impl FormatRule<Suite, PyFormatContext<'_>> for FormatSuite {
} else {
first.fmt(f)?;
#[allow(clippy::if_same_then_else)]
let empty_line_after_docstring = if matches!(first, SuiteChildStatement::Docstring(_))
&& self.kind == SuiteKind::Class
{

View file

@ -691,7 +691,6 @@ pub(crate) fn normalize_string(
}
if !new_flags.is_triple_quoted() {
#[allow(clippy::if_same_then_else)]
if next == opposite_quote {
// Remove the escape by ending before the backslash and starting again with the quote
chars.next();

View file

@ -487,7 +487,7 @@ enum SuppressionComments<'a> {
/// Comments that all fall into the formatted range.
Formatted {
#[allow(unused)]
#[expect(unused)]
comments: &'a [SourceComment],
},
}