format-code: enable prettier

prettier is a formatter for YAML, JSON, Markdown, etc.

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I7a47d02ef7382d811423b97a88132aa92b991eed
diff --git a/scripts/build-unit-test-docker b/scripts/build-unit-test-docker
index fff4b25..1de8f8b 100755
--- a/scripts/build-unit-test-docker
+++ b/scripts/build-unit-test-docker
@@ -817,8 +817,6 @@
     rsync \
     libcryptsetup-dev
 
-RUN npm install -g eslint@latest eslint-plugin-json@latest
-
 # Kinetic comes with GCC-12, so skip this.
 #RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 12 \
 #  --slave /usr/bin/g++ g++ /usr/bin/g++-12 \
@@ -855,6 +853,10 @@
 RUN pip3 install meson==0.63.0
 RUN pip3 install protobuf
 RUN pip3 install requests
+
+RUN npm install -g \
+        eslint@latest eslint-plugin-json@latest \
+        prettier@latest
 """
 
 # Build the base and stage docker images.
diff --git a/scripts/format-code.sh b/scripts/format-code.sh
index b0f56f3..77e8df0 100755
--- a/scripts/format-code.sh
+++ b/scripts/format-code.sh
@@ -30,6 +30,7 @@
         clang_format \
         eslint \
         flake8 \
+        prettier \
         shellcheck \
     )
 LINTERS_DISABLED=()
@@ -176,6 +177,13 @@
     # disagree on best practices.
 }
 
+LINTER_REQUIRE+=([prettier]="prettier;.prettierrc.yaml;${CONFIG_PATH}/prettierrc.yaml")
+LINTER_IGNORE+=([prettier]=".prettierignore")
+LINTER_TYPES+=([prettier]="json;markdown;yaml")
+function do_prettier() {
+    prettier --config "${LINTER_CONFIG[prettier]}" --write "$@"
+}
+
 LINTER_REQUIRE+=([shellcheck]="shellcheck")
 LINTER_IGNORE+=([shellcheck]=".shellcheck-ignore")
 LINTER_TYPES+=([shellcheck]="bash;sh")