From: Piotr Kosko/Native/Web API (PLT) /SRPOL/Professional/삼성전자 Date: Wed, 10 Apr 2019 09:00:29 +0000 (+0200) Subject: [Project][Codeformat] Added prettier as partial formatter for JS X-Git-Tag: submit/tizen/20190510.110853~5^2^2^2~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4a4d1f96504fa825a4932ce58a80bb2e967b3fcb;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [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 --- 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