mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-21 16:41:01 -05:00
commit
03fa6f8b8a
4 changed files with 193 additions and 244 deletions
|
@ -32,274 +32,162 @@ echo "\`\`\`bash" >> $report_path
|
|||
echo "$ $0 $base_dir $machine" >> $report_path
|
||||
echo "\`\`\`" >> $report_path
|
||||
echo "" >> $report_path
|
||||
|
||||
linux_clean_path=`$current_dir/fixtures/linux_clean.sh path $base_dir`
|
||||
linux_clean_version=`$current_dir/fixtures/linux_clean.sh version $base_dir`
|
||||
|
||||
linux_built_path=`$current_dir/fixtures/linux_built.sh path $base_dir`
|
||||
linux_built_version=`$current_dir/fixtures/linux_built.sh version $base_dir`
|
||||
|
||||
ripgrep_clean_path=`$current_dir/fixtures/ripgrep_clean.sh path $base_dir`
|
||||
ripgrep_clean_version=`$current_dir/fixtures/ripgrep_clean.sh version $base_dir`
|
||||
|
||||
ripgrep_built_path=`$current_dir/fixtures/ripgrep_built.sh path $base_dir`
|
||||
ripgrep_built_version=`$current_dir/fixtures/ripgrep_built.sh version $base_dir`
|
||||
|
||||
subtitles_en_path=`$current_dir/fixtures/subtitles_en.sh path $base_dir`
|
||||
subtitles_en_version=`$current_dir/fixtures/subtitles_en.sh version $base_dir`
|
||||
|
||||
subtitles_en_small_path=`$current_dir/fixtures/subtitles_en_small.sh path $base_dir`
|
||||
subtitles_en_small_version=`$current_dir/fixtures/subtitles_en_small.sh version $base_dir`
|
||||
|
||||
subtitles_ru_path=`$current_dir/fixtures/subtitles_ru.sh path $base_dir`
|
||||
subtitles_ru_version=`$current_dir/fixtures/subtitles_ru.sh version $base_dir`
|
||||
|
||||
subtitles_ru_small_path=`$current_dir/fixtures/subtitles_ru_small.sh path $base_dir`
|
||||
subtitles_ru_small_version=`$current_dir/fixtures/subtitles_ru_small.sh version $base_dir`
|
||||
echo "" >> $report_path
|
||||
|
||||
function print_tool() {
|
||||
local name=$1
|
||||
local version=$2
|
||||
local path=$3
|
||||
local output=$4
|
||||
if [[ -z $path ]]; then
|
||||
>&2 echo "Warning: $name uut is unavailable"
|
||||
echo "- $name: N/A" >> $output
|
||||
else
|
||||
echo "- $version" >> $output
|
||||
fi
|
||||
}
|
||||
|
||||
echo "Spell checkers:" >> $report_path
|
||||
rg_path=`$current_dir/uut/rg.sh path $base_dir`
|
||||
rg_version=`$current_dir/uut/rg.sh version $base_dir`
|
||||
if [[ -z $rg_path ]]; then
|
||||
>&2 echo "Warning: rg uut is unavailable"
|
||||
echo "- rg: N/A" >> $report_path
|
||||
else
|
||||
echo "- $rg_version" >> $report_path
|
||||
fi
|
||||
print_tool "rg" "$rg_version" "$rg_path" "$report_path"
|
||||
echo " - Though not a spell checker, present to be a theoretical lower bound" >> $report_path
|
||||
|
||||
typos_path=`$current_dir/uut/typos.sh path $base_dir`
|
||||
typos_version=`$current_dir/uut/typos.sh version $base_dir`
|
||||
if [[ -z $typos_path ]]; then
|
||||
>&2 echo "Warning: typos uut is unavailable"
|
||||
echo "- typos: N/A" >> $report_path
|
||||
else
|
||||
echo "- $typos_version" >> $report_path
|
||||
fi
|
||||
print_tool "typos" "$typos_version" "$typos_path" "$report_path"
|
||||
|
||||
misspell_rs_path=`$current_dir/uut/misspell_rs.sh path $base_dir`
|
||||
misspell_rs_version=`$current_dir/uut/misspell_rs.sh version $base_dir`
|
||||
if [[ -z $misspell_rs_path ]]; then
|
||||
>&2 echo "Warning: misspell_rs uut is unavailable"
|
||||
echo "- misspell_rs: N/A" >> $report_path
|
||||
else
|
||||
echo "- $misspell_rs_version" >> $report_path
|
||||
fi
|
||||
print_tool "misspell_rs" "$misspell_rs_version" "$misspell_rs_path" "$report_path"
|
||||
|
||||
misspell_go_path=`$current_dir/uut/misspell_go.sh path $base_dir`
|
||||
misspell_go_version=`$current_dir/uut/misspell_go.sh version $base_dir`
|
||||
if [[ -z $misspell_go_path ]]; then
|
||||
>&2 echo "Warning: misspell_go uut is unavailable"
|
||||
echo "- misspell_go: N/A" >> $report_path
|
||||
else
|
||||
echo "- $misspell_go_version" >> $report_path
|
||||
fi
|
||||
print_tool "misspell_go" "$misspell_go_version" "$misspell_go_path" "$report_path"
|
||||
|
||||
codespell_path=`$current_dir/uut/codespell.sh path $base_dir`
|
||||
codespell_version=`$current_dir/uut/codespell.sh version $base_dir`
|
||||
if [[ -z $codespell_path ]]; then
|
||||
>&2 echo "Warning: codespell uut is unavailable"
|
||||
echo "- codespell: N/A" >> $report_path
|
||||
else
|
||||
echo "- $codespell_version" >> $report_path
|
||||
fi
|
||||
print_tool "codespell" "$codespell_version" "$codespell_path" "$report_path"
|
||||
|
||||
scspell_path=`$current_dir/uut/scspell.sh path $base_dir`
|
||||
scspell_version=`$current_dir/uut/scspell.sh version $base_dir`
|
||||
if [[ -z $scspell_path ]]; then
|
||||
>&2 echo "Warning: scspell uut is unavailable"
|
||||
echo "- scspell: N/A" >> $report_path
|
||||
else
|
||||
echo "- $scspell_version" >> $report_path
|
||||
fi
|
||||
print_tool "scspell" "$scspell_version" "$scspell_path" "$report_path"
|
||||
|
||||
echo "" >> $report_path
|
||||
|
||||
function bench_dir() {
|
||||
local name=$1
|
||||
local version=$2
|
||||
local path=$3
|
||||
local output=$4
|
||||
|
||||
echo "## linux_clean fixture" >> $report_path
|
||||
echo "" >> $report_path
|
||||
if [[ -z $linux_clean_path ]]; then
|
||||
>&2 echo "Warning: linux_clean fixture is unavailable"
|
||||
echo "N/A" >> $report_path
|
||||
else
|
||||
echo "linux_clean: $linux_clean_version" >> $report_path
|
||||
echo "" >> $report_path
|
||||
rg_command=""
|
||||
if [[ ! -z $rg_path ]]; then
|
||||
rg_command="$rg_path bin $linux_clean_path"
|
||||
echo "## $name fixture" >> $output
|
||||
echo "" >> $output
|
||||
if [[ -z $path ]]; then
|
||||
>&2 echo "Warning: $name fixture is unavailable"
|
||||
echo "N/A" >> $output
|
||||
else
|
||||
echo "$name: $version" >> $output
|
||||
echo "" >> $output
|
||||
rg_command=""
|
||||
if [[ ! -z $rg_path ]]; then
|
||||
rg_command="$rg_path bin $path"
|
||||
fi
|
||||
typos_command=""
|
||||
if [[ ! -z $typos_path ]]; then
|
||||
typos_command="$typos_path $path"
|
||||
fi
|
||||
misspell_rs_command=""
|
||||
if [[ ! -z $misspell_rs_path ]]; then
|
||||
misspell_rs_command="$misspell_rs_path $path"
|
||||
fi
|
||||
misspell_go_command=""
|
||||
if [[ ! -z $misspell_go_path ]]; then
|
||||
misspell_go_command="$misspell_go_path $path"
|
||||
fi
|
||||
# Skipping scspell, doesn't work on directories
|
||||
codespell_command=""
|
||||
if [[ ! -z $codespell_path ]]; then
|
||||
codespell_command="$codespell_path $path"
|
||||
fi
|
||||
hyperfine --warmup 1 -i --export-json $report_prefix-rg.json --export-markdown $report_prefix-rg.md "$rg_command" "$typos_command" "$misspell_rs_command" "$misspell_go_command" "$codespell_command"
|
||||
cat $report_prefix-rg.md >> $output
|
||||
fi
|
||||
typos_command=""
|
||||
if [[ ! -z $typos_path ]]; then
|
||||
typos_command="$typos_path $linux_clean_path"
|
||||
fi
|
||||
misspell_rs_command=""
|
||||
if [[ ! -z $misspell_rs_path ]]; then
|
||||
misspell_rs_command="$misspell_rs_path $linux_clean_path"
|
||||
fi
|
||||
misspell_go_command=""
|
||||
if [[ ! -z $misspell_go_path ]]; then
|
||||
misspell_go_command="$misspell_go_path $linux_clean_path"
|
||||
fi
|
||||
# Skipping scspell, doesn't work on directories
|
||||
codespell_command=""
|
||||
if [[ ! -z $codespell_path ]]; then
|
||||
codespell_command="$codespell_path $linux_clean_path"
|
||||
fi
|
||||
hyperfine --warmup 1 -i --export-json $report_prefix-rg.json --export-markdown $report_prefix-rg.md "$rg_command" "$typos_command" "$misspell_rs_command" "$misspell_go_command" "$codespell_command"
|
||||
cat $report_prefix-rg.md >> $report_path
|
||||
fi
|
||||
echo "" >> $report_path
|
||||
echo "" >> $output
|
||||
}
|
||||
|
||||
function bench_file() {
|
||||
local name=$1
|
||||
local version=$2
|
||||
local path=$3
|
||||
local output=$4
|
||||
|
||||
echo "## linux_built fixture" >> $report_path
|
||||
echo "" >> $report_path
|
||||
if [[ -z $linux_built_path ]]; then
|
||||
>&2 echo "Warning: linux_built fixture is unavailable"
|
||||
echo "N/A" >> $report_path
|
||||
else
|
||||
echo "linux_built: $linux_built_version" >> $report_path
|
||||
echo "" >> $report_path
|
||||
rg_command=""
|
||||
if [[ ! -z $rg_path ]]; then
|
||||
rg_command="$rg_path bin $linux_built_path"
|
||||
echo "## $name fixture" >> $output
|
||||
echo "" >> $output
|
||||
if [[ -z $path ]]; then
|
||||
>&2 echo "Warning: $name fixture is unavailable"
|
||||
echo "N/A" >> $output
|
||||
else
|
||||
echo "$name: $version" >> $output
|
||||
echo "" >> $output
|
||||
rg_command=""
|
||||
if [[ ! -z $rg_path ]]; then
|
||||
rg_command="$rg_path bin $path"
|
||||
fi
|
||||
typos_command=""
|
||||
if [[ ! -z $typos_path ]]; then
|
||||
typos_command="$typos_path $path"
|
||||
fi
|
||||
misspell_rs_command=""
|
||||
if [[ ! -z $misspell_rs_path ]]; then
|
||||
misspell_rs_command="$misspell_rs_path $path"
|
||||
fi
|
||||
misspell_go_command=""
|
||||
if [[ ! -z $misspell_go_path ]]; then
|
||||
misspell_go_command="$misspell_go_path $path"
|
||||
fi
|
||||
scspell_command=""
|
||||
if [[ ! -z $scspell_path ]]; then
|
||||
scspell_command="$scspell_path $subtitles_ru_small_path"
|
||||
fi
|
||||
codespell_command=""
|
||||
if [[ ! -z $codespell_path ]]; then
|
||||
codespell_command="$codespell_path $path"
|
||||
fi
|
||||
hyperfine --warmup 1 -i --export-json $report_prefix-rg.json --export-markdown $report_prefix-rg.md "$rg_command" "$typos_command" "$misspell_rs_command" "$misspell_go_command" "$scspell_command" "$codespell_command"
|
||||
cat $report_prefix-rg.md >> $output
|
||||
fi
|
||||
typos_command=""
|
||||
if [[ ! -z $typos_path ]]; then
|
||||
typos_command="$typos_path $linux_built_path"
|
||||
fi
|
||||
misspell_rs_command=""
|
||||
if [[ ! -z $misspell_rs_path ]]; then
|
||||
misspell_rs_command="$misspell_rs_path $linux_built_path"
|
||||
fi
|
||||
misspell_go_command=""
|
||||
if [[ ! -z $misspell_go_path ]]; then
|
||||
misspell_go_command="$misspell_go_path $linux_built_path"
|
||||
fi
|
||||
# Skipping scspell, doesn't work on directories
|
||||
codespell_command=""
|
||||
if [[ ! -z $codespell_path ]]; then
|
||||
codespell_command="$codespell_path $linux_built_path"
|
||||
fi
|
||||
hyperfine --warmup 1 -i --export-json $report_prefix-rg.json --export-markdown $report_prefix-rg.md "$rg_command" "$typos_command" "$misspell_rs_command" "$misspell_go_command" "$codespell_command"
|
||||
cat $report_prefix-rg.md >> $report_path
|
||||
fi
|
||||
echo "" >> $report_path
|
||||
echo "" >> $output
|
||||
}
|
||||
|
||||
linux_clean_path=`$current_dir/fixtures/linux_clean.sh path $base_dir`
|
||||
linux_clean_version=`$current_dir/fixtures/linux_clean.sh version $base_dir`
|
||||
bench_dir "linux_clean" "$linux_clean_version" "$linux_clean_path" "$report_path"
|
||||
|
||||
if [[ -z $subtitles_en_path ]]; then
|
||||
>&2 echo "Warning: subtitles_en fixture is unavailable"
|
||||
fi
|
||||
linux_built_path=`$current_dir/fixtures/linux_built.sh path $base_dir`
|
||||
linux_built_version=`$current_dir/fixtures/linux_built.sh version $base_dir`
|
||||
bench_dir "linux_built" "$linux_built_version" "$linux_built_path" "$report_path"
|
||||
|
||||
ripgrep_clean_path=`$current_dir/fixtures/ripgrep_clean.sh path $base_dir`
|
||||
ripgrep_clean_version=`$current_dir/fixtures/ripgrep_clean.sh version $base_dir`
|
||||
bench_dir "ripgrep_clean" "$ripgrep_clean_version" "$ripgrep_clean_path" "$report_path"
|
||||
|
||||
if [[ -z $subtitles_en_small_path ]]; then
|
||||
>&2 echo "Warning: subtitles_en_small fixture is unavailable"
|
||||
fi
|
||||
ripgrep_built_path=`$current_dir/fixtures/ripgrep_built.sh path $base_dir`
|
||||
ripgrep_built_version=`$current_dir/fixtures/ripgrep_built.sh version $base_dir`
|
||||
bench_dir "ripgrep_built" "$ripgrep_built_version" "$ripgrep_built_path" "$report_path"
|
||||
|
||||
# subtitles_en_path=`$current_dir/fixtures/subtitles_en.sh path $base_dir`
|
||||
# subtitles_en_version=`$current_dir/fixtures/subtitles_en.sh version $base_dir`
|
||||
# bench_file "subtitles_en" "$subtitles_en_version" "$subtitles_en_path" "$report_path"
|
||||
|
||||
echo "## subtitles_ru_small fixture" >> $report_path
|
||||
echo "" >> $report_path
|
||||
if [[ -z $subtitles_ru_small_path ]]; then
|
||||
>&2 echo "Warning: subtitles_ru_small fixture is unavailable"
|
||||
echo "N/A" >> $report_path
|
||||
else
|
||||
echo "subtitles_ru_small: $subtitles_ru_small_version" >> $report_path
|
||||
echo "" >> $report_path
|
||||
rg_command=""
|
||||
if [[ ! -z $rg_path ]]; then
|
||||
rg_command="$rg_path bin $subtitles_ru_small_path"
|
||||
fi
|
||||
typos_command=""
|
||||
if [[ ! -z $typos_path ]]; then
|
||||
typos_command="$typos_path $subtitles_ru_small_path"
|
||||
fi
|
||||
misspell_rs_command=""
|
||||
if [[ ! -z $misspell_rs_path ]]; then
|
||||
misspell_rs_command="$misspell_rs_path $subtitles_ru_small_path"
|
||||
fi
|
||||
misspell_go_command=""
|
||||
if [[ ! -z $misspell_go_path ]]; then
|
||||
misspell_go_command="$misspell_go_path $subtitles_ru_small_path"
|
||||
fi
|
||||
scspell_command=""
|
||||
if [[ ! -z $scspell_path ]]; then
|
||||
scspell_command="$scspell_path $subtitles_ru_small_path"
|
||||
fi
|
||||
codespell_command=""
|
||||
if [[ ! -z $codespell_path ]]; then
|
||||
codespell_command="$codespell_path $subtitles_ru_small_path"
|
||||
fi
|
||||
hyperfine --warmup 1 -i --export-json $report_prefix-rg.json --export-markdown $report_prefix-rg.md "$rg_command" "$typos_command" "$misspell_rs_command" "$misspell_go_command" "$scspell_command" "$codespell_command"
|
||||
cat $report_prefix-rg.md >> $report_path
|
||||
fi
|
||||
echo "" >> $report_path
|
||||
# subtitles_en_small_path=`$current_dir/fixtures/subtitles_en_small.sh path $base_dir`
|
||||
# subtitles_en_small_version=`$current_dir/fixtures/subtitles_en_small.sh version $base_dir`
|
||||
# bench_file "subtitles_en_small" "$subtitles_en_small_version" "$subtitles_en_small_path" "$report_path"
|
||||
|
||||
subtitles_ru_path=`$current_dir/fixtures/subtitles_ru.sh path $base_dir`
|
||||
subtitles_ru_version=`$current_dir/fixtures/subtitles_ru.sh version $base_dir`
|
||||
bench_file "subtitles_ru" "$subtitles_ru_version" "$subtitles_ru_path" "$report_path"
|
||||
|
||||
echo "## ripgrep_clean fixture" >> $report_path
|
||||
echo "" >> $report_path
|
||||
if [[ -z $ripgrep_clean_path ]]; then
|
||||
>&2 echo "Warning: ripgrep_clean fixture is unavailable"
|
||||
echo "N/A" >> $report_path
|
||||
else
|
||||
echo "ripgrep_clean: $ripgrep_clean_version" >> $report_path
|
||||
echo "" >> $report_path
|
||||
rg_command=""
|
||||
if [[ ! -z $rg_path ]]; then
|
||||
rg_command="$rg_path bin $ripgrep_clean_path"
|
||||
fi
|
||||
typos_command=""
|
||||
if [[ ! -z $typos_path ]]; then
|
||||
typos_command="$typos_path $ripgrep_clean_path"
|
||||
fi
|
||||
misspell_rs_command=""
|
||||
if [[ ! -z $misspell_rs_path ]]; then
|
||||
misspell_rs_command="$misspell_rs_path $ripgrep_clean_path"
|
||||
fi
|
||||
misspell_go_command=""
|
||||
if [[ ! -z $misspell_go_path ]]; then
|
||||
misspell_go_command="$misspell_go_path $ripgrep_clean_path"
|
||||
fi
|
||||
# Skipping scspell, doesn't work on directories
|
||||
codespell_command=""
|
||||
if [[ ! -z $codespell_path ]]; then
|
||||
codespell_command="$codespell_path $ripgrep_clean_path"
|
||||
fi
|
||||
hyperfine --warmup 1 -i --export-json $report_prefix-rg.json --export-markdown $report_prefix-rg.md "$rg_command" "$typos_command" "$misspell_rs_command" "$misspell_go_command" "$codespell_command"
|
||||
cat $report_prefix-rg.md >> $report_path
|
||||
fi
|
||||
echo "" >> $report_path
|
||||
|
||||
|
||||
echo "## ripgrep_built fixture" >> $report_path
|
||||
echo "" >> $report_path
|
||||
if [[ -z $ripgrep_built_path ]]; then
|
||||
>&2 echo "Warning: ripgrep_built fixture is unavailable"
|
||||
echo "N/A" >> $report_path
|
||||
else
|
||||
echo "ripgrep_built: $ripgrep_built_version" >> $report_path
|
||||
echo "" >> $report_path
|
||||
rg_command=""
|
||||
if [[ ! -z $rg_path ]]; then
|
||||
rg_command="$rg_path bin $ripgrep_built_path"
|
||||
fi
|
||||
typos_command=""
|
||||
if [[ ! -z $typos_path ]]; then
|
||||
typos_command="$typos_path $ripgrep_built_path"
|
||||
fi
|
||||
misspell_rs_command=""
|
||||
if [[ ! -z $misspell_rs_path ]]; then
|
||||
misspell_rs_command="$misspell_rs_path $ripgrep_built_path"
|
||||
fi
|
||||
misspell_go_command=""
|
||||
if [[ ! -z $misspell_go_path ]]; then
|
||||
misspell_go_command="$misspell_go_path $ripgrep_built_path"
|
||||
fi
|
||||
# Skipping scspell, doesn't work on directories
|
||||
codespell_command=""
|
||||
if [[ ! -z $codespell_path ]]; then
|
||||
codespell_command="$codespell_path $ripgrep_built_path"
|
||||
fi
|
||||
hyperfine --warmup 1 -i --export-json $report_prefix-rg.json --export-markdown $report_prefix-rg.md "$rg_command" "$typos_command" "$misspell_rs_command" "$misspell_go_command" "$codespell_command"
|
||||
cat $report_prefix-rg.md >> $report_path
|
||||
fi
|
||||
echo "" >> $report_path
|
||||
subtitles_ru_small_path=`$current_dir/fixtures/subtitles_ru_small.sh path $base_dir`
|
||||
subtitles_ru_small_version=`$current_dir/fixtures/subtitles_ru_small.sh version $base_dir`
|
||||
bench_file "subtitles_ru_small" "$subtitles_ru_smal_version" "$subtitles_ru_smal_path" "$report_path"
|
||||
|
|
41
src/main.rs
41
src/main.rs
|
@ -266,6 +266,27 @@ pub fn init_logging(level: Option<log::Level>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_entry(
|
||||
entry: Result<ignore::DirEntry, ignore::Error>,
|
||||
args: &Args,
|
||||
checks: &typos::checks::Checks,
|
||||
) -> Result<bool, failure::Error> {
|
||||
let mut typos_found = false;
|
||||
|
||||
let entry = entry?;
|
||||
if entry.file_type().map(|t| t.is_file()).unwrap_or(true) {
|
||||
let explicit = entry.depth() == 0;
|
||||
if checks.check_filename(entry.path(), args.format.report())? {
|
||||
typos_found = true;
|
||||
}
|
||||
if checks.check_file(entry.path(), explicit, args.format.report())? {
|
||||
typos_found = true;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(typos_found)
|
||||
}
|
||||
|
||||
fn run() -> Result<i32, failure::Error> {
|
||||
let args = Args::from_args();
|
||||
|
||||
|
@ -279,6 +300,7 @@ fn run() -> Result<i32, failure::Error> {
|
|||
let config = config;
|
||||
|
||||
let mut typos_found = false;
|
||||
let mut errors_found = false;
|
||||
for path in args.path.iter() {
|
||||
let path = path.canonicalize()?;
|
||||
let cwd = if path.is_file() {
|
||||
|
@ -318,20 +340,21 @@ fn run() -> Result<i32, failure::Error> {
|
|||
.git_exclude(config.files.ignore_vcs())
|
||||
.parents(config.files.ignore_parent());
|
||||
for entry in walk.build() {
|
||||
let entry = entry?;
|
||||
if entry.file_type().map(|t| t.is_file()).unwrap_or(true) {
|
||||
let explicit = entry.depth() == 0;
|
||||
if checks.check_filename(entry.path(), args.format.report())? {
|
||||
typos_found = true;
|
||||
}
|
||||
if checks.check_file(entry.path(), explicit, args.format.report())? {
|
||||
typos_found = true;
|
||||
match check_entry(entry, &args, &checks) {
|
||||
Ok(true) => typos_found = true,
|
||||
Err(err) => {
|
||||
let msg = typos::report::Error::new(err.to_string());
|
||||
args.format.report()(msg.into());
|
||||
errors_found = true
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if typos_found {
|
||||
if errors_found {
|
||||
Ok(2)
|
||||
} else if typos_found {
|
||||
Ok(1)
|
||||
} else {
|
||||
Ok(0)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::borrow::Cow;
|
||||
|
||||
pub trait Dictionary {
|
||||
pub trait Dictionary: Send + Sync {
|
||||
fn correct_ident<'s, 'w>(
|
||||
&'s self,
|
||||
_ident: crate::tokens::Identifier<'w>,
|
||||
|
|
|
@ -8,6 +8,8 @@ pub enum Message<'m> {
|
|||
BinaryFile(BinaryFile<'m>),
|
||||
Correction(Correction<'m>),
|
||||
FilenameCorrection(FilenameCorrection<'m>),
|
||||
PathError(PathError<'m>),
|
||||
Error(Error),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize, derive_more::Display)]
|
||||
|
@ -40,6 +42,30 @@ pub struct FilenameCorrection<'m> {
|
|||
pub(crate) non_exhaustive: (),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize)]
|
||||
pub struct PathError<'m> {
|
||||
pub path: &'m std::path::Path,
|
||||
pub msg: String,
|
||||
#[serde(skip)]
|
||||
pub(crate) non_exhaustive: (),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize)]
|
||||
pub struct Error {
|
||||
pub msg: String,
|
||||
#[serde(skip)]
|
||||
pub(crate) non_exhaustive: (),
|
||||
}
|
||||
|
||||
impl Error {
|
||||
pub fn new(msg: String) -> Self {
|
||||
Self {
|
||||
msg,
|
||||
non_exhaustive: (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type Report = fn(msg: Message);
|
||||
|
||||
pub fn print_silent(_: Message) {}
|
||||
|
@ -62,6 +88,12 @@ pub fn print_brief(msg: Message) {
|
|||
Message::FilenameCorrection(msg) => {
|
||||
println!("{}: {} -> {}", msg.path.display(), msg.typo, msg.correction);
|
||||
}
|
||||
Message::PathError(msg) => {
|
||||
println!("{}: {}", msg.path.display(), msg.msg);
|
||||
}
|
||||
Message::Error(msg) => {
|
||||
println!("{}", msg.msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,6 +111,12 @@ pub fn print_long(msg: Message) {
|
|||
msg.correction
|
||||
);
|
||||
}
|
||||
Message::PathError(msg) => {
|
||||
println!("{}: {}", msg.path.display(), msg.msg);
|
||||
}
|
||||
Message::Error(msg) => {
|
||||
println!("{}", msg.msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue