Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F93655885
ClangFormatLinter.php
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, Nov 30, 12:01
Size
2 KB
Mime Type
text/x-php
Expires
Mon, Dec 2, 12:01 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22671753
Attached To
rAKA akantu
ClangFormatLinter.php
View Options
<?php
/**
* Uses the clang format to format C/C++/Obj-C code
*/
final
class
ClangFormatLinter
extends
ArcanistExternalLinter
{
public
function
getInfoName
()
{
return
'clang-format'
;
}
public
function
getInfoURI
()
{
return
'https://clang.llvm.org/docs/ClangFormat.html'
;
}
public
function
getInfoDescription
()
{
return
pht
(
'Use clang-format for processing specified files.'
);
}
public
function
getLinterName
()
{
return
'clang-format'
;
}
public
function
getLinterConfigurationName
()
{
return
'clang-format'
;
}
public
function
getLinterConfigurationOptions
()
{
$options
=
array
(
);
return
$options
+
parent
::
getLinterConfigurationOptions
();
}
public
function
getDefaultBinary
()
{
return
'clang-format'
;
}
public
function
getVersion
()
{
list
(
$stdout
)
=
execx
(
'%C -version'
,
$this
->
getExecutableCommand
());
$matches
=
array
();
if
(
preg_match
(
'/^(?P<version>
\d
+
\.\d
+
\.\d
+)$/'
,
$stdout
,
$matches
))
{
return
$matches
[
'version'
];
}
else
{
return
false
;
}
}
public
function
getInstallInstructions
()
{
return
pht
(
'On a apt based system, apt-get install clang-format. Othewhy install following the instructions on installing tool inb clang, and make sure clang-format is in directory specified by $PATH'
);
}
public
function
shouldExpectCommandErrors
()
{
return
false
;
}
protected
function
getMandatoryFlags
()
{
return
array
(
);
}
protected
function
parseLinterOutput
(
$path
,
$err
,
$stdout
,
$stderr
)
{
$ok
=
(
$err
==
0
);
if
(!
$ok
)
{
return
false
;
}
$root
=
$this
->
getProjectRoot
();
$path
=
Filesystem
::
resolvePath
(
$path
,
$root
);
$orig
=
file_get_contents
(
$path
);
if
(
$orig
==
$stdout
)
{
return
array
();
}
$message
=
id
(
new
ArcanistLintMessage
())
->
setPath
(
$path
)
->
setLine
(
1
)
->
setChar
(
1
)
->
setGranularity
(
ArcanistLinter
::
GRANULARITY_FILE
)
->
setCode
(
'CFMT'
)
->
setSeverity
(
ArcanistLintSeverity
::
SEVERITY_AUTOFIX
)
->
setName
(
'Code style violation'
)
->
setDescription
(
"'$path' has code style errors."
)
->
setOriginalText
(
$orig
)
->
setReplacementText
(
$stdout
);
return
array
(
$message
);
}
}
Event Timeline
Log In to Comment