tridactyl/scripts/common.sh

58 lines
1.7 KiB
Bash
Raw Normal View History

2018-08-24 13:38:05 -06:00
#!/usr/bin/env bash
# Accepts no arguments
# Returns git-add'ed files as a list of filenames separated by a newline character
cachedTSLintFiles() {
2019-05-31 15:24:31 +01:00
git diff --cached --name-only --diff-filter=ACM "*.js" "*.jsx" "*.ts" "*.tsx" ":(exclude)*.d.ts" ":(exclude)tests/*" ":(exclude)*test.ts"
}
# Accepts no arguments
# Returns git-add'ed files as a list of filenames separated by a newline character
cachedPrettierFiles() {
git diff --cached --name-only --diff-filter=ACM "*.md" "*.css"
}
# Accepts a single argument which is the name of a file tracked by git
# Returns a string which is the content of the file as stored in the git index
staged() {
git show :"$1"
}
# Accepts a single string argument made of multiple file names separated by a newline
# Returns an array of files that prettier wants to lint
prettierUgly() {
local acc=""
local IFS=$'\n'
for jsfile in $1; do
2019-05-31 16:48:53 +01:00
diff <(staged "$jsfile") <(staged "$jsfile" | "$(yarn bin)/prettier" --stdin-filepath "$jsfile") >/dev/null || acc="$jsfile"$'\n'"$acc"
done
echo "$acc"
}
2020-06-16 20:50:12 +02:00
eslintUgly() {
local acc=""
local IFS=$'\n'
2019-05-29 21:09:58 +01:00
local tmpdir
2020-06-17 18:00:24 +01:00
mkdir -p .tmp
tmpdir=$(mktemp --tmpdir=".tmp/" -d "tslint.XXXXXXXXX")
for jsfile in "$@"; do
tmpfile="$tmpdir/$jsfile"
mkdir -p "$(dirname "$tmpfile")"
staged "$jsfile" > "$tmpfile"
2020-06-17 18:00:24 +01:00
"$(yarn bin)/eslint" --no-ignore --quiet -o /dev/null "$tmpfile" || acc="$jsfile"$'\n'"$acc"
done
rm -rf "$tmpdir"
echo "$acc"
}
noisy() {
local acc=()
for jsfile in "$@"; do
if [ "$(git diff --cached "$jsfile" | grep '^+.*console.log' -c)" -gt '0' ] ; then
acc+=("jsfile")
fi
done
2019-05-29 21:09:58 +01:00
echo "${acc[@]}"
}