Skip to content
This repository has been archived by the owner on Nov 11, 2019. It is now read-only.

staticanalysis/bot: Consider having reviewbot provide more actionable clang-format and clang-tidy. #2045

Merged
merged 1 commit into from
Apr 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/staticanalysis/bot/static_analysis_bot/report/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
COMMENT_PARTS = {
ClangTidyIssue: {
'defect': ' - {nb} found by clang-tidy',
'analyzer': ' - `./mach static-analysis check path/to/file.cpp` (C/C++)',
'analyzer': ' - `./mach static-analysis check {files}` (C/C++)',
},
InferIssue: {
'defect': ' - {nb} found by infer',
Expand All @@ -25,7 +25,7 @@
},
ClangFormatIssue: {
'defect': ' - {nb} found by clang-format',
'analyzer': ' - `./mach clang-format -s -p path/to/file.cpp` (C/C++)',
'analyzer': ' - `./mach clang-format -s -p {files}` (C/C++)',
},
MozLintIssue: {
'defect': ' - {nb} found by mozlint',
Expand Down Expand Up @@ -103,7 +103,8 @@ def stats(items):
_items = list(items)
return {
'total': len(_items),
'publishable': sum([i.is_publishable() for i in _items])
'publishable': sum([i.is_publishable() for i in _items]),
'publishable_paths': list({i.path for i in _items if i.is_publishable()})
}

from collections import OrderedDict
Expand Down Expand Up @@ -134,7 +135,7 @@ def pluralize(word, nb):
nb=pluralize('defect', cls_stats['publishable'])
))
if 'analyzer' in part:
analyzers.append(part['analyzer'])
analyzers.append(part['analyzer'].format(files=' '.join(cls_stats['publishable_paths'])))

# Build top comment
nb = len(issues)
Expand Down
1 change: 1 addition & 0 deletions src/staticanalysis/bot/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def mock_issues():
class MockIssue(object):
def __init__(self, nb):
self.nb = nb
self.path = '/path/to/file'

def as_markdown(self):
return 'This is the mock issue n°{}'.format(self.nb)
Expand Down
1 change: 1 addition & 0 deletions src/staticanalysis/bot/tests/test_reporter_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,6 @@ def _check_email(request):
mock_cls: {
'total': 5,
'publishable': 3,
'publishable_paths': ['/path/to/file']
}
}
8 changes: 4 additions & 4 deletions src/staticanalysis/bot/tests/test_reporter_phabricator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- 1 defect found by clang-tidy

You can run this analysis locally with:
- `./mach static-analysis check path/to/file.cpp` (C/C++)
- `./mach static-analysis check another_test.cpp` (C/C++)

If you see a problem in this automated review, [please report it here](https://bugzilla.mozilla.org/enter_bug.cgi?product=Firefox+Build+System&component=Source+Code+Analysis&short_desc=[Automated+review]+UPDATE&comment=**Phabricator+URL:**+https://phabricator.services.mozilla.com/...&format=__default__).
''' # noqa
Expand All @@ -26,7 +26,7 @@
- 1 defect found by clang-format

You can run this analysis locally with:
- `./mach clang-format -s -p path/to/file.cpp` (C/C++)
- `./mach clang-format -s -p dom/test.cpp` (C/C++)

For your convenience, [here is a patch]({results}/clang-format-PHID-DIFF-abcdef.diff) that fixes all the clang-format defects (use it in your repository with `hg import` or `git apply`).

Expand Down Expand Up @@ -85,11 +85,11 @@ def _check_comment(request):
revision = PhabricatorRevision(api, 'PHID-DIFF-abcdef')
revision.lines = {
# Add dummy lines diff
'test.cpp': [41, 42, 43],
'another_test.cpp': [41, 42, 43],
}
reporter = PhabricatorReporter({'analyzers': ['clang-tidy'], 'modes': ('comment')}, api=api)

issue = ClangTidyIssue(revision, 'test.cpp', '42', '51', 'modernize-use-nullptr', 'dummy message', 'error')
issue = ClangTidyIssue(revision, 'another_test.cpp', '42', '51', 'modernize-use-nullptr', 'dummy message', 'error')
assert issue.is_publishable()

issues, patches = reporter.publish([issue, ], revision)
Expand Down