add clippy in pedantic mode and fix everything
parent
a3d457520a
commit
e0078e304d
|
@ -3,6 +3,12 @@ name = "zettel"
|
|||
version = "0.1.0"
|
||||
authors = ["Brian Hicks <brian@brianthicks.com>"]
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
repository = "https://git.bytes.zone/brian/zettel"
|
||||
readme = "README.md"
|
||||
keywords = ["TODO"]
|
||||
categories = ["TODO"]
|
||||
description = "command-line management of Zettelkasten"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
|
|
@ -15,5 +15,6 @@ stdenv.mkDerivation {
|
|||
rustc
|
||||
rustfmt
|
||||
cargo-watch
|
||||
rustPackages.clippy
|
||||
];
|
||||
}
|
||||
|
|
21
src/lib.rs
21
src/lib.rs
|
@ -1,3 +1,4 @@
|
|||
#![deny(clippy::all, clippy::pedantic, clippy::cargo)]
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
|
@ -24,7 +25,7 @@ pub struct Source {
|
|||
}
|
||||
|
||||
impl Config {
|
||||
pub fn load() -> Result<Config, ConfigLoadingError> {
|
||||
pub fn load() -> Result<Self, ConfigLoadingError> {
|
||||
let mut config = PathBuf::new();
|
||||
match env::var("ZETTEL_CONFIG") {
|
||||
Ok(val) => config.push(val),
|
||||
|
@ -43,12 +44,10 @@ impl Config {
|
|||
};
|
||||
|
||||
match File::open(config) {
|
||||
Ok(file) => {
|
||||
serde_json::from_reader(file).map_err(|err| ConfigLoadingError::JSONError(err))
|
||||
}
|
||||
Ok(file) => serde_json::from_reader(file).map_err(ConfigLoadingError::JSONError),
|
||||
Err(err) => {
|
||||
if err.kind() == ErrorKind::NotFound {
|
||||
Ok(Config {
|
||||
Ok(Self {
|
||||
sources: Vec::new(),
|
||||
})
|
||||
} else {
|
||||
|
@ -70,7 +69,7 @@ pub enum ConfigLoadingError {
|
|||
}
|
||||
|
||||
impl From<io::Error> for ConfigLoadingError {
|
||||
fn from(err: io::Error) -> ConfigLoadingError {
|
||||
fn from(err: io::Error) -> Self {
|
||||
ConfigLoadingError::IOError(err)
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +83,7 @@ pub struct Zettel {
|
|||
|
||||
impl Zettel {
|
||||
// TODO: this could maybe be an iterator?
|
||||
pub fn in_dir(directory: &Path) -> Result<Vec<Zettel>, io::Error> {
|
||||
pub fn in_dir(directory: &Path) -> Result<Vec<Self>, io::Error> {
|
||||
let mut out = Vec::new();
|
||||
|
||||
for entry in fs::read_dir(directory)? {
|
||||
|
@ -94,7 +93,7 @@ impl Zettel {
|
|||
continue;
|
||||
}
|
||||
|
||||
out.push(Zettel {
|
||||
out.push(Self {
|
||||
path: unwrapped.path(),
|
||||
})
|
||||
}
|
||||
|
@ -104,7 +103,7 @@ impl Zettel {
|
|||
|
||||
// TODO: is this the most efficient way to do this?
|
||||
// TODO: this mixes the logic of reading a file and parsing the first line. Separate!
|
||||
pub fn title(self: &Zettel) -> Result<String, io::Error> {
|
||||
pub fn title(self: &Self) -> Result<String, io::Error> {
|
||||
let file = File::open(&self.path)?;
|
||||
let mut reader = BufReader::new(file);
|
||||
|
||||
|
@ -127,7 +126,7 @@ impl Zettel {
|
|||
.to_string())
|
||||
}
|
||||
|
||||
pub fn path(self: &Zettel) -> &Path {
|
||||
pub fn path(self: &Self) -> &Path {
|
||||
self.path.as_path()
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +134,7 @@ impl Zettel {
|
|||
pub mod slugify {
|
||||
use regex::Regex;
|
||||
|
||||
pub fn slugify(input: &String) -> String {
|
||||
pub fn slugify(input: &str) -> String {
|
||||
lazy_static! {
|
||||
static ref DISALLOWED: Regex = Regex::new(r"[^\w ]").unwrap();
|
||||
static ref MANY_SPACES: Regex = Regex::new(r"\s+").unwrap();
|
||||
|
|
Reference in New Issue