Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F8890703
ArcanistCppcheckLinter.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
ArcanistCppcheckLinter.php
View Options
<?php
/**
* Uses Cppcheck to do basic checks in a C++ file.
*/
final
class
ArcanistCppcheckLinter
extends
ArcanistExternalLinter
{
public
function
getInfoName
()
{
return
'C++ linter'
;
}
public
function
getInfoURI
()
{
return
'http://cppcheck.sourceforge.net'
;
}
public
function
getInfoDescription
()
{
return
pht
(
'Use `%s` to perform static analysis on C/C++ code.'
,
'cppcheck'
);
}
public
function
getLinterName
()
{
return
'cppcheck'
;
}
public
function
getLinterConfigurationName
()
{
return
'cppcheck'
;
}
public
function
getDefaultBinary
()
{
return
'cppcheck'
;
}
public
function
getVersion
()
{
list
(
$stdout
)
=
execx
(
'%C --version'
,
$this
->
getExecutableCommand
());
$matches
=
array
();
$regex
=
'/^Cppcheck (?P<version>
\d
+
\.\d
+)$/'
;
if
(
preg_match
(
$regex
,
$stdout
,
$matches
))
{
return
$matches
[
'version'
];
}
else
{
return
false
;
}
}
public
function
getInstallInstructions
()
{
return
pht
(
'Install Cppcheck using `%s` or similar.'
,
'apt-get install cppcheck'
);
}
protected
function
getDefaultFlags
()
{
return
array
(
'-j2'
,
'--enable=performance,style,portability,information'
,
);
}
protected
function
getMandatoryFlags
()
{
return
array
(
'--quiet'
,
'--inline-suppr'
,
'--xml'
,
'--xml-version=2'
,
);
}
public
function
shouldExpectCommandErrors
()
{
return
false
;
}
protected
function
parseLinterOutput
(
$path
,
$err
,
$stdout
,
$stderr
)
{
$dom
=
new
DOMDocument
();
$ok
=
@
$dom
->
loadXML
(
$stderr
);
if
(!
$ok
)
{
return
false
;
}
$errors
=
$dom
->
getElementsByTagName
(
'error'
);
$messages
=
array
();
foreach
(
$errors
as
$error
)
{
foreach
(
$error
->
getElementsByTagName
(
'location'
)
as
$location
)
{
$message
=
new
ArcanistLintMessage
();
$message
->
setPath
(
$location
->
getAttribute
(
'file'
));
$message
->
setLine
(
$location
->
getAttribute
(
'line'
));
$message
->
setCode
(
'Cppcheck'
);
$message
->
setName
(
$error
->
getAttribute
(
'id'
));
$message
->
setDescription
(
$error
->
getAttribute
(
'msg'
));
switch
(
$error
->
getAttribute
(
'severity'
))
{
case
'error'
:
$message
->
setSeverity
(
ArcanistLintSeverity
::
SEVERITY_ERROR
);
break
;
default
:
if
(
$error
->
getAttribute
(
'inconclusive'
))
{
$message
->
setSeverity
(
ArcanistLintSeverity
::
SEVERITY_ADVICE
);
}
else
{
$message
->
setSeverity
(
ArcanistLintSeverity
::
SEVERITY_WARNING
);
}
break
;
}
$messages
[]
=
$message
;
}
}
return
$messages
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Thu, Jun 10, 1:38 PM (1 d, 23 h)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
3387655
Default Alt Text
ArcanistCppcheckLinter.php (2 KB)
Attached To
rARC Arcanist
Event Timeline
Log In to Comment