Adopt and apply nightly clippy configuration

This commit is contained in:
Juno Takano 2026-02-16 23:31:18 -03:00
commit 5b5541c28f
33 changed files with 233 additions and 139 deletions

View file

@ -7,7 +7,7 @@ use crate::prelude::*;
static FIRST_PARSE: AtomicBool = AtomicBool::new(true);
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Arguments {
pub hostname: String,
pub port: u16,

View file

@ -33,7 +33,7 @@ pub(super) fn rich_read(input: &str, graph: &Graph) -> TokenOutput {
}
/// Apply end-to-end point and inline parsing for nested formatting, such as
/// inside the display text of anchors and list items
/// inside the display text of anchors and list items.
pub fn format(input: &str, graph: &Graph) -> (String, Vec<Token>) {
let tokens = lex(input, LEXMAP, graph, false).tokens;
(parse(&tokens), tokens)

View file

@ -61,7 +61,7 @@ pub fn parse(
&& !lexeme.match_next_char('|')
{
log!(VERBOSE, "End: Plural anchor");
candidate.set_destination(Some(&candidate.text().clone()));
candidate.set_destination(Some(&candidate.text()));
candidate.text_push("s");
if lexeme.last() {
push(None, tokens, state, graph);
@ -73,7 +73,7 @@ pub fn parse(
if candidate.text().contains(':') {
candidate.set_external(true);
}
push(Some(&candidate.text().clone()), tokens, state, graph);
push(Some(&candidate.text()), tokens, state, graph);
} else {
push(Some(&buffer.destination.clone()), tokens, state, graph);
}

View file

@ -112,7 +112,7 @@ pub fn parse(
iterator.next();
return true;
} else if lexeme.match_char('\n') {
tokens.push(Token::LineBreak(LineBreak::default()));
tokens.push(Token::LineBreak(LineBreak));
return true;
}
},

View file

@ -48,11 +48,10 @@ pub fn parse(
log!(VERBOSE, "Inline Context: Code -> None on {lexeme}");
state.context.inline = Inline::None;
tokens.push(Token::Code(Code::new(false)));
return true;
} else {
tokens.push(Token::Literal(Literal::lex(lexeme)));
return true;
}
return true;
},
Inline::Anchor => {
if context::anchor::parse(lexeme, state, tokens, graph) {

View file

@ -30,7 +30,7 @@ pub fn parse(
let candidate = &mut buffer.candidate;
let item_candidate = &mut buffer.item_candidate;
#[allow(clippy::wildcard_enum_match_arm)]
#[expect(clippy::wildcard_enum_match_arm)]
match state.context.block {
Block::List => {
if lexeme.match_char(' ') && item_candidate.depth.is_none() {

View file

@ -26,7 +26,7 @@ pub fn parse(
let buffer = &mut state.buffers.quote;
let candidate = &mut buffer.candidate;
#[allow(clippy::wildcard_enum_match_arm)]
#[expect(clippy::wildcard_enum_match_arm)]
match state.context.block {
Block::Quote => {
if Quote::probe_end(lexeme) {

View file

@ -32,7 +32,7 @@ pub fn parse(
parsed_text
};
#[allow(clippy::wildcard_enum_match_arm)]
#[expect(clippy::wildcard_enum_match_arm)]
match state.context.block {
Block::Table => {
if Table::probe_end(lexeme) {

View file

@ -26,9 +26,9 @@ impl Lexeme {
pub fn next(&self) -> String { self.next.clone() }
pub fn last(&self) -> bool { self.last }
pub const fn last(&self) -> bool { self.last }
pub fn first(&self) -> bool { self.first }
pub const fn first(&self) -> bool { self.first }
pub fn mutate_text(&mut self, new: &str) { self.text = new.to_string(); }
@ -146,7 +146,7 @@ impl Lexeme {
}
/// # Panics
/// Panics if number of chars for a single lexeme exceeds `i32::MAX`
/// Panics if number of chars for a single lexeme exceeds `i32::MAX`.
pub fn count_char(&self, c: char) -> i32 {
let count = self.text().chars().filter(|&n| n == c).count();
match i32::try_from(count) {

View file

@ -17,9 +17,9 @@ pub fn parse(
tokens: &mut Vec<Token>,
iterator: &mut Peekable<Iter<'_, Lexeme>>,
) -> bool {
if let super::context::Block::PreFormat = state.context.block {
return false;
} else if let super::context::Inline::Code = state.context.inline {
if matches!(state.context.block, super::context::Block::PreFormat)
|| matches!(state.context.inline, super::context::Inline::Code)
{
return false;
}

View file

@ -28,15 +28,21 @@ impl Anchor {
self.route();
}
pub fn balanced(&self) -> bool { self.balanced }
pub const fn balanced(&self) -> bool { self.balanced }
pub fn set_balanced(&mut self, balanced: bool) { self.balanced = balanced; }
pub const fn set_balanced(&mut self, balanced: bool) {
self.balanced = balanced;
}
pub fn external(&self) -> bool { self.external }
pub const fn external(&self) -> bool { self.external }
pub fn set_external(&mut self, external: bool) { self.external = external; }
pub const fn set_external(&mut self, external: bool) {
self.external = external;
}
pub fn set_leading(&mut self, leading: bool) { self.leading = leading; }
pub const fn set_leading(&mut self, leading: bool) {
self.leading = leading;
}
pub fn node(&self) -> Option<Node> { self.node.clone() }
@ -52,7 +58,7 @@ impl Anchor {
fn route(&mut self) {
self.destination = if let Some(destination) = self.destination.clone() {
if destination.contains(":") || destination.contains("/") {
if destination.contains(':') || destination.contains('/') {
Some(destination)
} else if destination.is_empty() && self.text.is_empty() {
None

View file

@ -6,7 +6,7 @@ pub struct Bold {
}
impl Bold {
pub fn new(open: bool) -> Bold { Bold { open } }
pub const fn new(open: bool) -> Bold { Bold { open } }
}
impl Parseable for Bold {

View file

@ -6,7 +6,7 @@ pub struct CheckBox {
}
impl CheckBox {
pub fn new(checked: bool) -> CheckBox { CheckBox { checked } }
pub const fn new(checked: bool) -> CheckBox { CheckBox { checked } }
}
impl Parseable for CheckBox {

View file

@ -6,7 +6,7 @@ pub struct Code {
}
impl Code {
pub fn new(open: bool) -> Code { Code { open } }
pub const fn new(open: bool) -> Code { Code { open } }
}
impl Parseable for Code {

View file

@ -32,7 +32,7 @@ impl Header {
) -> String {
let base_id = if !config.ascii_dom_ids || next_lexeme.next().is_ascii()
{
next_lexeme.next().clone()
next_lexeme.next()
} else {
String::from("h")
};
@ -60,7 +60,7 @@ impl Header {
}
}
pub fn level(&self) -> u8 {
pub const fn level(&self) -> u8 {
match self.level {
Level::One => 1,
Level::Two => 2,
@ -147,7 +147,7 @@ pub enum Level {
}
impl Level {
fn from_u8(u: u8) -> Level {
const fn from_u8(u: u8) -> Level {
if u <= 1 {
Level::One
} else if u == 2 {

View file

@ -1,7 +1,7 @@
use crate::syntax::content::{Parseable, parser::Lexeme};
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct LineBreak {}
pub struct LineBreak;
impl Parseable for LineBreak {
fn probe(lexeme: &Lexeme) -> bool {

View file

@ -43,19 +43,19 @@ impl Parseable for List {
.unwrap_or(0)
.strict_div(scale);
output.push_str(&format!("<li>{}", item.text));
write_log!(output, "<li>{}", item.text);
if next_level > level {
// open nested lists
for _ in 0..(next_level.saturating_sub(level)) {
output.push_str(&format!("<{tag}>\n"));
write_log!(output, "<{tag}>\n");
}
} else {
// close current item
output.push_str("</li>");
// close nested lists
for _ in 0..(level.saturating_sub(next_level)) {
output.push_str(&format!("</{tag}></li>"));
write_log!(output, "</{tag}></li>");
}
output.push('\n');
}
@ -70,7 +70,7 @@ impl Parseable for List {
}
impl List {
pub fn new(ordered: bool) -> List {
pub const fn new(ordered: bool) -> List {
List {
ordered,
items: vec![],
@ -202,7 +202,7 @@ mod tests {
fn token_display() {
let list = List::new(false);
assert_eq!(
format!("{}", Token::List(list.clone())),
format!("{}", Token::List(list)),
"Tk:List [0 unordered items]"
);
}

View file

@ -6,7 +6,7 @@ pub struct Oblique {
}
impl Oblique {
pub fn new(open: bool) -> Oblique { Oblique { open } }
pub const fn new(open: bool) -> Oblique { Oblique { open } }
}
impl Parseable for Oblique {

View file

@ -6,7 +6,7 @@ pub struct Paragraph {
}
impl Paragraph {
pub fn new(open: bool) -> Paragraph { Paragraph { open: Some(open) } }
pub const fn new(open: bool) -> Paragraph { Paragraph { open: Some(open) } }
pub fn probe_end(lexeme: &Lexeme) -> bool {
lexeme.match_char('\n') && lexeme.match_next_char('\n')

View file

@ -6,7 +6,7 @@ pub struct PreFormat {
}
impl PreFormat {
pub fn new(open: bool) -> PreFormat { PreFormat { open: Some(open) } }
pub const fn new(open: bool) -> PreFormat { PreFormat { open: Some(open) } }
}
impl std::fmt::Display for PreFormat {

View file

@ -6,7 +6,7 @@ pub struct Strike {
}
impl Strike {
pub fn new(open: bool) -> Strike { Strike { open } }
pub const fn new(open: bool) -> Strike { Strike { open } }
}
impl Parseable for Strike {

View file

@ -6,7 +6,7 @@ pub struct Underline {
}
impl Underline {
pub fn new(open: bool) -> Underline { Underline { open } }
pub const fn new(open: bool) -> Underline { Underline { open } }
}
impl Parseable for Underline {

View file

@ -7,7 +7,7 @@ pub struct Verse {
}
impl Verse {
pub fn new(open: bool) -> Verse {
pub const fn new(open: bool) -> Verse {
Verse {
open: Some(open),
citation: None,