Add initial support for custom sniffing

This commit is contained in:
Michael Wolf
2023-09-30 15:33:25 -06:00
parent 3034cd23e8
commit ce634e496c
3 changed files with 77 additions and 0 deletions

View File

@@ -68,6 +68,21 @@ function resolve_symlink() {
echo "$out"
}
function custom_sniff() {
file="$1"
pr=$(project_root "$file")
if [[ -f "$pr/.would-reformat/custom-sniffer" ]]; then
custom=$("$pr/.would-reformat/custom-sniffer" "$1")
ret="$?"
echo "$custom"
return 0
fi
}
function custom_formatter() {
root="$1"
file_type="$2"
@@ -88,6 +103,12 @@ function sniff_file_type() {
ff=$1
shift
maybe_custom=$(custom_sniff "$ff")
if [[ "$maybe_custom" != "" ]]; then
echo "$maybe_custom"
return 0
fi
file_type=
if [[ $ff == *.py ]]; then
@@ -118,6 +139,8 @@ function sniff_file_type() {
file_type="golang"
elif [[ $ff = *.dart ]]; then
file_type="dart"
elif [[ $ff = *.pl ]]; then
file_type="perl"
fi
echo $file_type