Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Protected Member Functions | List of all members
PRESUBMIT_test_mocks.MockCannedChecks Class Reference
Inheritance diagram for PRESUBMIT_test_mocks.MockCannedChecks:

Protected Member Functions

 _FindNewViolationsOfRule (self, callable_rule, input_api, source_file_filter=None, error_formatter=_ReportErrorFileAndLine)
 

Detailed Description

Definition at line 21 of file PRESUBMIT_test_mocks.py.

Member Function Documentation

◆ _FindNewViolationsOfRule()

PRESUBMIT_test_mocks.MockCannedChecks._FindNewViolationsOfRule (   self,
  callable_rule,
  input_api,
  source_file_filter = None,
  error_formatter = _ReportErrorFileAndLine 
)
protected
Find all newly introduced violations of a per-line rule (a callable).

Arguments:
  callable_rule: a callable taking a file extension and line of input and
    returning True if the rule is satisfied and False if there was a
    problem.
  input_api: object to enumerate the affected files.
  source_file_filter: a filter to be passed to the input api.
  error_formatter: a callable taking (filename, line_number, line) and
    returning a formatted error string.

Returns:
  A list of the newly-introduced violations reported by the rule.

Definition at line 22 of file PRESUBMIT_test_mocks.py.

24 error_formatter=_ReportErrorFileAndLine):
25 """Find all newly introduced violations of a per-line rule (a callable).
26
27 Arguments:
28 callable_rule: a callable taking a file extension and line of input and
29 returning True if the rule is satisfied and False if there was a
30 problem.
31 input_api: object to enumerate the affected files.
32 source_file_filter: a filter to be passed to the input api.
33 error_formatter: a callable taking (filename, line_number, line) and
34 returning a formatted error string.
35
36 Returns:
37 A list of the newly-introduced violations reported by the rule.
38 """
39 errors = []
40 for f in input_api.AffectedFiles(include_deletes=False,
41 file_filter=source_file_filter):
42 # For speed, we do two passes, checking first the full file. Shelling out
43 # to the SCM to determine the changed region can be quite expensive on
44 # Win32. Assuming that most files will be kept problem-free, we can
45 # skip the SCM operations most of the time.
46 extension = str(f.LocalPath()).rsplit('.', 1)[-1]
47 if all(callable_rule(extension, line) for line in f.NewContents()):
48 # No violation found in full text: can skip considering diff.
49 continue
50
51 for line_num, line in f.ChangedContents():
52 if not callable_rule(extension, line):
53 errors.append(error_formatter(
54 f.LocalPath(), line_num, line))
55
56 return errors
57
58

The documentation for this class was generated from the following file: