diff --git a/src/lint/linter/ArcanistSCSSLintLinter.php b/src/lint/linter/ArcanistSCSSLintLinter.php new file mode 100644 --- /dev/null +++ b/src/lint/linter/ArcanistSCSSLintLinter.php @@ -0,0 +1,120 @@ +getExecutableCommand()); + + $matches = array(); + if (preg_match('/^scss-lint\s(?P\d+\.\d+\.\d+)$/', $stdout, + $matches)) { + return $matches['version']; + } else { + return false; + } + } + + public function getInstallInstructions() { + return pht( + 'Install %s using `%s`.', + 'SCSS-Lint', + 'gem install scss_lint'); + } + + protected function getMandatoryFlags() { + $options = array( + '--format=JSON', + ); + + if ($this->config) { + $options[] = '--config='.$this->config; + } + + return $options; + } + + public function getLinterConfigurationOptions() { + $options = array( + 'scss-lint.config' => array( + 'type' => 'optional string', + 'help' => pht('A custom configuration file.'), + ), + ); + + return $options + parent::getLinterConfigurationOptions(); + } + + public function setLinterConfigurationValue($key, $value) { + switch ($key) { + case 'scss-lint.config': + $this->config = $value; + return; + } + + return parent::setLinterConfigurationValue($key, $value); + } + + protected function parseLinterOutput($path, $err, $stdout, $stderr) { + $results = phutil_json_decode($stdout); + $messages = array(); + + foreach ($results as $path => $offenses) { + foreach ($offenses as $offense) { + $message = id(new ArcanistLintMessage()) + ->setPath($path) + ->setLine($offense['line']) + ->setChar($offense['column']) + ->setCode($offense['linter']) + ->setSeverity($this->getArcSeverity($offense['severity'])) + ->setName($this->getLinterName()) + ->setDescription($offense['reason']); + + $messages[] = $message; + } + } + + return $messages; + } + + private function getArcSeverity($severity) { + switch ($severity) { + case 'warning': + return ArcanistLintSeverity::SEVERITY_WARNING; + + case 'error': + return ArcanistLintSeverity::SEVERITY_ERROR; + + default: + return ArcanistLintSeverity::SEVERITY_ADVICE; + } + } + +} diff --git a/src/lint/linter/__tests__/ArcanistSCSSLintLinterTestCase.php b/src/lint/linter/__tests__/ArcanistSCSSLintLinterTestCase.php new file mode 100644 --- /dev/null +++ b/src/lint/linter/__tests__/ArcanistSCSSLintLinterTestCase.php @@ -0,0 +1,10 @@ +executeTestsInDirectory(dirname(__FILE__).'/scss-lint/'); + } + +} diff --git a/src/lint/linter/__tests__/scss-lint/no_errors.lint-test.scss b/src/lint/linter/__tests__/scss-lint/no_errors.lint-test.scss new file mode 100644 --- /dev/null +++ b/src/lint/linter/__tests__/scss-lint/no_errors.lint-test.scss @@ -0,0 +1,4 @@ +.module { + color: #fff; +} +~~~~~~~~~ diff --git a/src/lint/linter/__tests__/scss-lint/warning.lint-test.scss b/src/lint/linter/__tests__/scss-lint/warning.lint-test.scss new file mode 100644 --- /dev/null +++ b/src/lint/linter/__tests__/scss-lint/warning.lint-test.scss @@ -0,0 +1,5 @@ +.module { + border: none; +} +~~~~~~~~~ +warning:2:3