1313`git cl presubmit -v -v` to debug presubmit checks.
1414"""
1515
16+ import re
1617import sys
1718import six
1819import time
2728 r'^front_end[\\/]core[\\/]common[\\/]Color\.ts$' , # Apple copyright
2829 r'^front_end[\\/]core[\\/]common[\\/]Object\.ts$' , # Apple copyright
2930 r'^front_end[\\/]core[\\/]common[\\/]ResourceType\.ts$' , # Apple copyright
30- r'^front_end[\\/]core[\\/]dom_extension[\\/]DOMExtension\.ts$' , # Apple copyright
31+ # Apple copyright
32+ r'^front_end[\\/]core[\\/]dom_extension[\\/]DOMExtension\.ts$' ,
3133 r'^front_end[\\/]core[\\/]platform[\\/]UIString\.ts$' , # Apple copyright
3234 r'^front_end[\\/]core[\\/]sdk[\\/]Resource\.ts$' , # Apple copyright
3335 r'^front_end[\\/]core[\\/]sdk[\\/]Script\.ts$' , # Apple copyright
34- r'^front_end[\\/]ui[\\/]legacy[\\/]components[\\/]data_grid[\\/]DataGrid\.ts$' , # Apple copyright
36+ r'^front_end[\\/]third_party[\\/].*' , # 3rd party code
37+ # Apple copyright
38+ r'^front_end[\\/]ui[\\/]legacy[\\/]components[\\/]data_grid[\\/]DataGrid\.ts$' ,
39+ r'^node_modules[\\/].*' , # 3rd party code
3540 r'^scripts[\\/]build[\\/]build_inspector_overlay\.py$' , # Lines too long
3641 r'^scripts[\\/]build[\\/]code_generator_frontend\.py$' ,
3742 r'^scripts[\\/]deps[\\/]manage_node_deps\.py$' , # Lines too long
43+ r'front_end[\\/]generated[\\/]ARIAProperties\.ts$' # Auto-generated files
44+ # Auto-generated files
45+ r'front_end[\\/]generated[\\/]InspectorBackendCommands\.ts$'
3846]
3947
48+
4049def _ExecuteSubProcess (input_api ,
4150 output_api ,
4251 script_path ,
@@ -246,13 +255,7 @@ def CheckDevToolsLint(input_api, output_api):
246255 ]
247256
248257 lint_related_directories = [
249- input_api .os_path .join (input_api .PresubmitLocalPath (), 'node_modules' ,
250- 'eslint' ),
251- input_api .os_path .join (input_api .PresubmitLocalPath (), 'node_modules' ,
252- 'stylelint' ),
253- input_api .os_path .join (input_api .PresubmitLocalPath (), 'node_modules' ,
254- '@typescript-eslint' ),
255- input_api .os_path .join (scripts_directory , 'eslint_rules' ),
258+ input_api .os_path .join (input_api .PresubmitLocalPath (), 'node_modules' ),
256259 ]
257260
258261 lint_config_files = _GetAffectedFiles (
@@ -400,9 +403,38 @@ def CheckNodeModules(input_api, output_api):
400403 if not Path (file_path ).is_file ():
401404 results .extend ([
402405 output_api .PresubmitError (
403- "node_modules/%s is missing. Use npm run install-deps to re-create it."
406+ "node_modules/%s is missing. Use ` npm run install-deps` to re-create it."
404407 % file )
405408 ])
409+
410+ node_module_files = _GetAffectedFiles (input_api , [
411+ input_api .os_path .join (input_api .PresubmitLocalPath (), 'node_modules' )
412+ ], [], [])
413+
414+ # If the changes are above 100 assume that touching the node_modules
415+ # was intentional
416+ if len (node_module_files ) == 0 or len (node_module_files ) > 100 :
417+ return results
418+
419+ message = (
420+ "Changes to `node_modules` detected.\n " +
421+ "This is third party code and should not be modified.\n " +
422+ "`node_module` are mainly used in testing infra\n " +
423+ "For bug fixes and features usually you should not need this change.\n "
424+ + "Was this change intentional?" )
425+ results .extend ([
426+ output_api .PresubmitPromptWarning (
427+ message ,
428+ locations = [
429+ output_api .PresubmitResultLocation (
430+ # Location expects relative path
431+ # But _GetAffectedFiles returns us absolute path
432+ input_api .os_path .relpath (
433+ node_module_files [0 ],
434+ input_api .PresubmitLocalPath ()), ),
435+ ])
436+ ])
437+
406438 return results
407439
408440
@@ -416,7 +448,7 @@ def CheckNoUncheckedFiles(input_api, output_api):
416448 out , _ = process .communicate ()
417449 if process .returncode != 0 :
418450 files_changed_process = input_api .subprocess .Popen (
419- ['git' , 'diff' , '--name-only' ],
451+ ['git' , 'diff' ],
420452 stdout = input_api .subprocess .PIPE ,
421453 stderr = input_api .subprocess .STDOUT )
422454 files_changed , _ = files_changed_process .communicate ()
@@ -430,6 +462,50 @@ def CheckNoUncheckedFiles(input_api, output_api):
430462 return []
431463
432464
465+ def CheckKnownContextValues (input_api , output_api ):
466+ """Ensure all additions to `KnownContextValues.ts` following the naming convention.
467+
468+ This check ensures that all new cases added to the enum in `KnownContextValues.ts`
469+ follow the extended Kebab Case naming convention. Specifically it doesn't look at
470+ unchanged lines, because there are various existing values that cannot be changed
471+ (easily).
472+ """
473+ # This regexp matches the one we use in `StringUtilities.isExtendedKebabCase()`.
474+ kebab_case_re = re .compile (
475+ r"^([a-z0-9]+(?:-[a-z0-9]+)*\.)*[a-z0-9]+(?:-[a-z0-9]+)*$" )
476+ local_path = input_api .os_path .join ('front_end' , 'ui' , 'visual_logging' ,
477+ 'KnownContextValues.ts' )
478+ invalid_contexts = []
479+ for f in filter (
480+ lambda x : (x .LocalPath () == local_path and x .Action () == 'M' ),
481+ input_api .AffectedFiles ()):
482+ # Loop only through the changed lines of the affected file.
483+ for _ , line in f .ChangedContents ():
484+ match = re .search (r"\s+'(.+)'," , line )
485+ if match :
486+ context = match .group (1 )
487+ if not kebab_case_re .match (context ):
488+ invalid_contexts .append (context )
489+ continue
490+
491+ if not invalid_contexts :
492+ return []
493+ return [
494+ output_api .PresubmitError (
495+ message = f"Invalid jslog context(s): { ', ' .join (invalid_contexts )} " ,
496+ long_text =
497+ ("""The jslog contexts must follow the extended Kebab Case naming convention, where
498+ words are separated with either a dash (`-`) or a dot (`.`), and all characters
499+ must be lower-case alphanumeric.
500+ """ ),
501+ locations = [
502+ output_api .PresubmitResultLocation (file_path = local_path )
503+ ],
504+ )
505+ ]
506+
507+
508+
433509# Canned check wrappers below.
434510
435511
@@ -466,7 +542,6 @@ def CheckGenderNeutral(input_api, output_api):
466542 return input_api .canned_checks .CheckGenderNeutral (input_api , output_api )
467543
468544
469-
470545def CheckAuthorizedAuthor (input_api , output_api ):
471546 return input_api .canned_checks .CheckAuthorizedAuthor (
472547 input_api ,
0 commit comments