diff --git a/git_cl.py b/git_cl.py index 543b915a78..a8fa6e3933 100755 --- a/git_cl.py +++ b/git_cl.py @@ -5234,8 +5234,15 @@ def CMDformat(parser, args): 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 @@ def CMDformat(parser, args): 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 @@ def CMDformat(parser, args): # 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 = []