Skip to content

Commit

Permalink
style nitpicks
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Aug 19, 2024
1 parent 401ba8e commit 9a8fd54
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use crate::checkers::ast::Checker;
/// Checks for `Decimal` calls passing a float literal.
///
/// ## Why is this bad?
/// Float literals have limited precision that can lead to unexpected results. The `Decimal` class is designed to handle
/// numbers with fixed-point precision, so a string literal should be used instead.
/// Float literals have limited precision that can lead to unexpected results.
/// The `Decimal` class is designed to handle numbers with fixed-point precision,
/// so a string literal should be used instead.
///
/// ## Example
///
Expand All @@ -25,20 +26,20 @@ use crate::checkers::ast::Checker;
/// ```
///
/// ## Fix Safety
/// This rule's fix is marked as unsafe because it changes the underlying value of the `Decimal` instance that is
/// constructed. This can lead to unexpected behavior if your program relies on the previous value
/// (whether deliberately or not).
/// This rule's fix is marked as unsafe because it changes the underlying value
/// of the `Decimal` instance that is constructed. This can lead to unexpected
/// behavior if your program relies on the previous value (whether deliberately or not).
#[violation]
pub struct DecimalFromFloatLiteral;

impl AlwaysFixableViolation for DecimalFromFloatLiteral {
#[derive_message_formats]
fn message(&self) -> String {
format!(r#"`Decimal()` called with float literal argument"#)
format!("`Decimal()` called with float literal argument")
}

fn fix_title(&self) -> String {
"Use a string literal instead".into()
"Use a string literal instead".to_string()
}
}

Expand Down Expand Up @@ -73,9 +74,7 @@ fn is_arg_float_literal(arg: &ast::Expr) -> bool {
value: ast::Number::Float(_),
..
}) => true,
ast::Expr::UnaryOp(ast::ExprUnaryOp { operand, .. }) => {
is_arg_float_literal(operand.as_ref())
}
ast::Expr::UnaryOp(ast::ExprUnaryOp { operand, .. }) => is_arg_float_literal(operand),
_ => false,
}
}
Expand Down

0 comments on commit 9a8fd54

Please sign in to comment.