From ed183fb95fcbb5cf7a4ded5fdfa24a40e1368d1f Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 14 Jul 2020 14:34:29 -0700 Subject: [PATCH] lint: Use Prettier for JavaScript files. Signed-off-by: Anders Kaseorg --- .prettierignore | 1 + prettier.config.js | 16 ++++++++++++++++ tools/lint | 5 +++-- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 .prettierignore diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000000..59c243b8b0 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +/static/third diff --git a/prettier.config.js b/prettier.config.js index 5f9d8da169..1a98a2c0e5 100644 --- a/prettier.config.js +++ b/prettier.config.js @@ -1,3 +1,19 @@ module.exports = { bracketSpacing: false, + tabWidth: 4, + trailingComma: "all", + overrides: [ + { + files: ["frontend_tests/casper_tests/*.js", "frontend_tests/casper_lib/*.js"], + options: { + trailingComma: "es5", + }, + }, + { + files: ["**.yml", "**.yaml"], + options: { + tabWidth: 2, + }, + }, + ], }; diff --git a/tools/lint b/tools/lint index 7d7753cd2a..a537c0abd5 100755 --- a/tools/lint +++ b/tools/lint @@ -93,9 +93,10 @@ def run() -> None: linter_config.external_linter('isort', ['isort'], ['py'], description="Sorts Python import statements", check_arg=['--check-only', '--diff']) - linter_config.external_linter('prettier', ['node_modules/.bin/prettier'], ['yaml', 'yml'], + linter_config.external_linter('prettier', ['node_modules/.bin/prettier'], + ['js', 'ts', 'yaml', 'yml'], check_arg=['--check'], fix_arg=['--write'], - description="Formats YAML files", + description="Formats JavaScript and YAML", # https://github.com/prettier/prettier/pull/8703 suppress_line=lambda line: line in ["Checking formatting...\n", "All matched files use Prettier code style!\n"])