More clippy pedantism! (#70)

This commit is contained in:
Danilo Bargen 2018-12-07 12:25:25 +01:00 committed by GitHub
commit 9548f1dd1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 45 additions and 57 deletions

View file

@ -38,7 +38,6 @@ tempdir = "^0.3"
utime = "0.2.0"
[features]
dev = ["clippy"]
logging = ["env_logger"]
[profile.release]

View file

@ -184,6 +184,18 @@ To get bash autocompletion, simply rename the file `bash_tealdeer` to `tldr`
and copy it to `/usr/share/bash-completion/completions/tldr`.
## Development
To run tests:
$ cargo test
To run lints:
$ rustup component add clippy
$ cargo clean && cargo clippy
## License
Licensed under either of

View file

@ -1,5 +1,9 @@
# Releasing
Run linting:
$ cargo clean && cargo clippy
Set variables:
$ export VERSION=X.Y.Z

View file

@ -24,13 +24,13 @@ pub struct Cache {
}
impl Cache {
pub fn new<S>(url: S, os: OsType) -> Cache
pub fn new<S>(url: S, os: OsType) -> Self
where
S: Into<String>,
{
Cache {
Self {
url: url.into(),
os: os,
os,
}
}
@ -132,6 +132,7 @@ impl Cache {
}
/// Return the platform directory.
#[allow(clippy::match_same_arms)]
fn get_platform_dir(&self) -> Option<&'static str> {
match self.os {
OsType::Linux => Some("linux"),

View file

@ -35,7 +35,7 @@ pub enum RawColor {
}
impl From<RawColor> for Color {
fn from(raw_color: RawColor) -> Color {
fn from(raw_color: RawColor) -> Self {
match raw_color {
RawColor::Black => Color::Black,
RawColor::Red => Color::Red,
@ -60,8 +60,8 @@ struct RawStyle {
}
impl Default for RawStyle {
fn default() -> RawStyle {
RawStyle {
fn default() -> Self {
Self {
foreground: None,
background: None,
underline: false,
@ -71,8 +71,8 @@ impl Default for RawStyle {
} // impl RawStyle
impl From<RawStyle> for Style {
fn from(raw_style: RawStyle) -> Style {
let mut style = Style::default();
fn from(raw_style: RawStyle) -> Self {
let mut style = Self::default();
if let Some(foreground) = raw_style.foreground {
style = style.fg(Color::from(foreground));
@ -114,8 +114,8 @@ struct RawConfig {
}
impl RawConfig {
fn new() -> RawConfig {
let mut raw_config = RawConfig::default();
fn new() -> Self {
let mut raw_config = Self::default();
// Set default config
raw_config.style.example_text.foreground = Some(RawColor::Green);
@ -143,8 +143,8 @@ pub struct Config {
}
impl From<RawConfig> for Config {
fn from(raw_config: RawConfig) -> Config {
Config {
fn from(raw_config: RawConfig) -> Self {
Self {
style: StyleConfig {
command_name: raw_config.style.command_name.into(),
description: raw_config.style.description.into(),
@ -156,12 +156,13 @@ impl From<RawConfig> for Config {
}
}
#[allow(clippy::needless_pass_by_value)]
fn map_io_err_to_config_err(e: IoError) -> TealdeerError {
ConfigError(format!("Io Error: {}", e))
}
impl Config {
pub fn load() -> Result<Config, TealdeerError> {
pub fn load() -> Result<Self, TealdeerError> {
debug!("Loading config");
// Determine path
@ -182,7 +183,7 @@ impl Config {
RawConfig::new()
};
Ok(Config::from(raw_config))
Ok(Self::from(raw_config))
}
} // impl Config

View file

@ -2,6 +2,7 @@ use std::fmt;
use reqwest::Error as ReqwestError;
#[derive(Debug)]
#[allow(clippy::pub_enum_variant_names)]
pub enum TealdeerError {
CacheError(String),
ConfigError(String),
@ -9,7 +10,7 @@ pub enum TealdeerError {
}
impl From<ReqwestError> for TealdeerError {
fn from(err: ReqwestError) -> TealdeerError {
fn from(err: ReqwestError) -> Self {
TealdeerError::UpdateError(format!("HTTP error: {}", err.to_string()))
}
}

View file

@ -8,40 +8,10 @@
// option. All files in the project carrying such notice may not be
// copied, modified, or distributed except according to those terms.
#![deny(
missing_docs,
missing_debug_implementations,
unsafe_code,
unused_import_braces,
unused_qualifications
)]
#![warn(
trivial_casts,
trivial_numeric_casts,
missing_copy_implementations,
unused_extern_crates,
unused_results
)]
#![cfg_attr(feature = "dev", feature(plugin))]
#![cfg_attr(feature = "dev", plugin(clippy))]
#![cfg_attr(
feature = "dev",
warn(
cast_possible_truncation,
cast_possible_wrap,
cast_precision_loss,
cast_sign_loss,
mut_mut,
non_ascii_literal,
option_unwrap_used,
result_unwrap_used,
shadow_reuse,
shadow_same,
unicode_not_nfc,
wrong_self_convention,
wrong_pub_self_convention
)
)]
#![deny(clippy::all)]
#![warn(clippy::pedantic)]
#![allow(clippy::similar_names)]
#![allow(clippy::stutter)]
#[cfg(feature = "logging")]
extern crate env_logger;
@ -105,7 +75,7 @@ To render a local file (for testing):
$ tldr --render /path/to/file.md
";
const ARCHIVE_URL: &str = "https://github.com/tldr-pages/tldr/archive/master.tar.gz";
const MAX_CACHE_AGE: i64 = 2592000; // 30 days
const MAX_CACHE_AGE: i64 = 2_592_000; // 30 days
#[derive(Debug, Deserialize)]
struct Args {

View file

@ -15,7 +15,7 @@ pub enum TldrFormat {
V2,
}
/// A tokenizer is initialized with a BufReader instance that contains the
/// A tokenizer is initialized with a `BufReader` instance that contains the
/// entire Tldr page. It then returns tokens as `Option<LineType>`.
#[derive(Debug)]
pub struct Tokenizer<R: BufRead> {
@ -33,9 +33,9 @@ impl<R> Tokenizer<R>
where
R: BufRead,
{
pub fn new(reader: R) -> Tokenizer<R> {
Tokenizer {
reader: reader,
pub fn new(reader: R) -> Self {
Self {
reader,
first_line: true,
current_line: String::new(),
format: TldrFormat::Undecided,

View file

@ -37,7 +37,7 @@ pub enum LineType {
impl<'a> From<&'a str> for LineType {
/// Convert a string slice to a LineType. Newlines and trailing whitespace are trimmed.
fn from(line: &'a str) -> LineType {
fn from(line: &'a str) -> Self {
let trimmed: &str = line.trim_right();
let mut chars = trimmed.chars();
match chars.next() {
@ -65,7 +65,7 @@ impl<'a> From<&'a str> for LineType {
impl LineType {
/// Support for old format.
/// TODO: Remove once old format has been phased out!
pub fn from_v1(line: &str) -> LineType {
pub fn from_v1(line: &str) -> Self {
let trimmed = line.trim();
let mut chars = trimmed.chars();
match chars.next() {