Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12239884
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/.arcconfig b/.arcconfig
index 2c8becc..4aa932a 100644
--- a/.arcconfig
+++ b/.arcconfig
@@ -1,4 +1,7 @@
{
"phabricator.uri": "https://devcentral.nasqueron.org/",
- "repository.callsign": "SCL"
+ "repository.callsign": "SCL",
+ "load": [
+ "shellcheck-linter"
+ ]
}
diff --git a/.arcunit b/.arcunit
new file mode 100644
index 0000000..860ee1a
--- /dev/null
+++ b/.arcunit
@@ -0,0 +1,8 @@
+{
+ "engines": {
+ "phutil": {
+ "type": "phutil",
+ "include": "(\\.php$)"
+ }
+ }
+}
diff --git a/__phutil_library_map__.php b/__phutil_library_map__.php
index 68d26f7..4c473e8 100644
--- a/__phutil_library_map__.php
+++ b/__phutil_library_map__.php
@@ -1,18 +1,20 @@
<?php
/**
* This file is automatically generated. Use 'arc liberate' to rebuild it.
*
* @generated
* @phutil-library-version 2
*/
phutil_register_library_map(array(
'__library_version__' => 2,
'class' => array(
'ArcanistShellCheckLinter' => 'lint/linter/ArcanistShellCheckLinter.php',
+ 'ArcanistShellCheckLinterTestCase' => 'lint/linter/__tests__/ArcanistShellCheckLinterTestCase.php',
),
'function' => array(),
'xmap' => array(
'ArcanistShellCheckLinter' => 'ArcanistExternalLinter',
+ 'ArcanistShellCheckLinterTestCase' => 'PhutilTestCase',
),
));
diff --git a/lint/linter/ArcanistShellCheckLinter.php b/lint/linter/ArcanistShellCheckLinter.php
index 25ed4b2..a97158d 100644
--- a/lint/linter/ArcanistShellCheckLinter.php
+++ b/lint/linter/ArcanistShellCheckLinter.php
@@ -1,162 +1,162 @@
<?php
final class ArcanistShellCheckLinter extends ArcanistExternalLinter {
private $shell;
private $exclude;
public function getInfoName() {
return 'ShellCheck';
}
public function getInfoURI() {
return 'http://www.shellcheck.net/';
}
public function getInfoDescription() {
return pht(
'ShellCheck is a static analysis and linting tool for %s scripts.',
'sh/bash');
}
public function getLinterName() {
return 'SHELLCHECK';
}
public function getLinterConfigurationName() {
return 'shellcheck';
}
public function getLinterConfigurationOptions() {
$options = array(
'shellcheck.shell' => array(
'type' => 'optional string',
'help' => pht(
'Specify shell dialect (%s, %s, %s, %s).',
'bash',
'sh',
'ksh',
'zsh'),
),
'shellcheck.exclude' => array(
'type' => 'optional list<string>',
'help' => pht('Specify excluded checks, e.g.: SC2035.'),
),
);
return $options + parent::getLinterConfigurationOptions();
}
public function setLinterConfigurationValue($key, $value) {
switch ($key) {
case 'shellcheck.shell':
$this->setShell($value);
return;
case 'shellcheck.exclude':
$this->setExclude($value);
return;
default:
return parent::setLinterConfigurationValue($key, $value);
}
}
public function setShell($shell) {
$this->shell = $shell;
return $this;
}
public function setExclude($exclude) {
$this->exclude = $exclude;
return $this;
}
public function getDefaultBinary() {
return 'shellcheck';
}
public function getInstallInstructions() {
return pht(
'Install ShellCheck with `%s`.',
'cabal install shellcheck');
}
protected function getMandatoryFlags() {
$options = array();
$options[] = '--format=checkstyle';
if ($this->shell) {
$options[] = '--shell='.$this->shell;
}
if ($this->exclude) {
foreach ($this->exclude as $code) {
$options[] = '--exclude='.$code;
}
}
return $options;
}
public function getVersion() {
list($stdout, $stderr) = execx(
'%C --version', $this->getExecutableCommand());
$matches = null;
- if (preg_match('/^version: (\d(?:\.\d){2})$/', $stdout, $matches)) {
+ if (preg_match('/version: (\d(?:\.\d){2})/', $stdout, $matches)) {
return $matches[1];
}
return null;
}
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
$report_dom = new DOMDocument();
$ok = @$report_dom->loadXML($stdout);
if (!$ok) {
return false;
}
$files = $report_dom->getElementsByTagName('file');
$messages = array();
foreach ($files as $file) {
foreach ($file->getElementsByTagName('error') as $child) {
$code = str_replace('ShellCheck.', '', $child->getAttribute('source'));
$message = id(new ArcanistLintMessage())
->setPath($path)
->setLine($child->getAttribute('line'))
->setChar($child->getAttribute('column'))
->setName($this->getLinterName())
->setCode($code)
->setDescription($child->getAttribute('message'));
switch ($child->getAttribute('severity')) {
case 'error':
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
break;
case 'warning':
$message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
break;
case 'info':
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ADVICE);
break;
default:
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
break;
}
$messages[] = $message;
}
}
return $messages;
}
}
diff --git a/lint/linter/__tests__/ArcanistShellCheckLinterTestCase.php b/lint/linter/__tests__/ArcanistShellCheckLinterTestCase.php
new file mode 100644
index 0000000..6d917ae
--- /dev/null
+++ b/lint/linter/__tests__/ArcanistShellCheckLinterTestCase.php
@@ -0,0 +1,13 @@
+<?php
+
+final class ArcanistShellCheckLinterTestCase extends PhutilTestCase {
+
+ public function testGetVersion() {
+ $linter = new ArcanistShellCheckLinter();
+ $actualVersion = $linter->getVersion();
+
+ $this->assertFalse($actualVersion === null, "The version can't be extracted from the binary output.");
+ $this->assertTrue(strpos($actualVersion, '.') > -1, "The version doesn't match expected format: does not contain a dot.");
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Oct 12, 00:48 (1 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3059846
Default Alt Text
(6 KB)
Attached To
Mode
rSCL ShellCheck linter for Arcanist
Attached
Detach File
Event Timeline
Log In to Comment