MCPcopy Index your code
hub / github.com/nodejs/node / _CheckBannedCpp

Function _CheckBannedCpp

deps/v8/PRESUBMIT.py:618–657  ·  view source on GitHub ↗
(input_api, output_api)

Source from the content-addressed store, hash-verified

616
617
618def _CheckBannedCpp(input_api, output_api):
619 # We only check for a single pattern right now; feel free to add more, but
620 # potentially change the logic for files_to_skip then (and skip individual
621 # checks for individual files instead).
622 bad_cpp = [
623 ('std::bit_cast',
624 'Use base::bit_cast instead, which has additional checks'),
625 ]
626
627 def file_filter(x):
628 return input_api.FilterSourceFile(
629 x,
630 files_to_skip=[
631 # The implementation of base::bit_cast uses std::bit_cast.
632 r'src/base/macros\.h',
633 # src/base/numerics is a dependency-free header-only library, hence
634 # uses std::bit_cast directly.
635 r'src/base/numerics/.*'
636 ],
637 files_to_check=[r'.*\.h$', r'.*\.cc$'])
638
639 errors = []
640 for f in input_api.AffectedSourceFiles(file_filter):
641 for line_number, line in f.ChangedContents():
642 for pattern, message in bad_cpp:
643 if not pattern in line:
644 continue
645 # Skip if part of a comment.
646 if '//' in line and line.index('//') < line.index(pattern):
647 continue
648
649 # Make sure there are word separators around the pattern.
650 regex = r'\b%s\b' % pattern
651 if not input_api.re.search(regex, line):
652 continue
653
654 errors.append(
655 output_api.PresubmitError('Banned pattern ({}):\n {}:{} {}'.format(
656 regex, f.LocalPath(), line_number, message)))
657 return errors
658
659
660def CheckChangeOnUpload(input_api, output_api):

Callers

nothing calls this directly

Calls 6

ChangedContentsMethod · 0.80
LocalPathMethod · 0.80
formatMethod · 0.65
indexMethod · 0.45
searchMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…