Skip to content

Commit

Permalink
Fix all new warnings (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
denisidoro authored Apr 4, 2021
1 parent b6be9db commit 17cd4f5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
12 changes: 6 additions & 6 deletions scripts/fix
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 4 additions & 10 deletions src/cheatsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>> {
Expand All @@ -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()
}
Expand All @@ -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.
Expand Down
9 changes: 4 additions & 5 deletions src/tldr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,17 @@ 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])
} else if line.starts_with('%') {
line.to_string()
} else {
"".to_string()
};
Ok(new_line)
}
}

fn markdown_lines(query: &str, markdown: &str) -> impl Iterator<Item = Result<String, Error>> {
Expand All @@ -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()
}
Expand Down

0 comments on commit 17cd4f5

Please # to comment.