Put git cl format JS formatting behind a flag.

This CL moves JS formatting behind the --js flag for git cl format
due to issue with LayoutTests. It also adds an option to check
javascript for the presubmit canned formatting check.

BUG=567770

Change-Id: I9c080b1136f6ffef9fb1b08d3bfc97ce5b3185dc
Reviewed-on: https://chromium-review.googlesource.com/430526
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
Commit-Queue: Christopher Lam <calamity@chromium.org>
diff --git a/git_cl.py b/git_cl.py
index 4ca54e2..04a9130 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -5212,7 +5212,7 @@
 @subcommand.usage('[files or directories to diff]')
 def CMDformat(parser, args):
   """Runs auto-formatting tools (clang-format etc.) on the diff."""
-  CLANG_EXTS = ['.cc', '.cpp', '.h', '.m', '.mm', '.proto', '.java', '.js']
+  CLANG_EXTS = ['.cc', '.cpp', '.h', '.m', '.mm', '.proto', '.java']
   GN_EXTS = ['.gn', '.gni', '.typemap']
   parser.add_option('--full', action='store_true',
                     help='Reformat the full content of all touched files')
@@ -5220,6 +5220,8 @@
                     help='Don\'t modify any file on disk.')
   parser.add_option('--python', action='store_true',
                     help='Format python code with yapf (experimental).')
+  parser.add_option('--js', action='store_true',
+                    help='Format javascript code with clang-format.')
   parser.add_option('--diff', action='store_true',
                     help='Print diff to stdout rather than modifying files.')
   opts, args = parser.parse_args(args)
@@ -5255,6 +5257,9 @@
   # Filter out files deleted by this CL
   diff_files = [x for x in diff_files if os.path.isfile(x)]
 
+  if opts.js:
+    CLANG_EXTS.append('.js')
+
   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'])]