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>
changes/71/2029371/6
Tim van der Lippe 6 years ago committed by LUCI CQ
parent 4d67872733
commit 42a51f6af1

@ -5234,8 +5234,15 @@ def CMDformat(parser, args):
parser.add_option( parser.add_option(
'--js', '--js',
action='store_true', action='store_true',
default=None,
help='Format javascript code with clang-format. ' help='Format javascript code with clang-format. '
'Has no effect if --no-clang-format is set.') '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', parser.add_option('--diff', action='store_true',
help='Print diff to stdout rather than modifying files.') help='Print diff to stdout rather than modifying files.')
parser.add_option('--presubmit', action='store_true', parser.add_option('--presubmit', action='store_true',
@ -5246,6 +5253,10 @@ def CMDformat(parser, args):
raise parser.error('Cannot set both --python and --no-python') raise parser.error('Cannot set both --python and --no-python')
if opts.no_python: if opts.no_python:
opts.python = False 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 # Normalize any remaining args against the current path, so paths relative to
# the current directory are still resolved as expected. # the current directory are still resolved as expected.
@ -5278,7 +5289,8 @@ def CMDformat(parser, args):
# Filter out files deleted by this CL # Filter out files deleted by this CL
diff_files = [x for x in diff_files if os.path.isfile(x)] 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_EXTS.extend(['.js', '.ts'])
clang_diff_files = [] clang_diff_files = []

Loading…
Cancel
Save