1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-09 16:32:39 +01:00

Add a native JSON linter.

Summary:
Ref T5297. Utilize `PhutilJSONParser` to create a native JSON linter (native in that it is pure PHP with no external dependencies).

Since [[https://github.com/Seldaek/jsonlint | JsonLint]] is literally a PHP port of [[https://github.com/zaach/jsonlint | jsonlint]], I figured that we should also deprecate `ArcanistJSONLintLinter`. `ArcanistJSONLinter` //should// behave identically to `ArcanistJSONLintLinter`.

Depends on D9634.

Test Plan: Ran the `ArcanistJSONLintLinter` unit tests.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T5297

Differential Revision: https://secure.phabricator.com/D9628
This commit is contained in:
Joshua Spence 2014-06-22 06:41:22 +10:00
parent a428f22cbf
commit cf998db5e0
3 changed files with 54 additions and 0 deletions

View file

@ -95,6 +95,8 @@ phutil_register_library_map(array(
'ArcanistJSHintLinterTestCase' => 'lint/linter/__tests__/ArcanistJSHintLinterTestCase.php',
'ArcanistJSONLintLinter' => 'lint/linter/ArcanistJSONLintLinter.php',
'ArcanistJSONLintLinterTestCase' => 'lint/linter/__tests__/ArcanistJSONLintLinterTestCase.php',
'ArcanistJSONLinter' => 'lint/linter/ArcanistJSONLinter.php',
'ArcanistJSONLinterTestCase' => 'lint/linter/__tests__/ArcanistJSONLinterTestCase.php',
'ArcanistJscsLinter' => 'lint/linter/ArcanistJscsLinter.php',
'ArcanistJscsLinterTestCase' => 'lint/linter/__tests__/ArcanistJscsLinterTestCase.php',
'ArcanistLandWorkflow' => 'workflow/ArcanistLandWorkflow.php',
@ -276,6 +278,8 @@ phutil_register_library_map(array(
'ArcanistJSHintLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistJSONLintLinter' => 'ArcanistExternalLinter',
'ArcanistJSONLintLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistJSONLinter' => 'ArcanistLinter',
'ArcanistJSONLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistJscsLinter' => 'ArcanistExternalLinter',
'ArcanistJscsLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistLandWorkflow' => 'ArcanistBaseWorkflow',

View file

@ -0,0 +1,39 @@
<?php
/**
* A linter for JSON files.
*/
final class ArcanistJSONLinter extends ArcanistLinter {
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';
}
public function lintPath($path) {
$data = $this->getData($path);
try {
$parser = new PhutilJSONParser();
$parser->parse($data);
} catch (PhutilJSONParserException $ex) {
$this->raiseLintAtLine(
$ex->getSourceLine(),
$ex->getSourceChar(),
$this->getLinterName(),
$ex->getMessage());
}
}
}

View file

@ -0,0 +1,11 @@
<?php
final class ArcanistJSONLinterTestCase extends ArcanistArcanistLinterTestCase {
public function testJSONLinter() {
$this->executeTestsInDirectory(
dirname(__FILE__).'/jsonlint/',
new ArcanistJSONLinter());
}
}