Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22394747
ArcanistJSONLintLinter.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
ArcanistJSONLintLinter.php
View Options
<?php
/**
* A linter for JSON files.
*/
final
class
ArcanistJSONLintLinter
extends
ArcanistExternalLinter
{
public
function
getLinterName
()
{
return
'JSON'
;
}
public
function
getLinterConfigurationName
()
{
return
'jsonlint'
;
}
public
function
getDefaultBinary
()
{
return
'jsonlint'
;
}
public
function
getVersion
()
{
// NOTE: `jsonlint --version` returns a non-zero exit status.
list
(
$err
,
$stdout
)
=
exec_manual
(
'%C --version'
,
$this
->
getExecutableCommand
());
$matches
=
array
();
if
(
preg_match
(
'/^(?P<version>
\d
+
\.\d
+
\.\d
+)$/'
,
$stdout
,
$matches
))
{
$version
=
$matches
[
'version'
];
}
else
{
return
false
;
}
}
public
function
getInstallInstructions
()
{
return
pht
(
'Install jsonlint using `npm install -g jsonlint`.'
);
}
public
function
shouldExpectCommandErrors
()
{
return
true
;
}
public
function
supportsReadDataFromStdin
()
{
return
true
;
}
protected
function
getMandatoryFlags
()
{
return
array
(
'--compact'
,
);
}
protected
function
parseLinterOutput
(
$path
,
$err
,
$stdout
,
$stderr
)
{
$lines
=
phutil_split_lines
(
$stderr
,
false
);
$messages
=
array
();
foreach
(
$lines
as
$line
)
{
$matches
=
null
;
$match
=
preg_match
(
'/^(?:(?<path>.+): )?'
.
'line (?<line>
\d
+), col (?<column>
\d
+), '
.
'(?<description>.*)$/'
,
$line
,
$matches
);
if
(
$match
)
{
$message
=
new
ArcanistLintMessage
();
$message
->
setPath
(
$path
);
$message
->
setLine
(
$matches
[
'line'
]);
$message
->
setChar
(
$matches
[
'column'
]);
$message
->
setCode
(
$this
->
getLinterName
());
$message
->
setDescription
(
ucfirst
(
$matches
[
'description'
]));
$message
->
setSeverity
(
ArcanistLintSeverity
::
SEVERITY_ERROR
);
$messages
[]
=
$message
;
}
}
if
(
$err
&&
!
$messages
)
{
return
false
;
}
return
$messages
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Nov 27, 16:20 (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1223232
Default Alt Text
ArcanistJSONLintLinter.php (1 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline