Last active
December 8, 2021 07:07
-
-
Save wtnabe/a954065be1defa3861f723cb7440c3cc to your computer and use it in GitHub Desktop.
ESLintの設定でうっかり新しい記法が許されていた場合に警告する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
target_version=2017 | |
main () { | |
config_file=$1 | |
if [ -z "$config_version" ]; then | |
cat <<EOD | |
eslint config file not specified | |
ex) ./limit-ecma-version.sh .eslintrc.js | |
EOD | |
else | |
echo "start checking with " $config_file | |
do_check $config_file | |
fi | |
} | |
do_check () { | |
config_file=$1 | |
yarn run -s eslint --print-config $config_file | jq .env | awk -v target_version=$target_version '{ | |
if (match($0, /es([0-9]+)/) && /true/) { | |
version = substr($0, RSTART + 2, RLENGTH - 2) | |
if (version + 0 > target_version) { | |
print "CAUTION ! this config may break not-most-modern browsers." | |
exit 1 | |
} | |
} | |
} | |
' | |
} | |
main $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment