[Project][Codeformat] Added prettier as partial formatter for JS 79/203179/2
authorPiotr Kosko/Native/Web API (PLT) /SRPOL/Professional/삼성전자 <p.kosko@samsung.com>
Wed, 10 Apr 2019 09:00:29 +0000 (11:00 +0200)
committerPiotr Kosko/Native/Web API (PLT) /SRPOL/Professional/삼성전자 <p.kosko@samsung.com>
Wed, 10 Apr 2019 10:21:29 +0000 (12:21 +0200)
[Feature] Existing solution check the format using eslint and fix
some issues with predefined rules (which match the requirements
of review.tizen.org CodingRule_Auto bot rules.
However the tool checks the validity, it does not provide auto
formating of too long lines issues.
To ensure such feature, the new tool was introduced and executed before
eslint validation.
Thanks to prettier, the line breaks are unified and handled the same
way in whole project.

Change-Id: I077036521307ef28fda5388ecab01b8d850ad3e3

tools/codestyle/js_eslint_formatter.sh
tools/codestyle/prettier.config.js [new file with mode: 0644]

index ad78a4394944fde378ad09b9f322484420d61529..e4e6067737899af176f1f2f519a6835628d7ab9f 100755 (executable)
@@ -12,18 +12,35 @@ command -v eslint >/dev/null 2>&1 || {
   exit 1;
 }
 
+#https://prettier.io/docs/en/install.html
+command -v prettier >/dev/null 2>&1 || {
+
+  echo >&2 "prettier is required, but it's not installed";
+  echo "-------------------------------------------------------------------------------------";
+  echo "To install prettier on Debian/Ubuntu, execute the following commands."
+  echo "sudo npm install -g prettier"
+  echo "-------------------------------------------------------------------------------------";
+  exit 1;
+}
+
 script_path="$( cd "$(dirname "$0")" ; pwd -P )";
 config_file="$script_path/eslintrc_mandatory_4spaces.js"
+prettier_config_file="$script_path/prettier.config.js"
 
 formatJSDirectory() {
   ls $1/*.js &>/dev/null
   if [[ $? -eq 0 ]]; then
-    formatJSFile $1;
+    for f in $(ls $1/*.js)
+    do
+      formatJSFile $f;
+    done
   fi
 }
 
 formatJSFile() {
   printf "."
+  # fixing line breaks using prettier
+  prettier --config "$prettier_config_file" "$1" --write
   # using eslint for fixing some js issues
   eslint --no-eslintrc -c "$config_file" $1 --fix
   # issues that are not fixed, will be printed fur the user to take care of them
diff --git a/tools/codestyle/prettier.config.js b/tools/codestyle/prettier.config.js
new file mode 100644 (file)
index 0000000..8295f7d
--- /dev/null
@@ -0,0 +1,9 @@
+// prettier.config.js or .prettierrc.js
+module.exports = {
+    trailingComma: 'none',
+    tabWidth: 4,
+    semi: false,
+    singleQuote: true,
+    printWidth: 90,
+    semi: true
+};
\ No newline at end of file