Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F60131587
issue_generator_clang_format.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Apr 27, 18:14
Size
1 KB
Mime Type
text/x-python
Expires
Mon, Apr 29, 18:14 (2 d)
Engine
blob
Format
Raw Data
Handle
17306073
Attached To
rAKA akantu
issue_generator_clang_format.py
View Options
#!/usr/bin/env python3
from
.
import
print_debug
,
print_info
from
.issue_generator_clang_tool
import
ClangToolIssueGenerator
import
os
import
re
import
copy
import
difflib
import
subprocess
class
ClangFormatIssueGenerator
(
ClangToolIssueGenerator
):
"""issue generator for clang format"""
def
__init__
(
self
,
**
kwargs
):
kwargs
[
'clang_tool_executable'
]
=
kwargs
.
pop
(
'clang_format_executable'
,
'clang-format'
)
super
()
.
__init__
(
'clang-format'
,
**
kwargs
)
def
_get_classifiaction
(
self
,
issue
):
return
([
'Style'
],
'info'
)
def
generate_issues
(
self
):
issue
=
{}
for
filename
in
self
.
_files
:
with
open
(
filename
,
'r'
)
as
fh
:
unformated_file
=
fh
.
readlines
()
command
=
copy
.
copy
(
self
.
_command
)
command
.
append
(
filename
)
formated_file
=
list
(
self
.
_run_command
(
command
))
# diffs = difflib.unified_diff(unformated_file, formated_file, n=0)
# print(diffs)
# for diff in diffs:
# print(diff, end='')
s
=
difflib
.
SequenceMatcher
(
None
,
unformated_file
,
formated_file
)
for
tag
,
i1
,
i2
,
j1
,
j2
in
s
.
get_opcodes
():
if
tag
!=
'equal'
:
diff
=
list
(
difflib
.
unified_diff
(
unformated_file
[
i1
:
i2
],
formated_file
[
j1
:
j2
]))
issue
=
{
'name'
:
f
'''clang-format:{tag}'''
,
'description'
:
''
.
join
(
diff
[
3
:]),
'file'
:
filename
,
'line'
:
i1
,
'column'
:
1
,
'end_line'
:
i2
,
}
self
.
add_issue
(
issue
)
Event Timeline
Log In to Comment