From 4a4d1f96504fa825a4932ce58a80bb2e967b3fcb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Piotr=20Kosko/Native/Web=20API=20=28PLT=29=20/SRPOL/Profess?= =?utf8?q?ional/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Wed, 10 Apr 2019 11:00:29 +0200 Subject: [PATCH] [Project][Codeformat] Added prettier as partial formatter for JS [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 | 19 ++++++++++++++++++- tools/codestyle/prettier.config.js | 9 +++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tools/codestyle/prettier.config.js diff --git a/tools/codestyle/js_eslint_formatter.sh b/tools/codestyle/js_eslint_formatter.sh index ad78a439..e4e60677 100755 --- a/tools/codestyle/js_eslint_formatter.sh +++ b/tools/codestyle/js_eslint_formatter.sh @@ -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 index 00000000..8295f7dc --- /dev/null +++ b/tools/codestyle/prettier.config.js @@ -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 -- 2.34.1