From b53eeaf95b98fbd05d05081ebc5e3175d062c786 Mon Sep 17 00:00:00 2001 From: slerpy <48803074+slerpyyy@users.noreply.github.com> Date: Fri, 16 Oct 2020 11:37:54 +0200 Subject: [PATCH 1/2] Got it to build again --- Cargo.lock | 216 ++++++++++++++++++++++++++++++-------------------- Cargo.toml | 2 +- src/error.rs | 4 +- src/macros.rs | 5 +- 4 files changed, 135 insertions(+), 92 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bd03780..bdb6711 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,263 +1,305 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. [[package]] name = "aho-corasick" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b3fb52b09c1710b961acb35390d514be82e4ac96a9969a8e38565a29b878dc9" dependencies = [ - "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr", ] [[package]] name = "ansi_term" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6" + +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi 0.3.9", +] [[package]] name = "bitflags" -version = "0.7.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "cargo-count" version = "0.2.4" dependencies = [ - "ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "clap 2.11.2 (registry+https://github.com/rust-lang/crates.io-index)", - "clippy 0.0.88 (registry+https://github.com/rust-lang/crates.io-index)", - "gitignore 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.1.75 (registry+https://github.com/rust-lang/crates.io-index)", - "tabwriter 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "ansi_term 0.9.0", + "clap", + "clippy", + "gitignore", + "glob", + "regex", + "tabwriter", ] [[package]] name = "clap" -version = "2.11.2" +version = "2.33.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" dependencies = [ - "ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", - "strsim 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "term_size 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-segmentation 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "vec_map 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ansi_term 0.11.0", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", ] [[package]] name = "clippy" version = "0.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6cc502e63a10b490d8b445c728cfba3ea778a38a14432cf392b132e655cdf029" dependencies = [ - "clippy_lints 0.0.88 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy_lints", ] [[package]] name = "clippy_lints" version = "0.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28e4d47b13273289faf3e7a0d10e93e9ad5226c21e133e2e38ed09ca44a879fb" dependencies = [ - "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "toml 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "matches", + "quine-mc_cluskey", + "regex-syntax", + "rustc-serialize", + "semver", + "toml", + "unicode-normalization", ] [[package]] name = "gitignore" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cd9bd3a32e762ced4ea984bef04bb63700f0ac7964250eb16b25be637d39298" dependencies = [ - "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "glob", ] [[package]] name = "glob" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" + +[[package]] +name = "hermit-abi" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" +dependencies = [ + "libc", +] [[package]] name = "kernel32-sys" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8", + "winapi-build", ] [[package]] name = "libc" -version = "0.2.15" +version = "0.2.79" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743" [[package]] name = "matches" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15305656809ce5a4805b1ff2946892810992197ce1270ff79baded852187942e" [[package]] name = "memchr" version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20" dependencies = [ - "libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] [[package]] name = "nom" version = "1.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce" [[package]] name = "quine-mc_cluskey" version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07589615d719a60c8dd8a4622e7946465dfef20d1a428f969e3443e7386d5f45" [[package]] name = "regex" version = "0.1.75" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f62414f9d3b0f53e827ac46d6f8ce2ff6a91afd724225a5986e54e81e170693c" dependencies = [ - "aho-corasick 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", + "utf8-ranges", ] [[package]] name = "regex-syntax" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "279401017ae31cf4e15344aa3f085d0e2e5c1e70067289ef906906fdbe92c8fd" [[package]] name = "rustc-serialize" version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b" [[package]] name = "semver" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d5b7638a1f03815d94e88cb3b3c08e87f0db4d683ef499d1836aaf70a45623f" dependencies = [ - "nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "nom", ] [[package]] name = "strsim" -version = "0.5.1" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "tabwriter" version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85dbf563da2891d55ef4b00ef08c5b5f160143f67691ff1f97ad89e77824ed3b" dependencies = [ - "unicode-width 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width", ] [[package]] -name = "term_size" -version = "0.2.1" +name = "textwrap" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width", ] [[package]] name = "thread-id" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03" dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", + "kernel32-sys", + "libc", ] [[package]] name = "thread_local" version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55dd963dbaeadc08aa7266bf7f91c3154a7805e32bb94b820b769d2ef3b4744d" dependencies = [ - "thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "thread-id", ] [[package]] name = "toml" version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0590d72182e50e879c4da3b11c6488dae18fccb1ae0c7a3eda18e16795844796" dependencies = [ - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize", ] [[package]] name = "unicode-normalization" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "unicode-segmentation" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26643a2f83bac55f1976fb716c10234485f9202dcd65cfbdf9da49867b271172" [[package]] name = "unicode-width" -version = "0.1.3" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" [[package]] name = "utf8-ranges" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f" [[package]] name = "vec_map" -version = "0.6.0" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" [[package]] name = "winapi" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] [[package]] name = "winapi-build" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[metadata] -"checksum aho-corasick 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2b3fb52b09c1710b961acb35390d514be82e4ac96a9969a8e38565a29b878dc9" -"checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6" -"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" -"checksum clap 2.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8888b7b29ca3f7a23bc8b8526537f9e233a94c836140ffcfc6fdef1f320a40f7" -"checksum clippy 0.0.88 (registry+https://github.com/rust-lang/crates.io-index)" = "6cc502e63a10b490d8b445c728cfba3ea778a38a14432cf392b132e655cdf029" -"checksum clippy_lints 0.0.88 (registry+https://github.com/rust-lang/crates.io-index)" = "28e4d47b13273289faf3e7a0d10e93e9ad5226c21e133e2e38ed09ca44a879fb" -"checksum gitignore 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8cd9bd3a32e762ced4ea984bef04bb63700f0ac7964250eb16b25be637d39298" -"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" -"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "23e3757828fa702a20072c37ff47938e9dd331b92fac6e223d26d4b7a55f7ee2" -"checksum matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "15305656809ce5a4805b1ff2946892810992197ce1270ff79baded852187942e" -"checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20" -"checksum nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce" -"checksum quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "07589615d719a60c8dd8a4622e7946465dfef20d1a428f969e3443e7386d5f45" -"checksum regex 0.1.75 (registry+https://github.com/rust-lang/crates.io-index)" = "f62414f9d3b0f53e827ac46d6f8ce2ff6a91afd724225a5986e54e81e170693c" -"checksum regex-syntax 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279401017ae31cf4e15344aa3f085d0e2e5c1e70067289ef906906fdbe92c8fd" -"checksum rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b" -"checksum semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2d5b7638a1f03815d94e88cb3b3c08e87f0db4d683ef499d1836aaf70a45623f" -"checksum strsim 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "50c069df92e4b01425a8bf3576d5d417943a6a7272fbabaf5bd80b1aaa76442e" -"checksum tabwriter 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "85dbf563da2891d55ef4b00ef08c5b5f160143f67691ff1f97ad89e77824ed3b" -"checksum term_size 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f7f5f3f71b0040cecc71af239414c23fd3c73570f5ff54cf50e03cef637f2a0" -"checksum thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03" -"checksum thread_local 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "55dd963dbaeadc08aa7266bf7f91c3154a7805e32bb94b820b769d2ef3b4744d" -"checksum toml 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)" = "0590d72182e50e879c4da3b11c6488dae18fccb1ae0c7a3eda18e16795844796" -"checksum unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "26643a2f83bac55f1976fb716c10234485f9202dcd65cfbdf9da49867b271172" -"checksum unicode-segmentation 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b905d0fc2a1f0befd86b0e72e31d1787944efef9d38b9358a9e92a69757f7e3b" -"checksum unicode-width 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2d6722facc10989f63ee0e20a83cd4e1714a9ae11529403ac7e0afd069abc39e" -"checksum utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f" -"checksum vec_map 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cac5efe5cb0fa14ec2f84f83c701c562ee63f6dcc680861b21d65c682adfb05f" -"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index b6216aa..049809d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ name = "cargo-count" travis-ci = {repository = "kbknapp/cargo-count"} [dependencies] -clap = "~2.11.2" +clap = "~2.33" glob = "~0.2" tabwriter = "~0.1" regex = "~0.1" diff --git a/src/error.rs b/src/error.rs index c3a7401..40ab9e3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -41,7 +41,7 @@ impl CliError { impl Display for CliError { fn fmt(&self, f: &mut Formatter) -> FmtResult { - write!(f, "{} {}", Format::Error("error:"), self.description()) + write!(f, "{} {}", Format::Error("error:"), self.to_string()) } } @@ -55,7 +55,7 @@ impl Error for CliError { } } - fn cause(&self) -> Option<&Error> { + fn cause(&self) -> Option<&dyn Error> { None } } diff --git a/src/macros.rs b/src/macros.rs index 564a4ac..b42efbd 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,9 +1,8 @@ macro_rules! cli_try { ($t:expr) => ({ - use ::std::error::Error; match $t { Ok(o) => o, - Err(e) => return Err(CliError::Generic(e.description().to_owned())) + Err(e) => return Err(CliError::Generic(e.to_string().to_owned())) } }) } @@ -14,6 +13,7 @@ macro_rules! wlnerr( }) ); +#[allow(unused_macros)] macro_rules! werr( ($($arg:tt)*) => ({ use std::io::{Write, stderr}; @@ -57,6 +57,7 @@ macro_rules! debugln { ($fmt:expr, $($arg:tt)*) => (); } +#[allow(unused_macros)] #[cfg(not(feature = "debug"))] macro_rules! debug { ($fmt:expr) => (); From be91b58ce2433a52ed6fadacfae07fc08911e1f2 Mon Sep 17 00:00:00 2001 From: slerpy <48803074+slerpyyy@users.noreply.github.com> Date: Fri, 16 Oct 2020 11:42:56 +0200 Subject: [PATCH 2/2] Reformatted code with cargo fmt --- src/config.rs | 8 +-- src/count/counts.rs | 149 ++++++++++++++++++++++++++------------------ src/count/mod.rs | 21 ++++--- src/error.rs | 11 ++-- src/fmt.rs | 4 +- src/fsutil.rs | 55 +++++++++------- src/language.rs | 67 ++++++++++++++------ src/macros.rs | 14 ++--- src/main.rs | 63 +++++++++++-------- 9 files changed, 233 insertions(+), 159 deletions(-) diff --git a/src/config.rs b/src/config.rs index 05338cc..15014c1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,5 +1,3 @@ - - use clap::ArgMatches; use error::{CliError, CliResult}; @@ -34,9 +32,11 @@ impl<'a> Config<'a> { if let Some(ext_vec) = m.values_of("language") { for e in ext_vec { if let None = Language::from_ext(e) { - return Err(CliError::UnknownExt(format!("unsupported source code extension \ + return Err(CliError::UnknownExt(format!( + "unsupported source code extension \ '{}'", - e.to_owned()))); + e.to_owned() + ))); } } } diff --git a/src/count/counts.rs b/src/count/counts.rs index 7a26dea..230c6b3 100644 --- a/src/count/counts.rs +++ b/src/count/counts.rs @@ -1,5 +1,3 @@ - - use comment::Comment; use config::{Config, Utf8Rule}; use count::Count; @@ -54,11 +52,13 @@ impl<'c> Counts<'c> { for path in &self.cfg.to_count { debugln!("iter; path={:?};", path); let mut files = vec![]; - fsutil::get_all_files(&mut files, - path, - &self.cfg.exclude, - self.cfg.follow_links, - &gitignore); + fsutil::get_all_files( + &mut files, + path, + &self.cfg.exclude, + self.cfg.follow_links, + &gitignore, + ); for file in files { debugln!("iter; file={:?};", file); @@ -200,15 +200,19 @@ impl<'c> Counts<'c> { debugln!("There is a keyword"); debugln!("line={:?}", line); if is_in_unsafe { - debugln!("It didn't contain the keyword, but we are still in \ - unsafe"); + debugln!( + "It didn't contain the keyword, but we are still in \ + unsafe" + ); count.usafe += 1; bracket_count = Counts::count_brackets(line, Some(bracket_count)); is_in_unsafe = bracket_count > 0; - debugln!("after counting brackets; is_in_unsafe={:?}; \ + debugln!( + "after counting brackets; is_in_unsafe={:?}; \ bracket_count={:?}", - is_in_unsafe, - bracket_count); + is_in_unsafe, + bracket_count + ); } else if let Some(caps) = re.captures(line) { let mut should_count = true; if let Some(before) = caps.at(1) { @@ -221,8 +225,9 @@ impl<'c> Counts<'c> { } } if let Some(multi) = count.lang.multi_start() { - if before.contains(multi) && - !before.contains(count.lang.multi_end().unwrap()) { + if before.contains(multi) + && !before.contains(count.lang.multi_end().unwrap()) + { should_count = false; } } @@ -234,10 +239,12 @@ impl<'c> Counts<'c> { debugln!("after_usafe={:?}", after); bracket_count = Counts::count_brackets(after, None); is_in_unsafe = bracket_count > 0; - debugln!("after counting brackets; is_in_unsafe={:?}; \ + debugln!( + "after counting brackets; is_in_unsafe={:?}; \ bracket_count={:?}", - is_in_unsafe, - bracket_count); + is_in_unsafe, + bracket_count + ); } } } else { @@ -269,12 +276,16 @@ impl<'c> Counts<'c> { pub fn write_results(&mut self) -> CliResult<()> { let mut w = TabWriter::new(vec![]); - cli_try!(write!(w, - "\tLanguage\tFiles\tLines\tBlanks\tComments\tCode{}\n", - if self.cfg.usafe { "\tUnsafe (%)" } else { "" })); - cli_try!(write!(w, - "\t--------\t-----\t-----\t------\t--------\t----{}\n", - if self.cfg.usafe { "\t----------" } else { "" })); + cli_try!(write!( + w, + "\tLanguage\tFiles\tLines\tBlanks\tComments\tCode{}\n", + if self.cfg.usafe { "\tUnsafe (%)" } else { "" } + )); + cli_try!(write!( + w, + "\t--------\t-----\t-----\t------\t--------\t----{}\n", + if self.cfg.usafe { "\t----------" } else { "" } + )); for count in &self.counts { if self.cfg.usafe { let usafe_per = if count.code != 0 { @@ -282,53 +293,67 @@ impl<'c> Counts<'c> { } else { 0f64 }; - cli_try!(write!(w, - "\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n", - count.lang.name(), - count.total_files(), - count.lines(), - count.blanks(), - count.comments(), - count.code(), - if (usafe_per - 00f64).abs() < f64::EPSILON { - "".to_owned() - } else { - format!("{} ({:.2}%)", count.usafe(), usafe_per) - })); + cli_try!(write!( + w, + "\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n", + count.lang.name(), + count.total_files(), + count.lines(), + count.blanks(), + count.comments(), + count.code(), + if (usafe_per - 00f64).abs() < f64::EPSILON { + "".to_owned() + } else { + format!("{} ({:.2}%)", count.usafe(), usafe_per) + } + )); } else { cli_try!(write!(w, "\t{}\n", count)); } } - cli_try!(write!(w, - "\t--------\t-----\t-----\t------\t--------\t----{}\n", - if self.cfg.usafe { "\t----------" } else { "" })); - cli_try!(write!(w, - "{}\t\t{}\t{}\t{}\t{}\t{}{}\n", - "Totals:", - fmt::format_number(self.tot as u64, self.cfg.thousands), - fmt::format_number(self.tot_lines, self.cfg.thousands), - fmt::format_number(self.tot_blanks, self.cfg.thousands), - fmt::format_number(self.tot_comments, self.cfg.thousands), - fmt::format_number(self.tot_code, self.cfg.thousands), - if self.cfg.usafe { - format!("\t{} ({:.2}%)", - fmt::format_number(self.tot_usafe, self.cfg.thousands), - (self.tot_usafe as f64 / self.tot_code as f64) * 100.00f64) - } else { - "".to_owned() - })); + cli_try!(write!( + w, + "\t--------\t-----\t-----\t------\t--------\t----{}\n", + if self.cfg.usafe { "\t----------" } else { "" } + )); + cli_try!(write!( + w, + "{}\t\t{}\t{}\t{}\t{}\t{}{}\n", + "Totals:", + fmt::format_number(self.tot as u64, self.cfg.thousands), + fmt::format_number(self.tot_lines, self.cfg.thousands), + fmt::format_number(self.tot_blanks, self.cfg.thousands), + fmt::format_number(self.tot_comments, self.cfg.thousands), + fmt::format_number(self.tot_code, self.cfg.thousands), + if self.cfg.usafe { + format!( + "\t{} ({:.2}%)", + fmt::format_number(self.tot_usafe, self.cfg.thousands), + (self.tot_usafe as f64 / self.tot_code as f64) * 100.00f64 + ) + } else { + "".to_owned() + } + )); cli_try!(w.flush()); - verboseln!(self.cfg, - "{} {}", - Format::Good("Displaying"), - "the results:"); + verboseln!( + self.cfg, + "{} {}", + Format::Good("Displaying"), + "the results:" + ); if self.tot > 0 { - write!(io::stdout(), - "{}", - String::from_utf8(w.unwrap()).ok().expect("failed to get valid UTF-8 String")) - .expect("failed to write output"); + write!( + io::stdout(), + "{}", + String::from_utf8(w.unwrap()) + .ok() + .expect("failed to get valid UTF-8 String") + ) + .expect("failed to write output"); } else { println!("\n\tNo source files were found matching the specified criteria"); } diff --git a/src/count/mod.rs b/src/count/mod.rs index d242043..e281cbf 100644 --- a/src/count/mod.rs +++ b/src/count/mod.rs @@ -1,9 +1,8 @@ mod counts; - +pub use self::counts::Counts; use fmt; use language::Language; -pub use self::counts::Counts; use std::fmt as StdFmt; use std::ops::Deref; @@ -73,13 +72,15 @@ impl Deref for Count { impl StdFmt::Display for Count { fn fmt(&self, f: &mut StdFmt::Formatter) -> StdFmt::Result { - write!(f, - "{}\t{}\t{}\t{}\t{}\t{}", - self.lang, - self.total_files(), - self.lines(), - self.blanks(), - self.comments(), - self.code()) + write!( + f, + "{}\t{}\t{}\t{}\t{}\t{}", + self.lang, + self.total_files(), + self.lines(), + self.blanks(), + self.comments(), + self.code() + ) } } diff --git a/src/error.rs b/src/error.rs index 40ab9e3..4664da8 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,8 +1,7 @@ - - -use fmt::Format;use std::error::Error; -use std::fmt::{Display, Formatter}; +use fmt::Format; +use std::error::Error; use std::fmt::Result as FmtResult; +use std::fmt::{Display, Formatter}; pub type CliResult = Result; @@ -51,7 +50,9 @@ impl Error for CliError { match *self { CliError::Generic(ref d) => &*d, CliError::UnknownExt(ref d) => &*d, - CliError::Unknown => "An unknown fatal error has occurred, please consider filing a bug-report!", + CliError::Unknown => { + "An unknown fatal error has occurred, please consider filing a bug-report!" + } } } diff --git a/src/fmt.rs b/src/fmt.rs index 3ba67a2..bd1d29c 100644 --- a/src/fmt.rs +++ b/src/fmt.rs @@ -1,9 +1,9 @@ - #[cfg(all(feature = "color", not(target_os = "windows")))] use ansi_term::ANSIString; #[cfg(all(feature = "color", not(target_os = "windows")))] -use ansi_term::Colour::{Green, Red, Yellow};use std::fmt; +use ansi_term::Colour::{Green, Red, Yellow}; +use std::fmt; #[allow(dead_code)] pub enum Format { diff --git a/src/fsutil.rs b/src/fsutil.rs index ce2a959..94877ed 100644 --- a/src/fsutil.rs +++ b/src/fsutil.rs @@ -1,19 +1,23 @@ - use gitignore::File; -use glob;use std::fs; +use glob; +use std::fs; use std::io::Result; use std::path::PathBuf; -pub fn get_all_files(v: &mut Vec, - path: &PathBuf, - exclude: &[PathBuf], - follow_links: bool, - gitignore: &Option) { - debugln!("executing; get_all_files; path={:?}; exclude={:?}; all={:?}", - path, - exclude, - all); +pub fn get_all_files( + v: &mut Vec, + path: &PathBuf, + exclude: &[PathBuf], + follow_links: bool, + gitignore: &Option, +) { + debugln!( + "executing; get_all_files; path={:?}; exclude={:?}; all={:?}", + path, + exclude, + all + ); if exclude.contains(path) { return; } @@ -33,19 +37,22 @@ pub fn get_all_files(v: &mut Vec, for entry in dir { let entry = entry.unwrap(); let file_path = entry.path(); - get_all_files(v, - &file_path.to_path_buf(), - exclude, - follow_links, - gitignore); + get_all_files( + v, + &file_path.to_path_buf(), + exclude, + follow_links, + gitignore, + ); } } else { debugln!("It's a file"); v.push(path.clone()); } } else { - for path_buf in glob::glob(path.to_str().unwrap_or("")) - .expect("failed to get files from glob") { + for path_buf in + glob::glob(path.to_str().unwrap_or("")).expect("failed to get files from glob") + { if let Ok(file_path) = path_buf { if let Ok(result) = get_metadata(&file_path, follow_links) { if result.is_dir() { @@ -54,11 +61,13 @@ pub fn get_all_files(v: &mut Vec, for entry in dir { let entry = entry.unwrap(); let file_path = entry.path(); - get_all_files(v, - &file_path.to_path_buf(), - exclude, - follow_links, - gitignore); + get_all_files( + v, + &file_path.to_path_buf(), + exclude, + follow_links, + gitignore, + ); } } else { debugln!("It's a file"); diff --git a/src/language.rs b/src/language.rs index bf37841..8892887 100644 --- a/src/language.rs +++ b/src/language.rs @@ -1,5 +1,3 @@ - - use comment::Comment; use std::fmt as StdFmt; @@ -47,8 +45,8 @@ impl Language { "pl" => Some(Language::Perl), "go" => Some(Language::Go), "agc" | "asm" | "a51" | "inc" | "nasm" | "s" | "ms" => Some(Language::Assembly), - "ps1" | "psd1" | "psm1" | "sh" | "bash" | "bats" | "cgi" | "command" | "fcgi" | - "ksh" | "sh.in" | "tmux" | "tool" | "zsh" | "tcsh" | "csh" | "fish" => { + "ps1" | "psd1" | "psm1" | "sh" | "bash" | "bats" | "cgi" | "command" | "fcgi" + | "ksh" | "sh.in" | "tmux" | "tool" | "zsh" | "tcsh" | "csh" | "fish" => { Some(Language::Shell) } "d" | "di" => Some(Language::D), @@ -84,8 +82,13 @@ impl Language { pub fn is_unsafe(&self) -> bool { match *self { - Language::C | Language::Cpp | Language::Hpp | Language::Header | Language::Rust | - Language::Assembly | Language::Nim => true, + Language::C + | Language::Cpp + | Language::Hpp + | Language::Header + | Language::Rust + | Language::Assembly + | Language::Nim => true, _ => false, } } @@ -104,28 +107,46 @@ impl StdFmt::Display for Language { } } - impl Comment for Language { type Rep = &'static str; fn single(&self) -> Option::Rep>> { match *self { - Language::C | Language::Cpp | Language::Hpp | Language::Header | Language::Css | - Language::Java | Language::JavaScript | Language::Rust | Language::Go | Language::D => { - Some(vec!["//"]) - } + Language::C + | Language::Cpp + | Language::Hpp + | Language::Header + | Language::Css + | Language::Java + | Language::JavaScript + | Language::Rust + | Language::Go + | Language::D => Some(vec!["//"]), Language::Php => Some(vec!["//", "#"]), Language::Xml | Language::Html => Some(vec![""), Language::Ruby => Some("=end"), Language::Python => Some("'''"), diff --git a/src/macros.rs b/src/macros.rs index b42efbd..428431f 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,10 +1,10 @@ macro_rules! cli_try { - ($t:expr) => ({ + ($t:expr) => {{ match $t { Ok(o) => o, - Err(e) => return Err(CliError::Generic(e.to_string().to_owned())) + Err(e) => return Err(CliError::Generic(e.to_string().to_owned())), } - }) + }}; } macro_rules! wlnerr( ($($arg:tt)*) => ({ @@ -53,13 +53,13 @@ macro_rules! debug { #[cfg(not(feature = "debug"))] macro_rules! debugln { - ($fmt:expr) => (); - ($fmt:expr, $($arg:tt)*) => (); + ($fmt:expr) => {}; + ($fmt:expr, $($arg:tt)*) => {}; } #[allow(unused_macros)] #[cfg(not(feature = "debug"))] macro_rules! debug { - ($fmt:expr) => (); - ($fmt:expr, $($arg:tt)*) => (); + ($fmt:expr) => {}; + ($fmt:expr, $($arg:tt)*) => {}; } diff --git a/src/main.rs b/src/main.rs index 39df45b..fd75834 100644 --- a/src/main.rs +++ b/src/main.rs @@ -169,23 +169,29 @@ #![cfg_attr(feature = "lints", allow(should_implement_trait))] #![cfg_attr(feature = "lints", allow(unstable_features))] #![cfg_attr(feature = "lints", deny(warnings))] -#![cfg_attr(not(any(feature = "nightly", feature = "unstable")), deny(unstable_features))] -#![deny(missing_docs, - missing_debug_implementations, - missing_copy_implementations, - trivial_casts, trivial_numeric_casts, - unsafe_code, - unused_import_braces, - unused_qualifications)] +#![cfg_attr( + not(any(feature = "nightly", feature = "unstable")), + deny(unstable_features) +)] +#![deny( + missing_docs, + missing_debug_implementations, + missing_copy_implementations, + trivial_casts, + trivial_numeric_casts, + unsafe_code, + unused_import_braces, + unused_qualifications +)] #[macro_use] extern crate clap; #[cfg(feature = "color")] extern crate ansi_term; -extern crate tabwriter; +extern crate gitignore; extern crate glob; extern crate regex; -extern crate gitignore; +extern crate tabwriter; #[cfg(feature = "debug")] use std::env; @@ -210,8 +216,10 @@ mod language; static UTF8_RULES: [&'static str; 3] = ["strict", "lossy", "ignore"]; fn main() { - debugln!("executing; cmd=cargo-count; args={:?}", - env::args().collect::>()); + debugln!( + "executing; cmd=cargo-count; args={:?}", + env::args().collect::>() + ); let m = App::new("cargo-count") .version(concat!("v", crate_version!())) // We have to lie about our binary name since this will be a third party @@ -265,18 +273,19 @@ the current directory you could do '--exclude */test.rs'.")) fn execute(cfg: Config) -> CliResult<()> { debugln!("executing; cmd=execute;"); verboseln!(cfg, "{}: {:?}", Format::Warning("Excluding"), cfg.exclude); - verbose!(cfg, - "{}", - if cfg.exts.is_some() { - format!("{} including files with extension: {}\n", - Format::Warning("Only"), - cfg.exts - .as_ref() - .unwrap() - .join(", ")) - } else { - "".to_owned() - }); + verbose!( + cfg, + "{}", + if cfg.exts.is_some() { + format!( + "{} including files with extension: {}\n", + Format::Warning("Only"), + cfg.exts.as_ref().unwrap().join(", ") + ) + } else { + "".to_owned() + } + ); debugln!("Checking for files or dirs to count from cli"); @@ -291,9 +300,9 @@ fn single_char(s: String) -> Result<(), String> { if s.len() == 1 { Ok(()) } else { - Err( - format!( + Err(format!( "the --separator argument option only accepts a single character but found '{}'", - Format::Warning(s))) + Format::Warning(s) + )) } }