Skip to content

Commit

Permalink
chore(dev): enable even more clippy/lint checks (#1256)
Browse files Browse the repository at this point in the history
* chore(dev): enable even more clippy/lint checks

* more fixes

* more fixes

* more fixes
  • Loading branch information
pront authored Feb 3, 2025
1 parent c98f2ee commit 9225461
Show file tree
Hide file tree
Showing 20 changed files with 108 additions and 159 deletions.
2 changes: 0 additions & 2 deletions benches/stdlib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(deprecated)]

use chrono::{DateTime, Datelike, TimeZone, Utc};
use criterion::{criterion_group, criterion_main, Criterion};
use regex::Regex;
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn run(opts: &Opts, stdlib_functions: Vec<Box<dyn Function>>) -> Result<(), Erro
#[allow(clippy::print_stderr)]
if opts.print_warnings {
let warnings = Formatter::new(&source, warnings).colored().to_string();
eprintln!("{warnings}")
eprintln!("{warnings}");
}

for mut object in objects {
Expand Down
15 changes: 1 addition & 14 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
#![deny(
warnings,
clippy::all,
clippy::pedantic,
unreachable_pub,
unused_allocation,
unused_extern_crates,
unused_assignments,
unused_comparisons
)]
#![allow(
clippy::semicolon_if_nothing_returned, // allowed in initial deny commit
)]

#![deny(warnings, clippy::pedantic)]
pub mod cmd;
mod repl;

Expand Down
2 changes: 1 addition & 1 deletion src/cli/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub(crate) fn run(
Ok(line) if line == "exit" || line == "quit" => break,
Ok("help") => print_help_text(),
Ok(line) if line == "help functions" || line == "help funcs" || line == "help fs" => {
print_function_list()
print_function_list();
}
Ok("help docs") => open_url(DOCS_URL),
// Capture "help error <code>"
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ impl<'a> Compiler<'a> {
.compile_expr(*expr, state)
.map(|expr| Box::new(Node::new(span, expr)))
.or_else(|| {
self.skip_missing_assignment_target(target.clone().into_inner());
self.skip_missing_assignment_target(&target.clone().into_inner());
None
})?;

Expand All @@ -513,8 +513,8 @@ impl<'a> Compiler<'a> {
.compile_expr(*expr, state)
.map(|expr| Box::new(Node::new(span, expr)))
.or_else(|| {
self.skip_missing_assignment_target(ok.clone().into_inner());
self.skip_missing_assignment_target(err.clone().into_inner());
self.skip_missing_assignment_target(&ok.clone().into_inner());
self.skip_missing_assignment_target(&err.clone().into_inner());
None
})?;

Expand Down Expand Up @@ -837,7 +837,7 @@ impl<'a> Compiler<'a> {
self.diagnostics.push(Box::new(error));
}

fn skip_missing_assignment_target(&mut self, target: ast::AssignmentTarget) {
fn skip_missing_assignment_target(&mut self, target: &ast::AssignmentTarget) {
let query = match &target {
ast::AssignmentTarget::Noop => return,
ast::AssignmentTarget::Query(ast::Query { target, path }) => {
Expand Down
12 changes: 6 additions & 6 deletions src/compiler/conversion/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn parse_bool_errors() {
assert!(parse_bool("123.4").is_err());
}

fn convert_float(input: impl ToString) -> Result<StubValue, Error> {
fn convert_float(input: &str) -> Result<StubValue, Error> {
let input = input.to_string();
let converter = Conversion::parse("float", TimeZone::Local).expect("float conversion");
converter.convert::<StubValue>(input.into())
Expand All @@ -103,12 +103,12 @@ fn convert_float(input: impl ToString) -> Result<StubValue, Error> {
fn convert_float_ok() {
let max_float = format!("17976931348623157{}", "0".repeat(292));
let min_float = format!("-{max_float}");
assert_eq!(convert_float(max_float), Ok(StubValue::Float(f64::MAX)));
assert_eq!(convert_float(&max_float), Ok(StubValue::Float(f64::MAX)));
assert_eq!(convert_float("1"), Ok(StubValue::Float(1.0)));
assert_eq!(convert_float("1.23"), Ok(StubValue::Float(1.23)));
assert_eq!(convert_float("-1"), Ok(StubValue::Float(-1.0)));
assert_eq!(convert_float("-1.23"), Ok(StubValue::Float(-1.23)));
assert_eq!(convert_float(min_float), Ok(StubValue::Float(f64::MIN)));
assert_eq!(convert_float(&min_float), Ok(StubValue::Float(f64::MIN)));

assert_eq!(convert_float("0"), Ok(StubValue::Float(0.0)));
assert_eq!(convert_float("+0"), Ok(StubValue::Float(0.0)));
Expand All @@ -118,17 +118,17 @@ fn convert_float_ok() {
let exceeds_max_float = format!("17976931348623159{}", "0".repeat(292));
let exceeds_min_float = format!("-{exceeds_max_float}");
assert_eq!(
convert_float(exceeds_max_float),
convert_float(&exceeds_max_float),
Ok(StubValue::Float(f64::INFINITY))
);
assert_eq!(
convert_float(exceeds_min_float),
convert_float(&exceeds_min_float),
Ok(StubValue::Float(f64::NEG_INFINITY))
);

let subnormal_lower_than_min = 1.0e-308_f64;
assert_eq!(
convert_float(subnormal_lower_than_min),
convert_float(&subnormal_lower_than_min.to_string()),
Ok(StubValue::Float(1.0e-308_f64))
);
}
Expand Down
13 changes: 6 additions & 7 deletions src/compiler/expression/assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct Assignment {
}

impl Assignment {
#[allow(unused_variables)]
#[allow(clippy::too_many_lines)]
pub(crate) fn new(
node: Node<Variant<Node<ast::AssignmentTarget>, Node<Expr>>>,
state: &TypeState,
Expand Down Expand Up @@ -395,9 +395,8 @@ impl Target {
Internal(ident, path) => {
// Get the provided path, or else insert into the variable
// without any path appended and return early.
let path = match path.is_root() {
false => path,
true => return ctx.state_mut().insert_variable(ident.clone(), value),
if path.is_root() {
return ctx.state_mut().insert_variable(ident.clone(), value);
};

// Update existing variable using the provided path, or create a
Expand Down Expand Up @@ -703,7 +702,9 @@ impl DiagnosticMessage for Error {
Label::primary("this expression is fallible because at least one argument's type cannot be verified to be valid", self.expr_span)];
if let Some(context) = context {
let helper = "update the expression to be infallible by adding a `!`";
if !context.arguments_fmt.is_empty() {
if context.arguments_fmt.is_empty() {
labels.push(Label::primary(helper, self.expr_span));
} else {
labels.push(
Label::primary(format!(
"`{}` argument type is `{}` and this function expected a parameter `{}` of type `{}`",
Expand All @@ -721,8 +722,6 @@ impl DiagnosticMessage for Error {
format!("{helper}: `{fixed_expression}`"),
self.expr_span,
));
} else {
labels.push(Label::primary(helper, self.expr_span));
}
};

Expand Down
11 changes: 7 additions & 4 deletions src/compiler/expression/function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl<'a> Builder<'a> {
&self.list
}

#[allow(clippy::too_many_lines)]
#[allow(clippy::too_many_arguments)]
pub(crate) fn new(
call_span: Span,
Expand Down Expand Up @@ -197,6 +198,7 @@ impl<'a> Builder<'a> {
})
}

#[allow(clippy::too_many_lines)]
fn check_closure(
function: &dyn Function,
closure_variables: Option<Node<Vec<Node<Ident>>>>,
Expand Down Expand Up @@ -355,15 +357,15 @@ impl<'a> Builder<'a> {
VariableKind::TargetInnerKey => {
let mut kind = Kind::never();

if !type_def.is_collection() {
kind = Kind::any()
} else {
if type_def.is_collection() {
if type_def.is_object() {
kind.add_bytes();
}
if type_def.is_array() {
kind.add_integer();
}
} else {
kind = Kind::any();
}

(kind.into(), None)
Expand Down Expand Up @@ -966,6 +968,7 @@ impl DiagnosticMessage for FunctionCallError {
}
}

#[allow(clippy::too_many_lines)]
fn labels(&self) -> Vec<Label> {
use FunctionCallError::{
ClosureArityMismatch, ClosureParameterTypeMismatch, Compilation, FallibleArgument,
Expand Down Expand Up @@ -1199,7 +1202,7 @@ impl DiagnosticMessage for FunctionCallError {
notes.append(&mut Note::solution(
"coercing to an appropriate type and specifying a default value as a fallback in case coercion fails",
vec![format!("{argument} = {coerce}"), call],
))
));
}

notes.push(Note::SeeErrorDocs);
Expand Down
10 changes: 5 additions & 5 deletions src/compiler/expression/if_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ impl Expression for IfStatement {
fn resolve(&self, ctx: &mut Context) -> Resolved {
let predicate = self.predicate.resolve(ctx)?.try_boolean()?;

match predicate {
true => self.if_block.resolve(ctx),
false => self
.else_block
if predicate {
self.if_block.resolve(ctx)
} else {
self.else_block
.as_ref()
.map_or(Ok(Value::Null), |block| block.resolve(ctx)),
.map_or(Ok(Value::Null), |block| block.resolve(ctx))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/expression/levenstein.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub(crate) fn distance(word1: &[char], word2: &[char]) -> usize {
&& word1[col - 2] == word2[row - 1]
{
matrix[pos(col, row)] =
min(matrix[pos(col, row)], matrix[pos(col - 2, row - 2)] + 1)
min(matrix[pos(col, row)], matrix[pos(col - 2, row - 2)] + 1);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/expression/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ impl Expression for Op {
.map_err(Into::into)
}

#[allow(clippy::too_many_lines)]
fn type_info(&self, state: &TypeState) -> TypeInfo {
use crate::value::Kind as K;
use ast::Opcode::{Add, And, Div, Eq, Err, Ge, Gt, Le, Lt, Merge, Mul, Ne, Or, Sub};
Expand Down Expand Up @@ -432,6 +433,7 @@ mod tests {

use super::*;

#[allow(clippy::needless_pass_by_value)]
fn op(
opcode: ast::Opcode,
lhs: impl TryInto<Literal> + fmt::Debug + Clone,
Expand Down
8 changes: 2 additions & 6 deletions src/compiler/expression_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ impl From<ExpressionError> for Diagnostic {
impl DiagnosticMessage for ExpressionError {
fn code(&self) -> usize {
match self {
Abort { .. } => 0,
Return { .. } => 0,
Error { .. } => 0,
Abort { .. } | Return { .. } | Error { .. } => 0,
Fallible { .. } => 100,
Missing { .. } => 900,
}
Expand Down Expand Up @@ -99,11 +97,9 @@ impl DiagnosticMessage for ExpressionError {

fn notes(&self) -> Vec<Note> {
match self {
Abort { .. } => vec![],
Return { .. } => vec![],
Return { .. } | Abort { .. } | Missing { .. } => vec![],
Error { notes, .. } => notes.clone(),
Fallible { .. } => vec![Note::SeeErrorDocs],
Missing { .. } => vec![],
}
}
}
Expand Down
21 changes: 1 addition & 20 deletions src/compiler/mod.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
#![deny(
// warnings,
clippy::all,
clippy::pedantic,
unreachable_pub,
unused_allocation,
unused_extern_crates,
unused_assignments,
unused_comparisons
)]
#![deny(warnings, clippy::pedantic)]
#![allow(
clippy::cast_possible_truncation, // allowed in initial deny commit
clippy::cast_possible_wrap, // allowed in initial deny commit
clippy::cast_precision_loss, // allowed in initial deny commit
clippy::cast_sign_loss, // allowed in initial deny commit
clippy::if_not_else, // allowed in initial deny commit
clippy::match_bool, // allowed in initial deny commit
clippy::match_same_arms, // allowed in initial deny commit
clippy::match_wild_err_arm, // allowed in initial deny commit
clippy::missing_errors_doc, // allowed in initial deny commit
clippy::missing_panics_doc, // allowed in initial deny commit
clippy::module_name_repetitions, // allowed in initial deny commit
clippy::needless_pass_by_value, // allowed in initial deny commit
clippy::return_self_not_must_use, // allowed in initial deny commit
clippy::semicolon_if_nothing_returned, // allowed in initial deny commit
clippy::similar_names, // allowed in initial deny commit
clippy::too_many_lines, // allowed in initial deny commit
let_underscore_drop, // allowed in initial deny commit
)]

use std::fmt::Debug;
Expand Down
6 changes: 2 additions & 4 deletions src/compiler/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,15 @@ impl Terminate {
#[must_use]
pub fn get_expression_error(self) -> ExpressionError {
match self {
Terminate::Abort(error) => error,
Terminate::Error(error) => error,
Terminate::Error(error) | Terminate::Abort(error) => error,
}
}
}

impl fmt::Display for Terminate {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Terminate::Abort(error) => error.fmt(f),
Terminate::Error(error) => error.fmt(f),
Terminate::Error(error) | Terminate::Abort(error) => error.fmt(f),
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ pub struct TypeInfo {
}

impl TypeInfo {
#[must_use]
pub fn new(state: impl Into<TypeState>, result: TypeDef) -> Self {
Self {
state: state.into(),
result,
}
}

#[must_use]
pub fn map_result(self, f: impl FnOnce(TypeDef) -> TypeDef) -> Self {
Self {
state: self.state,
Expand All @@ -39,6 +41,7 @@ pub struct TypeState {
}

impl TypeState {
#[must_use]
pub fn merge(self, other: Self) -> Self {
Self {
local: self.local.merge(other.local),
Expand Down Expand Up @@ -116,6 +119,7 @@ impl Default for ExternalEnv {
}

impl ExternalEnv {
#[must_use]
pub fn merge(self, other: Self) -> Self {
Self {
target: self.target.merge(other.target),
Expand Down
Loading

0 comments on commit 9225461

Please sign in to comment.