mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 23:02:41 +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:
parent
a428f22cbf
commit
cf998db5e0
3 changed files with 54 additions and 0 deletions
|
@ -95,6 +95,8 @@ phutil_register_library_map(array(
|
||||||
'ArcanistJSHintLinterTestCase' => 'lint/linter/__tests__/ArcanistJSHintLinterTestCase.php',
|
'ArcanistJSHintLinterTestCase' => 'lint/linter/__tests__/ArcanistJSHintLinterTestCase.php',
|
||||||
'ArcanistJSONLintLinter' => 'lint/linter/ArcanistJSONLintLinter.php',
|
'ArcanistJSONLintLinter' => 'lint/linter/ArcanistJSONLintLinter.php',
|
||||||
'ArcanistJSONLintLinterTestCase' => 'lint/linter/__tests__/ArcanistJSONLintLinterTestCase.php',
|
'ArcanistJSONLintLinterTestCase' => 'lint/linter/__tests__/ArcanistJSONLintLinterTestCase.php',
|
||||||
|
'ArcanistJSONLinter' => 'lint/linter/ArcanistJSONLinter.php',
|
||||||
|
'ArcanistJSONLinterTestCase' => 'lint/linter/__tests__/ArcanistJSONLinterTestCase.php',
|
||||||
'ArcanistJscsLinter' => 'lint/linter/ArcanistJscsLinter.php',
|
'ArcanistJscsLinter' => 'lint/linter/ArcanistJscsLinter.php',
|
||||||
'ArcanistJscsLinterTestCase' => 'lint/linter/__tests__/ArcanistJscsLinterTestCase.php',
|
'ArcanistJscsLinterTestCase' => 'lint/linter/__tests__/ArcanistJscsLinterTestCase.php',
|
||||||
'ArcanistLandWorkflow' => 'workflow/ArcanistLandWorkflow.php',
|
'ArcanistLandWorkflow' => 'workflow/ArcanistLandWorkflow.php',
|
||||||
|
@ -276,6 +278,8 @@ phutil_register_library_map(array(
|
||||||
'ArcanistJSHintLinterTestCase' => 'ArcanistArcanistLinterTestCase',
|
'ArcanistJSHintLinterTestCase' => 'ArcanistArcanistLinterTestCase',
|
||||||
'ArcanistJSONLintLinter' => 'ArcanistExternalLinter',
|
'ArcanistJSONLintLinter' => 'ArcanistExternalLinter',
|
||||||
'ArcanistJSONLintLinterTestCase' => 'ArcanistArcanistLinterTestCase',
|
'ArcanistJSONLintLinterTestCase' => 'ArcanistArcanistLinterTestCase',
|
||||||
|
'ArcanistJSONLinter' => 'ArcanistLinter',
|
||||||
|
'ArcanistJSONLinterTestCase' => 'ArcanistArcanistLinterTestCase',
|
||||||
'ArcanistJscsLinter' => 'ArcanistExternalLinter',
|
'ArcanistJscsLinter' => 'ArcanistExternalLinter',
|
||||||
'ArcanistJscsLinterTestCase' => 'ArcanistArcanistLinterTestCase',
|
'ArcanistJscsLinterTestCase' => 'ArcanistArcanistLinterTestCase',
|
||||||
'ArcanistLandWorkflow' => 'ArcanistBaseWorkflow',
|
'ArcanistLandWorkflow' => 'ArcanistBaseWorkflow',
|
||||||
|
|
39
src/lint/linter/ArcanistJSONLinter.php
Normal file
39
src/lint/linter/ArcanistJSONLinter.php
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
11
src/lint/linter/__tests__/ArcanistJSONLinterTestCase.php
Normal file
11
src/lint/linter/__tests__/ArcanistJSONLinterTestCase.php
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class ArcanistJSONLinterTestCase extends ArcanistArcanistLinterTestCase {
|
||||||
|
|
||||||
|
public function testJSONLinter() {
|
||||||
|
$this->executeTestsInDirectory(
|
||||||
|
dirname(__FILE__).'/jsonlint/',
|
||||||
|
new ArcanistJSONLinter());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue