From 6c6035d04b6cd877f6fade9a04b387cdd5f88d79 Mon Sep 17 00:00:00 2001 From: Vihang Mehta Date: Thu, 15 May 2014 09:18:24 -0700 Subject: [PATCH] Add Closure linter to arcanist Summary: Found https://secure.phabricator.com/D4519 but it was horribly out of date, so decided to write a new version. Kinda clobbered together form that diff and the new version of ArcanistJSHintLinter Test Plan: Tested on personal projects with js files. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D9131 --- src/__phutil_library_map__.php | 4 + src/lint/linter/ArcanistClosureLinter.php | 82 +++++++++++++++++++ .../ArcanistClosureLinterTestCase.php | 15 ++++ .../__tests__/gjslint/gjslint.lint-test | 20 +++++ 4 files changed, 121 insertions(+) create mode 100644 src/lint/linter/ArcanistClosureLinter.php create mode 100644 src/lint/linter/__tests__/ArcanistClosureLinterTestCase.php create mode 100644 src/lint/linter/__tests__/gjslint/gjslint.lint-test diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 6131a1aa..6dcf598c 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -36,6 +36,8 @@ phutil_register_library_map(array( 'ArcanistChooseNoRevisionsException' => 'exception/ArcanistChooseNoRevisionsException.php', 'ArcanistCloseRevisionWorkflow' => 'workflow/ArcanistCloseRevisionWorkflow.php', 'ArcanistCloseWorkflow' => 'workflow/ArcanistCloseWorkflow.php', + 'ArcanistClosureLinter' => 'lint/linter/ArcanistClosureLinter.php', + 'ArcanistClosureLinterTestCase' => 'lint/linter/__tests__/ArcanistClosureLinterTestCase.php', 'ArcanistCommentRemover' => 'parser/ArcanistCommentRemover.php', 'ArcanistCommentRemoverTestCase' => 'parser/__tests__/ArcanistCommentRemoverTestCase.php', 'ArcanistCommitWorkflow' => 'workflow/ArcanistCommitWorkflow.php', @@ -222,6 +224,8 @@ phutil_register_library_map(array( 'ArcanistChooseNoRevisionsException' => 'Exception', 'ArcanistCloseRevisionWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistCloseWorkflow' => 'ArcanistBaseWorkflow', + 'ArcanistClosureLinter' => 'ArcanistExternalLinter', + 'ArcanistClosureLinterTestCase' => 'ArcanistArcanistLinterTestCase', 'ArcanistCommentRemoverTestCase' => 'ArcanistTestCase', 'ArcanistCommitWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistConduitLinter' => 'ArcanistLinter', diff --git a/src/lint/linter/ArcanistClosureLinter.php b/src/lint/linter/ArcanistClosureLinter.php new file mode 100644 index 00000000..6cc21bba --- /dev/null +++ b/src/lint/linter/ArcanistClosureLinter.php @@ -0,0 +1,82 @@ + $match) { + $matches[$key] = trim($match); + } + + $message = new ArcanistLintMessage(); + $message->setPath($path); + $message->setLine($matches[1]); + $message->setName($matches[2]); + $message->setCode($this->getLinterName()); + $message->setDescription($matches[3]); + $message->setSeverity($severity_code); + + $messages[] = $message; + } + + return $messages; + } +} diff --git a/src/lint/linter/__tests__/ArcanistClosureLinterTestCase.php b/src/lint/linter/__tests__/ArcanistClosureLinterTestCase.php new file mode 100644 index 00000000..45afe24f --- /dev/null +++ b/src/lint/linter/__tests__/ArcanistClosureLinterTestCase.php @@ -0,0 +1,15 @@ +setFlags(array("--additional_extensions=lint-test")); + + $this->executeTestsInDirectory( + dirname(__FILE__).'/gjslint/', + $linter); + } + +} diff --git a/src/lint/linter/__tests__/gjslint/gjslint.lint-test b/src/lint/linter/__tests__/gjslint/gjslint.lint-test new file mode 100644 index 00000000..64c5c331 --- /dev/null +++ b/src/lint/linter/__tests__/gjslint/gjslint.lint-test @@ -0,0 +1,20 @@ +var x = 'some really really really really really really really long string'; +var y = 'some really really really really really really really really really long string', + z = 14; +var obj = {name : 'vm'}; +var x +var result = true + || false; +/** + * @param x + * @return {string} + */ +function foo(x) { + return 'bar'; +} +~~~~~~~~~~ +error:2: +error:4: +error:5: +error:7: +error:9: \ No newline at end of file -- 2.43.0