Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy lints #404

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions numbat-cli/src/completer.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use std::sync::{Arc, Mutex};

use numbat::{unicode_input::UNICODE_INPUT, Context};
use rustyline::{
self,
completion::{extract_word, Completer, Pair},
};
use rustyline::completion::{extract_word, Completer, Pair};

pub struct NumbatCompleter {
pub context: Arc<Mutex<Context>>,
Expand Down
3 changes: 1 addition & 2 deletions numbat-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ use anyhow::{bail, Context as AnyhowContext, Result};
use clap::Parser;
use rustyline::config::Configurer;
use rustyline::{
self, error::ReadlineError, history::DefaultHistory, Completer, Editor, Helper, Hinter,
Validator,
error::ReadlineError, history::DefaultHistory, Completer, Editor, Helper, Hinter, Validator,
};
use rustyline::{EventHandler, Highlighter, KeyCode, KeyEvent, Modifiers};

Expand Down
18 changes: 9 additions & 9 deletions numbat-wasm/src/jquery_terminal_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ pub fn jt_format(class: Option<&str>, content: &str) -> String {
}

let content = html_escape::encode_text(content)
.replace("[", "&#91;")
.replace("]", "&#93;");
.replace('[', "&#91;")
.replace(']', "&#93;");

if let Some(class) = class {
format!("[[;;;hl-{class}]{content}]")
} else {
content.into()
content
}
}

Expand Down Expand Up @@ -68,19 +68,19 @@ impl std::io::Write for JqueryTerminalWriter {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
if let Some(color) = &self.color {
if color.fg() == Some(&Color::Red) {
self.buffer.write("[[;;;hl-diagnostic-red]".as_bytes())?;
self.buffer.write_all("[[;;;hl-diagnostic-red]".as_bytes())?;
let size = self.buffer.write(buf)?;
self.buffer.write("]".as_bytes())?;
self.buffer.write_all("]".as_bytes())?;
Ok(size)
} else if color.fg() == Some(&Color::Blue) {
self.buffer.write("[[;;;hl-diagnostic-blue]".as_bytes())?;
self.buffer.write_all("[[;;;hl-diagnostic-blue]".as_bytes())?;
let size = self.buffer.write(buf)?;
self.buffer.write("]".as_bytes())?;
self.buffer.write_all("]".as_bytes())?;
Ok(size)
} else if color.bold() {
self.buffer.write("[[;;;hl-diagnostic-bold]".as_bytes())?;
self.buffer.write_all("[[;;;hl-diagnostic-bold]".as_bytes())?;
let size = self.buffer.write(buf)?;
self.buffer.write("]".as_bytes())?;
self.buffer.write_all("]".as_bytes())?;
Ok(size)
} else {
self.buffer.write(buf)
Expand Down
4 changes: 2 additions & 2 deletions numbat-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl Numbat {
FormatType::JqueryTerminal => Box::new(JqueryTerminalFormatter {}),
FormatType::Html => Box::new(HtmlFormatter {}),
};
fmt.format(&markup, indent).into()
fmt.format(markup, indent)
}

pub fn interpret(&mut self, code: &str) -> InterpreterOutput {
Expand All @@ -102,7 +102,7 @@ impl Numbat {

match self
.ctx
.interpret_with_settings(&mut settings, &code, CodeSource::Text)
.interpret_with_settings(&mut settings, code, CodeSource::Text)
{
Ok((statements, result)) => {
// Pretty print
Expand Down
2 changes: 1 addition & 1 deletion numbat/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ fn from_unixtime(args: &[Value]) -> Result<Value> {
}

fn random(args: &[Value]) -> Result<Value> {
assert!(args.len() == 0);
assert!(args.is_empty());

let output = rand::random::<f64>();

Expand Down
2 changes: 1 addition & 1 deletion numbat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub struct Context {
}

impl Context {
pub fn new(module_importer: impl ModuleImporter + Send + Sync + 'static) -> Self {
pub fn new(module_importer: impl ModuleImporter + 'static) -> Self {
Context {
prefix_transformer: Transformer::new(),
typechecker: TypeChecker::default(),
Expand Down
4 changes: 2 additions & 2 deletions numbat/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ impl<'a> Parser<'a> {
} else if let Some(token) = self.match_exact(TokenKind::StringInterpolationStart) {
let mut parts = Vec::new();

self.interpolation(&mut parts, &token)?;
self.interpolation(&mut parts, token)?;

let mut span_full_string = token.span;
let mut has_end = false;
Expand All @@ -1153,7 +1153,7 @@ impl<'a> Parser<'a> {
span_full_string = span_full_string.extend(&inner_token.span);
match inner_token.kind {
TokenKind::StringInterpolationMiddle => {
self.interpolation(&mut parts, &inner_token)?;
self.interpolation(&mut parts, inner_token)?;
}
TokenKind::StringInterpolationEnd => {
parts.push(StringPart::Fixed(strip_first_and_last(&inner_token.lexeme)));
Expand Down
7 changes: 2 additions & 5 deletions numbat/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct Resolver {
}

impl Resolver {
pub(crate) fn new(importer: impl ModuleImporter + Send + 'static) -> Self {
pub(crate) fn new(importer: impl ModuleImporter + 'static) -> Self {
Self {
importer: Arc::new(importer),
files: SimpleFiles::new(),
Expand Down Expand Up @@ -136,10 +136,7 @@ impl Resolver {

#[cfg(test)]
mod tests {
use crate::{
ast::{Expression, Statement},
number::Number,
};
use crate::{ast::Expression, number::Number};

use super::*;

Expand Down
1 change: 1 addition & 0 deletions numbat/src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ pub fn tokenize(input: &str, code_source_id: usize) -> Result<Vec<Token>> {
}

#[cfg(test)]
#[allow(clippy::type_complexity)]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to merge this PR if we can remove these excepts. Here and below.

fn tokenize_reduced(input: &str) -> Result<Vec<(String, TokenKind, (u32, u32))>, String> {
Ok(tokenize(input, 0)
.map_err(|e| {
Expand Down
1 change: 1 addition & 0 deletions numbat/src/typechecker.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::result_large_err)]
use std::{
collections::{HashMap, HashSet},
error::Error,
Expand Down
2 changes: 1 addition & 1 deletion numbat/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl PrettyPrint for Value {
Value::String(s) => s.pretty_print(),
Value::DateTime(dt) => crate::markup::string(crate::datetime::to_rfc2822_save(dt)),
Value::FunctionReference(r) => crate::markup::string(r.to_string()),
Value::FormatSpecifiers(Some(s)) => crate::markup::string(s.to_string()),
Value::FormatSpecifiers(Some(s)) => crate::markup::string(s),
Value::FormatSpecifiers(None) => crate::markup::empty(),
}
}
Expand Down