Page MenuHomePhabricator

D9628.diff
No OneTemporary

D9628.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -95,6 +95,8 @@
'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 @@
'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
--- /dev/null
+++ b/src/lint/linter/ArcanistJSONLinter.php
@@ -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());
+ }
+ }
+
+}
diff --git a/src/lint/linter/__tests__/ArcanistJSONLinterTestCase.php b/src/lint/linter/__tests__/ArcanistJSONLinterTestCase.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/__tests__/ArcanistJSONLinterTestCase.php
@@ -0,0 +1,11 @@
+<?php
+
+final class ArcanistJSONLinterTestCase extends ArcanistArcanistLinterTestCase {
+
+ public function testJSONLinter() {
+ $this->executeTestsInDirectory(
+ dirname(__FILE__).'/jsonlint/',
+ new ArcanistJSONLinter());
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 25, 12:19 AM (19 h, 31 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6782261
Default Alt Text
D9628.diff (2 KB)

Event Timeline