Enable Javascript formatting by default
This removes the need for explicitly passing `--js` to `git cl format`
to format both JavaScript and TypeScript. It would reduce a significant
amount of mental overhead for formatting code in DevTools frontend,
which is primarily JS/TS.
Fixed: 1007347
Change-Id: Ia35c9af677d12ce9be72fe5fcdd6ceb6cb039c5f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2029371
Reviewed-by: Anthony Polito <apolito@google.com>
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
diff --git a/git_cl.py b/git_cl.py
index 543b915..a8fa6e3 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -5234,8 +5234,15 @@
parser.add_option(
'--js',
action='store_true',
+ default=None,
help='Format javascript code with clang-format. '
'Has no effect if --no-clang-format is set.')
+ parser.add_option(
+ '--no-js',
+ action='store_true',
+ default=False,
+ help='Disable JavaScript/TypeScript formatting code with clang-format. '
+ 'Has no effect if --no-clang-format is set.')
parser.add_option('--diff', action='store_true',
help='Print diff to stdout rather than modifying files.')
parser.add_option('--presubmit', action='store_true',
@@ -5246,6 +5253,10 @@
raise parser.error('Cannot set both --python and --no-python')
if opts.no_python:
opts.python = False
+ if opts.js is not None and opts.no_js:
+ raise parser.error('Cannot set both --js and --no-js')
+ if opts.no_js:
+ opts.js = False
# Normalize any remaining args against the current path, so paths relative to
# the current directory are still resolved as expected.
@@ -5278,7 +5289,8 @@
# Filter out files deleted by this CL
diff_files = [x for x in diff_files if os.path.isfile(x)]
- if opts.js:
+ js_explicitly_disabled = opts.js is not None and not opts.js
+ if not js_explicitly_disabled:
CLANG_EXTS.extend(['.js', '.ts'])
clang_diff_files = []