2014-06-22 06:41:22 +10:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A linter for JSON files.
|
|
|
|
*/
|
|
|
|
final class ArcanistJSONLinter extends ArcanistLinter {
|
|
|
|
|
2015-01-12 06:40:40 +11:00
|
|
|
const LINT_PARSE_ERROR = 1;
|
|
|
|
|
2014-06-22 06:41:22 +10:00
|
|
|
public function getInfoName() {
|
|
|
|
return 'JSON Lint';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getInfoDescription() {
|
|
|
|
return pht('Detect syntax errors in JSON files.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLinterName() {
|
|
|
|
return 'JSON';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLinterConfigurationName() {
|
|
|
|
return 'json';
|
|
|
|
}
|
|
|
|
|
2015-01-12 06:40:40 +11:00
|
|
|
public function getLintNameMap() {
|
|
|
|
return array(
|
|
|
|
self::LINT_PARSE_ERROR => pht('Parse Error'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function canCustomizeLintSeverities() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:41:22 +10:00
|
|
|
public function lintPath($path) {
|
|
|
|
$data = $this->getData($path);
|
|
|
|
|
|
|
|
try {
|
2015-01-12 06:40:40 +11:00
|
|
|
id(new PhutilJSONParser())->parse($data);
|
2014-06-22 06:41:22 +10:00
|
|
|
} catch (PhutilJSONParserException $ex) {
|
|
|
|
$this->raiseLintAtLine(
|
|
|
|
$ex->getSourceLine(),
|
|
|
|
$ex->getSourceChar(),
|
2015-01-12 06:40:40 +11:00
|
|
|
self::LINT_PARSE_ERROR,
|
2014-06-22 06:41:22 +10:00
|
|
|
$ex->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|