Fix all new warnings (#467)

This commit is contained in:
Denis Isidoro 2021-04-04 18:06:35 -03:00 committed by GitHub
parent b6be9db6a8
commit 17cd4f52d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 21 deletions

View file

@ -6,21 +6,21 @@ source "${NAVI_HOME}/scripts/install"
cd "$NAVI_HOME"
header "Cargo nighly fix..."
header "cargo clippy fix..."
cargo +nightly clippy --fix -Z unstable-options || true
header "Cargo fix..."
header "cargo fix..."
cargo fix || true
header "Cargo fmt..."
header "cargo fmt..."
cargo fmt || true
header "clippy..."
cargo clippy || true
header "dot code beautify..."
find scripts -type f | xargs -I% dot code beautify % || true
dot code beautify "${NAVI_HOME}/alfred/alfred.bash" || true
dot code beautify "${NAVI_HOME}/alfred/alfred2.bash" || true
dot code beautify "${NAVI_HOME}/tests/core.bash" || true
dot code beautify "${NAVI_HOME}/tests/run" || true
header "clippy..."
cargo clippy || true

View file

@ -4,17 +4,11 @@ use crate::parser;
use crate::structures::cheat::VariableMap;
use anyhow::Context;
use anyhow::Error;
use regex::Regex;
use std::collections::HashSet;
use std::process::{self, Command, Stdio};
lazy_static! {
static ref UNKNOWN_TOPIC_REGEX: Regex = Regex::new(r"^Unknown topic\.").expect("Invalid regex");
}
fn map_line(line: &str) -> Result<String, Error> {
let line = line.trim().trim_end_matches(':');
Ok(line.to_string())
fn map_line(line: &str) -> String {
line.trim().trim_end_matches(':').to_string()
}
fn lines(query: &str, markdown: &str) -> impl Iterator<Item = Result<String, Error>> {
@ -24,7 +18,7 @@ fn lines(query: &str, markdown: &str) -> impl Iterator<Item = Result<String, Err
query, markdown
)
.lines()
.map(map_line)
.map(|line| Ok(map_line(line)))
.collect::<Vec<Result<String, Error>>>()
.into_iter()
}
@ -38,7 +32,7 @@ fn read_all(
let mut variables = VariableMap::new();
let mut visited_lines = HashSet::new();
if UNKNOWN_TOPIC_REGEX.is_match(cheat) {
if cheat.starts_with("Unknown topic.") {
eprintln!(
"`{}` not found in cheatsh.

View file

@ -34,9 +34,9 @@ fn convert_tldr_vars(line: &str) -> String {
new_line
}
fn convert_tldr(line: &str) -> Result<String, Error> {
fn convert_tldr(line: &str) -> String {
let line = line.trim();
let new_line = if line.starts_with('-') {
if line.starts_with('-') {
format!("{}{}", "# ", &line[2..line.len() - 1])
} else if line.starts_with('`') {
convert_tldr_vars(&line[1..line.len() - 1])
@ -44,8 +44,7 @@ fn convert_tldr(line: &str) -> Result<String, Error> {
line.to_string()
} else {
"".to_string()
};
Ok(new_line)
}
}
fn markdown_lines(query: &str, markdown: &str) -> impl Iterator<Item = Result<String, Error>> {
@ -55,7 +54,7 @@ fn markdown_lines(query: &str, markdown: &str) -> impl Iterator<Item = Result<St
query, markdown
)
.lines()
.map(convert_tldr)
.map(|line| Ok(convert_tldr(line)))
.collect::<Vec<Result<String, Error>>>()
.into_iter()
}