diff --git a/git_cl.py b/git_cl.py index 7f8741782..fe0c00f2c 100755 --- a/git_cl.py +++ b/git_cl.py @@ -5132,6 +5132,12 @@ def CMDformat(parser, args): help='Reformat the full content of all touched files') parser.add_option('--dry-run', action='store_true', help='Don\'t modify any file on disk.') + parser.add_option( + '--no-clang-format', + dest='clang_format', + action='store_false', + default=True, + help='Disables formatting of various file types using clang-format.') parser.add_option( '--python', action='store_true', @@ -5145,8 +5151,11 @@ def CMDformat(parser, args): 'If neither --python or --no-python are set, python files that have a ' '.style.yapf file in an ancestor directory will be formatted. ' 'It is an error to set both.') - parser.add_option('--js', action='store_true', - help='Format javascript code with clang-format.') + parser.add_option( + '--js', + action='store_true', + help='Format javascript 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', @@ -5192,7 +5201,11 @@ def CMDformat(parser, args): if opts.js: CLANG_EXTS.extend(['.js', '.ts']) - clang_diff_files = [x for x in diff_files if MatchingFileType(x, CLANG_EXTS)] + clang_diff_files = [] + if opts.clang_format: + clang_diff_files = [ + x for x in diff_files if MatchingFileType(x, CLANG_EXTS) + ] python_diff_files = [x for x in diff_files if MatchingFileType(x, ['.py'])] dart_diff_files = [x for x in diff_files if MatchingFileType(x, ['.dart'])] gn_diff_files = [x for x in diff_files if MatchingFileType(x, GN_EXTS)] diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 76cab04c8..13e77fe43 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -1214,6 +1214,7 @@ def PanProjectChecks(input_api, output_api, def CheckPatchFormatted(input_api, output_api, bypass_warnings=True, + check_clang_format=True, check_js=False, check_python=None, result_factory=None): @@ -1221,6 +1222,9 @@ def CheckPatchFormatted(input_api, import git_cl display_args = [] + if not check_clang_format: + display_args.append('--no-clang-format') + if check_js: display_args.append('--js')