mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-24 18:10:56 -05:00
feat: Control over output format
This commit is contained in:
parent
e59d7817b4
commit
2ddd7d93df
5 changed files with 156 additions and 66 deletions
109
Cargo.lock
generated
109
Cargo.lock
generated
|
@ -146,6 +146,11 @@ name = "difference"
|
|||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "encoding_rs"
|
||||
version = "0.8.14"
|
||||
|
@ -162,23 +167,6 @@ dependencies = [
|
|||
"encoding_rs 0.8.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.5.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "exitcode"
|
||||
version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "failure"
|
||||
version = "0.1.5"
|
||||
|
@ -277,14 +265,6 @@ dependencies = [
|
|||
"unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "humantime"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ignore"
|
||||
version = "0.4.6"
|
||||
|
@ -302,6 +282,19 @@ dependencies = [
|
|||
"winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.2.0"
|
||||
|
@ -454,11 +447,6 @@ dependencies = [
|
|||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-error"
|
||||
version = "1.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "0.6.11"
|
||||
|
@ -606,6 +594,11 @@ dependencies = [
|
|||
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "same-file"
|
||||
version = "1.0.4"
|
||||
|
@ -626,16 +619,17 @@ dependencies = [
|
|||
"assert_fs 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"csv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"exitcode 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"grep-searcher 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ignore 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"phf 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"phf_codegen 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"structopt 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -657,6 +651,26 @@ name = "serde"
|
|||
version = "1.0.85"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.85"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "0.2.3"
|
||||
|
@ -734,14 +748,6 @@ dependencies = [
|
|||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termion"
|
||||
version = "1.5.1"
|
||||
|
@ -853,15 +859,6 @@ name = "winapi-x86_64-pc-windows-gnu"
|
|||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "wincolor"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[metadata]
|
||||
"checksum aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1e9a933f4e58658d7b12defcf96dc5c720f20832deebe3e0a19efd3b6aaeeb9e"
|
||||
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||
|
@ -881,10 +878,9 @@ dependencies = [
|
|||
"checksum csv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "9fd1c44c58078cfbeaf11fbb3eac9ae5534c23004ed770cc4bfb48e658ae4f04"
|
||||
"checksum csv-core 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa5cdef62f37e6ffe7d1f07a381bc0db32b7a3ff1cac0de56cb0d81e71f53d65"
|
||||
"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
|
||||
"checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0"
|
||||
"checksum encoding_rs 0.8.14 (registry+https://github.com/rust-lang/crates.io-index)" = "a69d152eaa438a291636c1971b0a370212165ca8a75759eb66818c5ce9b538f7"
|
||||
"checksum encoding_rs_io 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "098f6a0ab73a9ba256b71344dc82c6d7e252736ad9db7f4e35345f3a1f8713f5"
|
||||
"checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38"
|
||||
"checksum exitcode 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "de853764b47027c2e862a995c34978ffa63c1501f2e15f987ba11bd4f9bba193"
|
||||
"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2"
|
||||
"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1"
|
||||
"checksum float-cmp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "134a8fa843d80a51a5b77d36d42bc2def9edcb0262c914861d08129fd1926600"
|
||||
|
@ -896,8 +892,9 @@ dependencies = [
|
|||
"checksum grep-matcher 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "820946e0c314510779a8d86c5cd03240e0ae0993dabcdb98733a8f6a9001b607"
|
||||
"checksum grep-searcher 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6eb23805170ff0e96894a24847019500de11e9baaabe3dafed75b35a897636e1"
|
||||
"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
|
||||
"checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114"
|
||||
"checksum ignore 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ad03ca67dc12474ecd91fdb94d758cbd20cb4e7a78ebe831df26a9b7511e1162"
|
||||
"checksum itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b8467d9c1cebe26feb08c640139247fac215782d35371ade9a2136ed6085358"
|
||||
"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
|
||||
"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1"
|
||||
"checksum libc 0.2.47 (registry+https://github.com/rust-lang/crates.io-index)" = "48450664a984b25d5b479554c29cc04e3150c97aa4c01da5604a2d4ed9151476"
|
||||
"checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c"
|
||||
|
@ -917,7 +914,6 @@ dependencies = [
|
|||
"checksum predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "06075c3a3e92559ff8929e7a280684489ea27fe44805174c3ebd9328dcb37178"
|
||||
"checksum predicates-tree 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8e63c4859013b38a76eca2414c64911fba30def9e3202ac461a2d22831220124"
|
||||
"checksum proc-macro2 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)" = "38fddd23d98b2144d197c0eca5705632d4fe2667d14a6be5df8934f8d74f1978"
|
||||
"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
|
||||
"checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1"
|
||||
"checksum rand 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3906503e80ac6cbcacb2c2973fa8e473f24d7e2747c8c92bb230c2441cad96b5"
|
||||
"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"
|
||||
|
@ -935,11 +931,14 @@ dependencies = [
|
|||
"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
|
||||
"checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619"
|
||||
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||
"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
|
||||
"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267"
|
||||
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
|
||||
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
||||
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
"checksum serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)" = "534b8b91a95e0f71bca3ed5824752d558da048d4248c91af873b63bd60519752"
|
||||
"checksum serde_derive 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)" = "a915306b0f1ac5607797697148c223bedeaa36bcc2e28a01441cd638cc6567b4"
|
||||
"checksum serde_json 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)" = "574378d957d6dcdf1bbb5d562a15cbd5e644159432f84634b94e485267abbcc7"
|
||||
"checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac"
|
||||
"checksum smallvec 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "88aea073965ab29f6edb5493faf96ad662fb18aa9eeb186a3b7057951605ed15"
|
||||
"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
|
||||
|
@ -949,7 +948,6 @@ dependencies = [
|
|||
"checksum syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)" = "f92e629aa1d9c827b2bb8297046c1ccffc57c99b947a680d3ccff1f136a3bee9"
|
||||
"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015"
|
||||
"checksum tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7e91405c14320e5c79b3d148e1c86f40749a36e490642202a31689cb1a3452b2"
|
||||
"checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f"
|
||||
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
|
||||
"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6"
|
||||
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
|
||||
|
@ -967,4 +965,3 @@ dependencies = [
|
|||
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
"checksum winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "afc5508759c5bf4285e61feb862b6083c8480aec864fa17a81fdec6f69b461ab"
|
||||
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
"checksum wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "561ed901ae465d6185fa7864d63fbd5720d0ef718366c9a4dc83cf6170d7e9ba"
|
||||
|
|
|
@ -18,11 +18,16 @@ appveyor = { repository = "epage/scorrect" }
|
|||
[dependencies]
|
||||
failure = "0.1"
|
||||
structopt = "0.2"
|
||||
clap = "2"
|
||||
ignore = "0.4"
|
||||
phf = "0.7"
|
||||
regex = "1.0"
|
||||
lazy_static = "1.2.0"
|
||||
grep-searcher = "0.1"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
serde_json = "1.0"
|
||||
itertools = "0.8"
|
||||
|
||||
[dev-dependencies]
|
||||
assert_fs = "0.10"
|
||||
|
|
|
@ -13,7 +13,7 @@ fn process_empty(b: &mut test::Bencher) {
|
|||
sample_path.write_str(data::EMPTY).unwrap();
|
||||
|
||||
let corrections = scorrect::Corrections::new();
|
||||
b.iter(|| scorrect::process_file(sample_path.path(), &corrections));
|
||||
b.iter(|| scorrect::process_file(sample_path.path(), &corrections, scorrect::print_silent));
|
||||
|
||||
temp.close().unwrap();
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ fn process_no_tokens(b: &mut test::Bencher) {
|
|||
sample_path.write_str(data::NO_TOKENS).unwrap();
|
||||
|
||||
let corrections = scorrect::Corrections::new();
|
||||
b.iter(|| scorrect::process_file(sample_path.path(), &corrections));
|
||||
b.iter(|| scorrect::process_file(sample_path.path(), &corrections, scorrect::print_silent));
|
||||
|
||||
temp.close().unwrap();
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ fn process_single_token(b: &mut test::Bencher) {
|
|||
sample_path.write_str(data::SINGLE_TOKEN).unwrap();
|
||||
|
||||
let corrections = scorrect::Corrections::new();
|
||||
b.iter(|| scorrect::process_file(sample_path.path(), &corrections));
|
||||
b.iter(|| scorrect::process_file(sample_path.path(), &corrections, scorrect::print_silent));
|
||||
|
||||
temp.close().unwrap();
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ fn process_sherlock(b: &mut test::Bencher) {
|
|||
sample_path.write_str(data::SHERLOCK).unwrap();
|
||||
|
||||
let corrections = scorrect::Corrections::new();
|
||||
b.iter(|| scorrect::process_file(sample_path.path(), &corrections));
|
||||
b.iter(|| scorrect::process_file(sample_path.path(), &corrections, scorrect::print_silent));
|
||||
|
||||
temp.close().unwrap();
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ fn process_code(b: &mut test::Bencher) {
|
|||
sample_path.write_str(data::CODE).unwrap();
|
||||
|
||||
let corrections = scorrect::Corrections::new();
|
||||
b.iter(|| scorrect::process_file(sample_path.path(), &corrections));
|
||||
b.iter(|| scorrect::process_file(sample_path.path(), &corrections, scorrect::print_silent));
|
||||
|
||||
temp.close().unwrap();
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ fn process_corpus(b: &mut test::Bencher) {
|
|||
sample_path.write_str(data::CORPUS).unwrap();
|
||||
|
||||
let corrections = scorrect::Corrections::new();
|
||||
b.iter(|| scorrect::process_file(sample_path.path(), &corrections));
|
||||
b.iter(|| scorrect::process_file(sample_path.path(), &corrections, scorrect::print_silent));
|
||||
|
||||
temp.close().unwrap();
|
||||
}
|
||||
|
|
57
src/lib.rs
57
src/lib.rs
|
@ -1,8 +1,12 @@
|
|||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/codegen.rs"));
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Token<'t> {
|
||||
pub token: &'t [u8],
|
||||
pub offset: usize,
|
||||
|
@ -20,7 +24,18 @@ pub fn tokenize(content: &[u8]) -> impl Iterator<Item=Token> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn process_file(path: &std::path::Path, dictionary: &Corrections) -> Result<(), failure::Error> {
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct Message<'m> {
|
||||
path: &'m std::path::Path,
|
||||
#[serde(skip)]
|
||||
line: &'m [u8],
|
||||
line_num: usize,
|
||||
col_num: usize,
|
||||
word: &'m str,
|
||||
correction: &'m str,
|
||||
}
|
||||
|
||||
pub fn process_file(path: &std::path::Path, dictionary: &Corrections, report: Report) -> Result<(), failure::Error> {
|
||||
let mut buffer = Vec::new();
|
||||
File::open(path)?.read_to_end(&mut buffer)?;
|
||||
for (line_idx, line) in grep_searcher::LineIter::new(b'\n', &buffer).enumerate() {
|
||||
|
@ -28,8 +43,16 @@ pub fn process_file(path: &std::path::Path, dictionary: &Corrections) -> Result<
|
|||
for token in tokenize(line) {
|
||||
if let Some(word) = std::str::from_utf8(token.token).ok() {
|
||||
if let Some(correction) = dictionary.correct_str(word) {
|
||||
let column = token.offset;
|
||||
println!("{}:{}:{}: {} -> {}", path.display(), line_num, column, word, correction);
|
||||
let col_num = token.offset;
|
||||
let msg = Message {
|
||||
path,
|
||||
line,
|
||||
line_num,
|
||||
col_num,
|
||||
word,
|
||||
correction,
|
||||
};
|
||||
report(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +61,34 @@ pub fn process_file(path: &std::path::Path, dictionary: &Corrections) -> Result<
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub type Report = fn(msg: Message);
|
||||
|
||||
pub fn print_silent(_: Message) {
|
||||
}
|
||||
|
||||
pub fn print_brief(msg: Message) {
|
||||
println!("{}:{}:{}: {} -> {}", msg.path.display(), msg.line_num, msg.col_num, msg.word, msg.correction);
|
||||
}
|
||||
|
||||
pub fn print_long(msg: Message) {
|
||||
let line_num = msg.line_num.to_string();
|
||||
let line_indent: String = itertools::repeat_n(" ", line_num.len()).collect();
|
||||
|
||||
let hl_indent: String = itertools::repeat_n(" ", msg.col_num).collect();
|
||||
let hl: String = itertools::repeat_n("^", msg.word.len()).collect();
|
||||
|
||||
println!("error: `{}` should be `{}`", msg.word, msg.correction);
|
||||
println!(" --> {}:{}:{}", msg.path.display(), msg.line_num, msg.col_num);
|
||||
println!("{} |", line_indent);
|
||||
println!("{} | {}", msg.line_num, String::from_utf8_lossy(msg.line).trim_end());
|
||||
println!("{} | {}{}", line_indent, hl_indent, hl);
|
||||
println!("{} |", line_indent);
|
||||
}
|
||||
|
||||
pub fn print_json(msg: Message) {
|
||||
println!("{}", serde_json::to_string(&msg).unwrap());
|
||||
}
|
||||
|
||||
pub struct Corrections {
|
||||
}
|
||||
|
||||
|
|
39
src/main.rs
39
src/main.rs
|
@ -1,11 +1,48 @@
|
|||
// 2015-edition macros.
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
|
||||
use structopt::StructOpt;
|
||||
|
||||
arg_enum!{
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
enum Format {
|
||||
Silent,
|
||||
Brief,
|
||||
Long,
|
||||
Json,
|
||||
}
|
||||
}
|
||||
|
||||
impl Format {
|
||||
fn report(self) -> scorrect::Report {
|
||||
match self {
|
||||
Format::Silent => scorrect::print_silent,
|
||||
Format::Brief => scorrect::print_brief,
|
||||
Format::Long => scorrect::print_long,
|
||||
Format::Json => scorrect::print_json,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Format {
|
||||
fn default() -> Self {
|
||||
Format::Long
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
struct Options {
|
||||
#[structopt(parse(from_os_str))]
|
||||
/// Paths to check
|
||||
path: Vec<std::path::PathBuf>,
|
||||
|
||||
|
||||
#[structopt(long = "format",
|
||||
raw(possible_values = "&Format::variants()", case_insensitive = "true"),
|
||||
default_value = "long")]
|
||||
pub format: Format,
|
||||
|
||||
#[structopt(short="j", long="threads", default_value="0")]
|
||||
/// The approximate number of threads to use.
|
||||
threads: usize,
|
||||
|
@ -38,7 +75,7 @@ fn run() -> Result<(), failure::Error> {
|
|||
for entry in walk.build() {
|
||||
let entry = entry?;
|
||||
if entry.file_type().map(|t| t.is_file()).unwrap_or(true) {
|
||||
scorrect::process_file(entry.path(), &dictionary)?;
|
||||
scorrect::process_file(entry.path(), &dictionary, options.format.report())?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue