From 97b38565cfe96ae96f004c3f58b1cc7e4fcfe275 Mon Sep 17 00:00:00 2001 From: Bastien Abadie Date: Fri, 7 Dec 2018 09:50:02 +0100 Subject: [PATCH] staticanalysis/bot: Do not publish clang-format issues on third party, fixes #1735. --- .../bot/static_analysis_bot/clang/format.py | 3 ++- src/staticanalysis/bot/tests/conftest.py | 2 +- src/staticanalysis/bot/tests/test_clang.py | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/staticanalysis/bot/static_analysis_bot/clang/format.py b/src/staticanalysis/bot/static_analysis_bot/clang/format.py index 10baeb7149..eae7af1f10 100644 --- a/src/staticanalysis/bot/static_analysis_bot/clang/format.py +++ b/src/staticanalysis/bot/static_analysis_bot/clang/format.py @@ -141,7 +141,8 @@ def validates(self): ''' Should match one of the allowed paths rules ''' - return settings.is_allowed_path(self.path) + return settings.is_allowed_path(self.path) \ + and not self.is_third_party() def as_text(self): ''' diff --git a/src/staticanalysis/bot/tests/conftest.py b/src/staticanalysis/bot/tests/conftest.py index 9d37f3f3fe..e13ea1a64b 100644 --- a/src/staticanalysis/bot/tests/conftest.py +++ b/src/staticanalysis/bot/tests/conftest.py @@ -45,7 +45,7 @@ def mock_config(): from static_analysis_bot.config import settings tempdir = tempfile.mkdtemp() - settings.setup('test', tempdir, 'IN_PATCH', ['dom/*', 'tests/*.py']) + settings.setup('test', tempdir, 'IN_PATCH', ['dom/*', 'tests/*.py', 'test/*.c']) return settings diff --git a/src/staticanalysis/bot/tests/test_clang.py b/src/staticanalysis/bot/tests/test_clang.py index 622a1170b3..d67834170e 100644 --- a/src/staticanalysis/bot/tests/test_clang.py +++ b/src/staticanalysis/bot/tests/test_clang.py @@ -315,3 +315,21 @@ def test_repeats(mock_clang_repeats, mock_revision, mock_config): assert len(issues) == 3 count = Counter(i.check for i in issues) assert count['modernize-loop-convert'] == 1 + + +def test_clang_format_3rd_party(mock_repository, mock_revision): + ''' + Test a clang format issue in 3rd party is not publishable + ''' + from static_analysis_bot.clang.format import ClangFormatIssue + + mock_revision.lines = { + 'test/not_3rd.c': [10, ], + 'test/dummy/third_party.c': [10, ], + } + issue = ClangFormatIssue('test/not_3rd.c', 10, 1, mock_revision) + assert issue.is_publishable() + + # test/dummy is a third party directory + issue = ClangFormatIssue('test/dummy/third_party.c', 10, 1, mock_revision) + assert not issue.is_publishable()