Add default filters to git cl lint.

Use the same set of default filters as presubmit checks. Presubmit
checks use filters to give better lint results as expected by Google C++
style. Give git-cl's lint subcommand the same benefit.

Bug: 1106028
Change-Id: I51ff0737b310990ab424376d2721e8a6a50dfc6e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2298122
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
changes/22/2298122/4
Lei Zhang 5 years ago committed by LUCI CQ
parent 379d1ad115
commit b8c62cf5f4

@ -44,6 +44,7 @@ import metrics
import metrics_utils
import owners
import owners_finder
import presubmit_canned_checks
import presubmit_support
import scm
import setup_color
@ -3780,10 +3781,9 @@ def CMDlint(parser, args):
print('Cannot lint an empty CL')
return 1
# Process cpplints arguments if any.
command = args + files
if options.filter:
command = ['--filter=' + ','.join(options.filter)] + command
# Process cpplint arguments, if any.
filters = presubmit_canned_checks.GetCppLintFilters(options.filter)
command = ['--filter=' + ','.join(filters)] + args + files
filenames = cpplint.ParseArguments(command)
include_regex = re.compile(settings.GetLintRegex())

@ -159,6 +159,14 @@ def CheckDoNotSubmitInFiles(input_api, output_api):
return []
def GetCppLintFilters(lint_filters=None):
filters = OFF_UNLESS_MANUALLY_ENABLED_LINT_FILTERS[:]
if lint_filters is None:
lint_filters = OFF_BY_DEFAULT_LINT_FILTERS
filters.extend(lint_filters)
return filters
def CheckChangeLintsClean(input_api, output_api, source_file_filter=None,
lint_filters=None, verbose_level=None):
"""Checks that all '.cc' and '.h' files pass cpplint.py."""
@ -170,11 +178,7 @@ def CheckChangeLintsClean(input_api, output_api, source_file_filter=None,
# pylint: disable=protected-access
cpplint._cpplint_state.ResetErrorCounts()
filters = OFF_UNLESS_MANUALLY_ENABLED_LINT_FILTERS[:]
if lint_filters is None:
lint_filters = OFF_BY_DEFAULT_LINT_FILTERS
filters.extend(lint_filters)
cpplint._SetFilters(','.join(filters))
cpplint._SetFilters(','.join(GetCppLintFilters(lint_filters)))
# We currently are more strict with normal code than unit tests; 4 and 5 are
# the verbosity level that would normally be passed to cpplint.py through

Loading…
Cancel
Save