From cf998db5e07e6f3c263913a446ab25e060012ad8 Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Sun, 22 Jun 2014 06:41:22 +1000 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 4 ++ src/lint/linter/ArcanistJSONLinter.php | 39 +++++++++++++++++++ .../__tests__/ArcanistJSONLinterTestCase.php | 11 ++++++ 3 files changed, 54 insertions(+) create mode 100644 src/lint/linter/ArcanistJSONLinter.php create mode 100644 src/lint/linter/__tests__/ArcanistJSONLinterTestCase.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 1b325c6c..58826e12 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/lint/linter/ArcanistJSONLinter.php b/src/lint/linter/ArcanistJSONLinter.php new file mode 100644 index 00000000..ff03a8c3 --- /dev/null +++ b/src/lint/linter/ArcanistJSONLinter.php @@ -0,0 +1,39 @@ +getData($path); + + try { + $parser = new PhutilJSONParser(); + $parser->parse($data); + } catch (PhutilJSONParserException $ex) { + $this->raiseLintAtLine( + $ex->getSourceLine(), + $ex->getSourceChar(), + $this->getLinterName(), + $ex->getMessage()); + } + } + +} diff --git a/src/lint/linter/__tests__/ArcanistJSONLinterTestCase.php b/src/lint/linter/__tests__/ArcanistJSONLinterTestCase.php new file mode 100644 index 00000000..1913c0dc --- /dev/null +++ b/src/lint/linter/__tests__/ArcanistJSONLinterTestCase.php @@ -0,0 +1,11 @@ +executeTestsInDirectory( + dirname(__FILE__).'/jsonlint/', + new ArcanistJSONLinter()); + } + +} -- 2.43.0