Adopt and apply nightly clippy configuration
This commit is contained in:
parent
2e95c94f54
commit
5b5541c28f
33 changed files with 233 additions and 139 deletions
21
src/graph.rs
21
src/graph.rs
|
|
@ -78,7 +78,7 @@ impl Graph {
|
|||
}
|
||||
}
|
||||
|
||||
/// Takes a file path to a TOML file and returns a modulated Graph
|
||||
/// Takes a file path to a TOML file and returns a modulated Graph.
|
||||
///
|
||||
/// If `path` is None, it will fallback to CLI arguments or their defaults.
|
||||
///
|
||||
|
|
@ -99,11 +99,18 @@ impl Graph {
|
|||
let cli_path = Arguments::default().parse().graph_path;
|
||||
let path = in_path.map_or(cli_path, PathBuf::from);
|
||||
|
||||
let toml_source = match std::fs::read_to_string(path) {
|
||||
let toml_source = match std::fs::read_to_string(&path) {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
log!(ERROR, "Failed reading {e}");
|
||||
return Err("Failed reading file at {path}".to_string());
|
||||
log!(
|
||||
ERROR,
|
||||
"Error reading path {}: {e}",
|
||||
path.as_path().display(),
|
||||
);
|
||||
return Err(format!(
|
||||
"Failed reading file at {}",
|
||||
path.as_path().display(),
|
||||
));
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -192,7 +199,7 @@ impl Graph {
|
|||
tlog!(&instant, "Parsed configuration");
|
||||
}
|
||||
|
||||
/// Construct a `HashMap` with incoming connections (reversed edges)
|
||||
/// Construct a `HashMap` with incoming connections (reversed edges).
|
||||
fn map_incoming(&mut self) {
|
||||
for node in self.nodes.clone().into_values() {
|
||||
for edge in node.connections.clone().values() {
|
||||
|
|
@ -372,7 +379,7 @@ impl Graph {
|
|||
}
|
||||
}
|
||||
|
||||
/// Increments detached node statistics for the given node ID
|
||||
/// Increments detached node statistics for the given node ID.
|
||||
///
|
||||
/// Performs checked arithmetic to the following effect:
|
||||
/// - Stats will saturate at `u32::MAX`
|
||||
|
|
@ -392,7 +399,7 @@ impl Graph {
|
|||
}
|
||||
|
||||
pub fn find_node(&self, query: &str) -> QueryResult {
|
||||
let collapsed_query = query.trim().replace(" ", "");
|
||||
let collapsed_query = query.trim().replace(' ', "");
|
||||
|
||||
if query == collapsed_query {
|
||||
log!(VERBOSE, "Chasing candidate for query {query}");
|
||||
|
|
|
|||
|
|
@ -105,9 +105,9 @@ impl Default for Config {
|
|||
}
|
||||
|
||||
// See: https://github.com/serde-rs/serde/issues/368
|
||||
fn mktrue() -> bool { true }
|
||||
fn mkfalse() -> bool { false }
|
||||
fn mk8() -> u16 { 8 }
|
||||
const fn mktrue() -> bool { true }
|
||||
const fn mkfalse() -> bool { false }
|
||||
const fn mk8() -> u16 { 8 }
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct Version {
|
||||
|
|
@ -148,7 +148,7 @@ impl Version {
|
|||
Version::from_text(env!("CARGO_PKG_VERSION"))
|
||||
}
|
||||
|
||||
/// Parses a string into a Version struct
|
||||
/// Parses a string into a Version struct.
|
||||
///
|
||||
/// It is expected for the version string to contain exactly three
|
||||
/// dot-separated numeric values with an optional leading `v` character.
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ pub mod prelude {
|
|||
pub use crate::{
|
||||
log,
|
||||
log::{Level::*, now},
|
||||
tlog,
|
||||
tlog, write_log,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
23
src/log.rs
23
src/log.rs
|
|
@ -4,7 +4,7 @@ pub use level::*;
|
|||
|
||||
mod level;
|
||||
|
||||
/// Strings in this slice suppress logging if found in the stack trace
|
||||
/// Strings in this slice suppress logging if found in the stack trace.
|
||||
pub const EXCLUSIONS: &[&str] = &["en::graph::Graph::parse_config"];
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -46,7 +46,7 @@ impl Data {
|
|||
&& !excluded_by_env
|
||||
&& matches_filter;
|
||||
|
||||
#[allow(clippy::print_stderr)]
|
||||
#[expect(clippy::print_stderr)]
|
||||
if env_level == Level::META {
|
||||
eprintln!(
|
||||
"Log decision for message from {path}: {should_log} given\n\
|
||||
|
|
@ -79,7 +79,7 @@ pub fn env_level() -> Level {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::print_stderr)]
|
||||
#[expect(clippy::print_stderr)]
|
||||
pub fn print_state() {
|
||||
let env_level = env_level();
|
||||
let version = env!("CARGO_PKG_VERSION");
|
||||
|
|
@ -90,7 +90,7 @@ pub fn print_state() {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::print_stderr)]
|
||||
#[expect(clippy::print_stderr)]
|
||||
pub fn timed(past: &Instant, message: &str) -> Instant {
|
||||
let now = Instant::now();
|
||||
let env_level = env_level();
|
||||
|
|
@ -120,7 +120,7 @@ macro_rules! tlog {
|
|||
|
||||
pub fn now() -> Instant { Instant::now() }
|
||||
|
||||
#[allow(clippy::print_stderr)]
|
||||
#[expect(clippy::print_stderr, clippy::use_debug)]
|
||||
pub fn elog(function: &str, message: &str) {
|
||||
eprintln!("{:?} [{function}] {message}", crate::ONSET.elapsed());
|
||||
}
|
||||
|
|
@ -214,6 +214,17 @@ pub fn wrap(s: &str) -> String {
|
|||
symbolize("e(&escape(s)))
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! write_log {
|
||||
($buffer:expr, $format_string:expr $(, $format_args:expr)* $(,)?) => {{
|
||||
use std::fmt::Write as _;
|
||||
let result = write!($buffer, $format_string $(, $format_args)*);
|
||||
if let Err(error) = result {
|
||||
log!(ERROR, "Unexpected error writing into {}: ${error}", $buffer);
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
@ -239,7 +250,7 @@ mod tests {
|
|||
}
|
||||
|
||||
fn run_in_debug_level(level: &str) {
|
||||
#[allow(unsafe_code)]
|
||||
#[expect(unsafe_code)]
|
||||
unsafe {
|
||||
std::env::set_var("DEBUG", level);
|
||||
log!("Debug is set to {level}");
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::{backtrace, io, panic};
|
|||
use en::{ONSET, graph::Graph, log, prelude::*, syntax};
|
||||
|
||||
#[tokio::main]
|
||||
#[allow(clippy::print_stderr, clippy::print_stdout)]
|
||||
#[expect(clippy::print_stderr, clippy::print_stdout, clippy::use_debug)]
|
||||
async fn main() -> io::Result<()> {
|
||||
log::print_state();
|
||||
let mut instant = now();
|
||||
|
|
|
|||
|
|
@ -37,13 +37,10 @@ pub async fn node(
|
|||
"node",
|
||||
&context,
|
||||
if found { 500 } else { 404 },
|
||||
Some(
|
||||
format!(
|
||||
"Failed to generate page for node {} (ID {}).",
|
||||
node.title, id
|
||||
)
|
||||
.to_owned(),
|
||||
),
|
||||
Some(format!(
|
||||
"Failed to generate page for node {} (ID {}).",
|
||||
node.title, id
|
||||
)),
|
||||
!found,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ pub async fn data(State(state): State<GlobalState>) -> Response<Body> {
|
|||
|
||||
let mut detached_pairs: Vec<(String, u32)> =
|
||||
state.graph.stats.detached.clone().into_iter().collect();
|
||||
detached_pairs.sort_by(|a, b| b.1.cmp(&a.1));
|
||||
detached_pairs.sort_by_key(|b| std::cmp::Reverse(b.1));
|
||||
|
||||
let mut context = tera::Context::default();
|
||||
context.insert("graph", &state.graph);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use crate::{
|
|||
router::{GlobalState, handlers::raw::make_response},
|
||||
};
|
||||
|
||||
/// Assembles a response containing the graph as its only context
|
||||
/// Assembles a response containing the graph as its only context.
|
||||
///
|
||||
/// The template name **must not** contain the extension.
|
||||
#[expect(clippy::unused_async)]
|
||||
|
|
@ -38,7 +38,7 @@ pub(in crate::router::handlers) fn with_context(
|
|||
make_response(&body, status_code, &[(header::CONTENT_TYPE, "text/html")])
|
||||
}
|
||||
|
||||
/// Renderes a template into a String and error code
|
||||
/// Renderes a template into a String and error code.
|
||||
///
|
||||
/// The template name **must not** contain the extension (e.g. `.html`).
|
||||
pub(in crate::router::handlers) fn render(
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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]"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue