mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-24 18:10:56 -05:00
parent
5b6b5bd9e2
commit
81f20bb293
3 changed files with 23 additions and 9 deletions
|
@ -47,6 +47,7 @@ Whitelist: A confidence rating is given for how close a word is to one in the wh
|
|||
| Ignores hidden | Yes | Yes | ? | Yes | No |
|
||||
| Respect gitignore | Yes | Yes | ? | No | No |
|
||||
| Checks filenames | Yes | No | ? | Yes | No |
|
||||
| Status via exit code | Yes | No | Yes | Yes | Yes |
|
||||
| API | Rust / [JSON Lines] | Rust | ? | Python | None |
|
||||
| License | MIT or Apache | AGPL | MIT | GPLv2 | GPLv2 |
|
||||
|
||||
|
|
12
src/lib.rs
12
src/lib.rs
|
@ -22,7 +22,9 @@ pub fn process_file(
|
|||
ignore_hex: bool,
|
||||
binary: bool,
|
||||
report: report::Report,
|
||||
) -> Result<(), failure::Error> {
|
||||
) -> Result<bool, failure::Error> {
|
||||
let mut typos_found = false;
|
||||
|
||||
if check_filenames {
|
||||
for part in path.components().filter_map(|c| c.as_os_str().to_str()) {
|
||||
for ident in tokens::Identifier::parse(part) {
|
||||
|
@ -37,6 +39,7 @@ pub fn process_file(
|
|||
non_exhaustive: (),
|
||||
};
|
||||
report(msg.into());
|
||||
typos_found = true;
|
||||
}
|
||||
for word in ident.split() {
|
||||
if let Some(correction) = dictionary.correct_word(word) {
|
||||
|
@ -47,6 +50,7 @@ pub fn process_file(
|
|||
non_exhaustive: (),
|
||||
};
|
||||
report(msg.into());
|
||||
typos_found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +66,7 @@ pub fn process_file(
|
|||
non_exhaustive: (),
|
||||
};
|
||||
report(msg.into());
|
||||
return Ok(());
|
||||
return Ok(typos_found);
|
||||
}
|
||||
|
||||
for (line_idx, line) in buffer.lines().enumerate() {
|
||||
|
@ -82,6 +86,7 @@ pub fn process_file(
|
|||
correction,
|
||||
non_exhaustive: (),
|
||||
};
|
||||
typos_found = true;
|
||||
report(msg.into());
|
||||
}
|
||||
for word in ident.split() {
|
||||
|
@ -96,6 +101,7 @@ pub fn process_file(
|
|||
correction,
|
||||
non_exhaustive: (),
|
||||
};
|
||||
typos_found = true;
|
||||
report(msg.into());
|
||||
}
|
||||
}
|
||||
|
@ -103,7 +109,7 @@ pub fn process_file(
|
|||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
Ok(typos_found)
|
||||
}
|
||||
|
||||
fn is_hex(ident: &str) -> bool {
|
||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -249,7 +249,7 @@ pub fn get_logging(level: log::Level) -> env_logger::Builder {
|
|||
builder
|
||||
}
|
||||
|
||||
fn run() -> Result<(), failure::Error> {
|
||||
fn run() -> Result<i32, failure::Error> {
|
||||
let options = Options::from_args().infer();
|
||||
|
||||
let mut builder = get_logging(options.verbose.log_level());
|
||||
|
@ -275,11 +275,11 @@ fn run() -> Result<(), failure::Error> {
|
|||
.git_ignore(options.ignore_vcs().unwrap_or(true))
|
||||
.git_exclude(options.ignore_vcs().unwrap_or(true))
|
||||
.parents(options.ignore_parent().unwrap_or(true));
|
||||
// TODO Add build_parallel for options.threads != 1
|
||||
let mut typos_found = false;
|
||||
for entry in walk.build() {
|
||||
let entry = entry?;
|
||||
if entry.file_type().map(|t| t.is_file()).unwrap_or(true) {
|
||||
typos::process_file(
|
||||
if typos::process_file(
|
||||
entry.path(),
|
||||
&dictionary,
|
||||
check_filenames,
|
||||
|
@ -287,13 +287,20 @@ fn run() -> Result<(), failure::Error> {
|
|||
ignore_hex,
|
||||
binary,
|
||||
options.format.report(),
|
||||
)?;
|
||||
)? {
|
||||
typos_found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
if typos_found {
|
||||
Ok(1)
|
||||
} else {
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
run().unwrap();
|
||||
let code = run().unwrap();
|
||||
std::process::exit(code);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue