Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14029652
D14430.id35011.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D14430.id35011.diff
View Options
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
@@ -89,6 +89,7 @@
'ArcanistDuplicateKeysInArrayXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistDuplicateKeysInArrayXHPASTLinterRule.php',
'ArcanistDuplicateSwitchCaseXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistDuplicateSwitchCaseXHPASTLinterRule.php',
'ArcanistDynamicDefineXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistDynamicDefineXHPASTLinterRule.php',
+ 'ArcanistElixirDogmaLinter' => 'lint/linter/ArcanistElixirDogmaLinter.php',
'ArcanistElseIfUsageXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistElseIfUsageXHPASTLinterRule.php',
'ArcanistEmptyFileXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistEmptyFileXHPASTLinterRule.php',
'ArcanistEmptyStatementXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistEmptyStatementXHPASTLinterRule.php',
@@ -283,6 +284,7 @@
'ArcanistXMLLinterTestCase' => 'lint/linter/__tests__/ArcanistXMLLinterTestCase.php',
'ArcanistXUnitTestResultParser' => 'unit/parser/ArcanistXUnitTestResultParser.php',
'CSharpToolsTestEngine' => 'unit/engine/CSharpToolsTestEngine.php',
+ 'ExunitTestEngine' => 'unit/engine/ExunitTestEngine.php',
'NoseTestEngine' => 'unit/engine/NoseTestEngine.php',
'PhpunitTestEngine' => 'unit/engine/PhpunitTestEngine.php',
'PhpunitTestEngineTestCase' => 'unit/engine/__tests__/PhpunitTestEngineTestCase.php',
@@ -378,6 +380,7 @@
'ArcanistDuplicateKeysInArrayXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistDuplicateSwitchCaseXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistDynamicDefineXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
+ 'ArcanistElixirDogmaLinter' => 'ArcanistExternalLinter',
'ArcanistElseIfUsageXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistEmptyFileXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistEmptyStatementXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
@@ -572,6 +575,7 @@
'ArcanistXMLLinterTestCase' => 'ArcanistLinterTestCase',
'ArcanistXUnitTestResultParser' => 'Phobject',
'CSharpToolsTestEngine' => 'XUnitTestEngine',
+ 'ExunitTestEngine' => 'ArcanistUnitTestEngine',
'NoseTestEngine' => 'ArcanistUnitTestEngine',
'PhpunitTestEngine' => 'ArcanistUnitTestEngine',
'PhpunitTestEngineTestCase' => 'PhutilTestCase',
diff --git a/src/lint/linter/ArcanistElixirDogmaLinter.php b/src/lint/linter/ArcanistElixirDogmaLinter.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/ArcanistElixirDogmaLinter.php
@@ -0,0 +1,118 @@
+<?php
+
+final class ArcanistElixirDogmaLinter extends ArcanistExternalLinter {
+
+ private $projectRootDir = null;
+
+ public function getInfoName() {
+ return 'ElixirDogma';
+ }
+
+ public function getInfoURI() {
+ return 'https://github.com/lpil/dogma';
+ }
+
+ public function getInfoDescription() {
+ return pht('A code style linter for Elixir, powered by shame.');
+ }
+
+ public function getLinterName() {
+ return 'ELIXIRDOGMA';
+ }
+
+ public function getLinterConfigurationName() {
+ return 'elixirdogma';
+ }
+ public function getLinterConfigurationOptions() {
+ $options = array(
+ 'elixirdogma.project-root-dir' => array(
+ 'type' => 'optional string',
+ 'help' => pht(
+ 'Adjust the project root directory in which mix is executed.'.
+ 'This is useful in case the Elixir project\'s root'.
+ 'resides in a subdirectory of the repository.'),
+ ),
+ );
+
+ return $options + parent::getLinterConfigurationOptions();
+ }
+
+ public function setProjectRootDir($new_dir) {
+ $this->projectRootDir = $new_dir;
+ return $this;
+ }
+
+ public function setLinterConfigurationValue($key, $value) {
+ switch ($key) {
+ case 'elixirdogma.project-root-dir':
+ $this->setProjectRootDir($value);
+ return;
+ }
+
+ return parent::setLinterConfigurationValue($key, $value);
+ }
+
+ public function getDefaultBinary() {
+ return 'mix';
+ }
+
+ protected function getMandatoryFlags() {
+ $flags = array();
+ if ($this->projectRootDir) {
+ $flags[] = 'cmd';
+ $flags[] = 'cd '.$this->projectRootDir;
+ $flags[] = "&&";
+ $flags[] = 'mix';
+ }
+ $flags[] = 'dogma --format=flycheck';
+ return $flags;
+ }
+
+ public function getInstallInstructions() {
+ return pht(
+ 'Install dogma by adding it as a dependency to your deps and
+ executing mix deps.get');
+ }
+
+ public function shouldExpectCommandErrors() {
+ return true;
+ }
+
+ protected function canCustomizeLintSeverities() {
+ return false;
+ }
+
+ protected function parseLinterOutput($path, $err, $stdout, $stderr) {
+ $lines = phutil_split_lines($stdout, false);
+
+ $messages = array();
+ foreach ($lines as $line) {
+ $matches = explode(':', $line, 5);
+
+ if (count($matches) === 5) {
+ $message = new ArcanistLintMessage();
+ $message->setPath($path);
+ $message->setLine($matches[1]);
+ $message->setChar($matches[2]);
+ $message->setCode($this->getLinterName());
+ $message->setName($this->getLinterName());
+ $message->setDescription(ucfirst(trim($matches[4])));
+ $message->setSeverity($this->getSeverity(ucfirst(trim($matches[3]))));
+
+ $messages[] = $message;
+ }
+ }
+
+ return $messages;
+ }
+
+ private function getSeverity($identifier) {
+ switch ($identifier) {
+ case 'W':
+ return ArcanistLintSeverity::SEVERITY_WARNING;
+ case 'E':
+ return ArcanistLintSeverity::SEVERITY_ERROR;
+ }
+ return ArcanistLintSeverity::SEVERITY_ADVICE;
+ }
+}
diff --git a/src/unit/engine/ExunitTestEngine.php b/src/unit/engine/ExunitTestEngine.php
new file mode 100644
--- /dev/null
+++ b/src/unit/engine/ExunitTestEngine.php
@@ -0,0 +1,57 @@
+<?php
+
+/**
+ * Very basic 'mix test' unit test engine wrapper.
+ *
+ * It requires the use of the junit_formatter to produce the xml report.
+ * Refer to https://hex.pm/packages/junit_formatter
+ *
+ * Cover reporting is not supported yet.
+ *
+ * Note: When using mix configurations you likely want to execute the
+ * unit tests with the correct environment, e.g. `MIX_ENV=test arc unit`
+ */
+final class ExunitTestEngine extends ArcanistUnitTestEngine {
+
+ private $projectRoot;
+
+ public function run() {
+ $working_copy = $this->getWorkingCopy();
+ $this->projectRoot = $working_copy->getProjectRoot();
+
+ // this is the standard report location when using mix test
+ $junit_file = $this->projectRoot.'/_build/test/test-junit-report.xml';
+ $cover_tmp = new TempFile();
+
+ $future = $this->buildTestFuture($junit_file, $cover_tmp);
+ list($err, $stdout, $stderr) = $future->resolve();
+
+ if (!Filesystem::pathExists($junit_file)) {
+ throw new CommandException(
+ pht('Command failed with error #%s!', $err),
+ $future->getCommand(),
+ $err,
+ $stdout,
+ $stderr);
+ }
+
+ return $this->parseTestResults($junit_file, $cover_tmp);
+ }
+
+ public function buildTestFuture($junit_tmp, $cover_tmp) {
+ $paths = $this->getPaths();
+
+ $cmd_line = csprintf('mix test --junit');
+
+ return new ExecFuture('%C', $cmd_line);
+ }
+
+ public function parseTestResults($junit_tmp, $cover_tmp) {
+ $parser = new ArcanistXUnitTestResultParser();
+ $results = $parser->parseTestResults(
+ Filesystem::readFile($junit_tmp));
+
+ return $results;
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 9, 8:52 PM (1 w, 18 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6732510
Default Alt Text
D14430.id35011.diff (7 KB)
Attached To
Mode
D14430: Add linting and unit testing support for Elixir
Attached
Detach File
Event Timeline
Log In to Comment