13
13
`git cl presubmit -v -v` to debug presubmit checks.
14
14
"""
15
15
16
+ import re
16
17
import sys
17
18
import six
18
19
import time
27
28
r'^front_end[\\/]core[\\/]common[\\/]Color\.ts$' , # Apple copyright
28
29
r'^front_end[\\/]core[\\/]common[\\/]Object\.ts$' , # Apple copyright
29
30
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$' ,
31
33
r'^front_end[\\/]core[\\/]platform[\\/]UIString\.ts$' , # Apple copyright
32
34
r'^front_end[\\/]core[\\/]sdk[\\/]Resource\.ts$' , # Apple copyright
33
35
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
35
40
r'^scripts[\\/]build[\\/]build_inspector_overlay\.py$' , # Lines too long
36
41
r'^scripts[\\/]build[\\/]code_generator_frontend\.py$' ,
37
42
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$'
38
46
]
39
47
48
+
40
49
def _ExecuteSubProcess (input_api ,
41
50
output_api ,
42
51
script_path ,
@@ -246,13 +255,7 @@ def CheckDevToolsLint(input_api, output_api):
246
255
]
247
256
248
257
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' ),
256
259
]
257
260
258
261
lint_config_files = _GetAffectedFiles (
@@ -400,9 +403,38 @@ def CheckNodeModules(input_api, output_api):
400
403
if not Path (file_path ).is_file ():
401
404
results .extend ([
402
405
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."
404
407
% file )
405
408
])
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
+
406
438
return results
407
439
408
440
@@ -416,7 +448,7 @@ def CheckNoUncheckedFiles(input_api, output_api):
416
448
out , _ = process .communicate ()
417
449
if process .returncode != 0 :
418
450
files_changed_process = input_api .subprocess .Popen (
419
- ['git' , 'diff' , '--name-only' ],
451
+ ['git' , 'diff' ],
420
452
stdout = input_api .subprocess .PIPE ,
421
453
stderr = input_api .subprocess .STDOUT )
422
454
files_changed , _ = files_changed_process .communicate ()
@@ -430,6 +462,50 @@ def CheckNoUncheckedFiles(input_api, output_api):
430
462
return []
431
463
432
464
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
+
433
509
# Canned check wrappers below.
434
510
435
511
@@ -466,7 +542,6 @@ def CheckGenderNeutral(input_api, output_api):
466
542
return input_api .canned_checks .CheckGenderNeutral (input_api , output_api )
467
543
468
544
469
-
470
545
def CheckAuthorizedAuthor (input_api , output_api ):
471
546
return input_api .canned_checks .CheckAuthorizedAuthor (
472
547
input_api ,
0 commit comments