pre-upload: allow gofmt_check to be overridden
Protoc generates files that do not pass gofmt linting (due to line
lengths). Allow a repo to specify which golang files should be included
and/or excluded in the gofmt check.
BUG=None
TEST=infra/proto repo can override
Change-Id: I73f2012dabba03a981b52ea31d5be24d7a3774c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/repohooks/+/2048136
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: David Burger <dburger@chromium.org>
Tested-by: LaMont Jones <lamontjones@chromium.org>
diff --git a/pre-upload.py b/pre-upload.py
index 4220d14..dbd8526 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -600,11 +600,13 @@
'Found a space in indentation (must be all tabs):')
-def _check_gofmt(_project, commit):
+def _check_gofmt(_project, commit, options=()):
"""Checks that Go files are formatted with gofmt."""
+ included, excluded = _parse_common_inclusion_options(options)
errors = []
files = _filter_files(_get_affected_files(commit, relative=True),
- [r'\.go$'])
+ included + [r'\.go$'],
+ excluded)
for gofile in files:
contents = _get_file_content(gofile, commit)
@@ -1870,6 +1872,7 @@
'long_line_check': _check_no_long_lines,
'cros_license_check': _check_cros_license,
'aosp_license_check': _check_aosp_license,
+ 'gofmt_check': _check_gofmt,
'tab_check': _check_no_tabs,
'tabbed_indent_required_check': _check_tabbed_indents,
'branch_check': _check_change_has_branch_field,