Let eslint use .gitignore file
There is a well documented issue when using eslint with a folder that
already has subprojects checked out. A quick perusing of the eslint
documentation shows that the eslintignore files happily accept a
.gitignore file as its input. Considering there might be repos that
already have put a .eslintignore file in place, rely on that if it
exists, if it doesn't, fall back to .gitignore if it exists.
While here, this exposed another issue that we were missing the
--format=json command, and there were cases where eslint would make a
mistake.
Tested:
Ran on bmcweb repo with subprojects checked out. Observed build
succeeded.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Iafab1d4d9e80a093a13b4c5a758a1f68bc37138c
diff --git a/scripts/format-code.sh b/scripts/format-code.sh
index 152a5b2..0609d9f 100755
--- a/scripts/format-code.sh
+++ b/scripts/format-code.sh
@@ -28,28 +28,30 @@
echo "Formatting code under $DIR/"
-ESLINT_CONFIG="eslint ${DIR} --no-eslintrc -c ${WORKSPACE}/eslint-global-config.json \
- --ext .json --resolve-plugins-relative-to /usr/local/lib/node_modules\
- --no-error-on-unmatched-pattern"
-ESLINT_IGNORE=" --ignore-path ${DIR}/.eslintignore"
-
-# Get the eslint configuration from the repository
-if [[ -f ".eslintrc.json" ]] || [[ -f ".eslintignore" ]]; then
- echo "Running the json validator on the repo using it's config > "
- if [[ ! -f ".eslintrc.json" ]]; then
- eslint_command="${ESLINT_CONFIG} ${ESLINT_IGNORE}"
- else
- eslint_command="$ESLINT_CONFIG"
- fi
-else
- echo "Running the json validator on the repo using the global config > "
- eslint_command="$ESLINT_CONFIG"
+if [[ -f ".eslintignore" ]]; then
+ ESLINT_IGNORE="--ignore-path .eslintignore"
+elif [[ -f ".gitignore" ]]; then
+ ESLINT_IGNORE="--ignore-path .gitignore"
fi
+# Get the eslint configuration from the repository
+if [[ -f ".eslintrc.json" ]]; then
+ echo "Running the json validator on the repo using it's config > "
+ ESLINT_RC="-c .eslintrc.json"
+else
+ echo "Running the json validator on the repo using the global config"
+ ESLINT_RC="--no-eslintrc -c ${WORKSPACE}/eslint-global-config.json"
+fi
+
+ESLINT_COMMAND="eslint . ${ESLINT_IGNORE} ${ESLINT_RC} \
+ --ext .json --format=json \
+ --resolve-plugins-relative-to /usr/local/lib/node_modules \
+ --no-error-on-unmatched-pattern"
+
# Print eslint command
-echo "$eslint_command"
+echo "$ESLINT_COMMAND"
# Run eslint
-$eslint_command
+$ESLINT_COMMAND
if [[ -f "setup.cfg" ]]; then
pycodestyle --show-source --exclude=subprojects .