JSON validation support in CI
Most of the openbmc repositories depend on JSON configuration files,
which are consumed by the respective daemons at runtime.
It's a good value add to catch the JSON validation errors early in the
repository CI itself.
By default, the CI would be picking config/eslint-global-config as the
default configuration to run the JSON validation. The default configuration
can be overridden by the presence of the .eslintrc.json file from the
repository for which the CI is running against.
Repositories cannot completely opt-out of the JSON validation, but they
choose to skip whatever files/folders they want using the .eslintignore
configuration file or, they can also write the rules in .eslintrc.json
config file to turn errors into warnings.
This commit brings in eslint & eslint-plugin-json which does only the
"json validation".
Visit the below link(s) for more details & various error's/warnings that
this plugin would report:
https://www.npmjs.com/package/eslint-plugin-json
https://github.com/azeemba/eslint-plugin-json
I have tested all the repos under openbmc with the eslint-global-config
and only two repos are breaking due to this change, they are already
fixed(please check the topic: "json-validation" for more details)
Testing Example :
1. Make a json bad by purposefully removing a comma
Running the json validator on the repo using it's config >
/home/manojeda/ci_test_area/pldm/configurations/fru_master.json
19:26 error Expected comma json/*
✖ 1 problem (1 error, 0 warnings)
2. if the json is good, the validation proceeds fruther without
any issues.
Change-Id: I2c2c14b18bb626b1a5ab5d818b92d5ba370e1639
Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
diff --git a/scripts/format-code.sh b/scripts/format-code.sh
index e1bdaa9..47cb0f7 100755
--- a/scripts/format-code.sh
+++ b/scripts/format-code.sh
@@ -10,6 +10,7 @@
# Input parmameter must be full path to git repo to scan
DIR=$1
+WORKSPACE=$PWD
set -e
@@ -27,6 +28,29 @@
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"
+fi
+
+# Print eslint command
+echo "$eslint_command"
+# Run eslint
+$eslint_command
+
if [[ -f "setup.cfg" ]]; then
pycodestyle --show-source --exclude=subprojects .
rc=$?