Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F22680256
D18814.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D18814.diff
View Options
diff --git a/src/lint/linter/ArcanistTextLinter.php b/src/lint/linter/ArcanistTextLinter.php
--- a/src/lint/linter/ArcanistTextLinter.php
+++ b/src/lint/linter/ArcanistTextLinter.php
@@ -16,6 +16,7 @@
const LINT_EMPTY_FILE = 10;
private $maxLineLength = 80;
+ private $trailingWhitespaceNonEmptyOnly = false;
public function getInfoName() {
return pht('Basic Text Linter');
@@ -39,6 +40,13 @@
'Adjust the maximum line length before a warning is raised. By '.
'default, a warning is raised on lines exceeding 80 characters.'),
),
+ 'text.trailing-whitespace-non-empty-only' => array(
+ 'type' => 'optional bool',
+ 'help' => pht(
+ 'Only raise a warning for trailing whitespace on non-empty lines.'.
+ 'By default, a warning is raised for all lines with trailing '.
+ 'whitespace.'),
+ ),
);
return $options + parent::getLinterConfigurationOptions();
@@ -49,11 +57,19 @@
return $this;
}
+ public function setTrailingWhitespaceNonEmptyOnly($new_non_empty_only) {
+ $this->trailingWhitespaceNonEmptyOnly = $new_non_empty_only;
+ return $this;
+ }
+
public function setLinterConfigurationValue($key, $value) {
switch ($key) {
case 'text.max-line-length':
$this->setMaxLineLength($value);
return;
+ case 'text.trailing-whitespace-non-empty-only':
+ $this->setTrailingWhitespaceNonEmptyOnly($value);
+ return;
}
return parent::setLinterConfigurationValue($key, $value);
@@ -241,11 +257,18 @@
}
protected function lintTrailingWhitespace($path) {
+ $non_empty_only = $this->trailingWhitespaceNonEmptyOnly;
+ if ($non_empty_only) {
+ $pattern = '/[^[:space:]]+([[:blank:]]+)$/m';
+ } else {
+ $pattern = '/[[:blank:]]+$/m';
+ }
+
$data = $this->getData($path);
$matches = null;
$preg = preg_match_all(
- '/[[:blank:]]+$/m',
+ $pattern,
$data,
$matches,
PREG_OFFSET_CAPTURE);
@@ -254,7 +277,12 @@
return;
}
- foreach ($matches[0] as $match) {
+ if ($non_empty_only) {
+ $whitespace_matches = $matches[1];
+ } else {
+ $whitespace_matches = $matches[0];
+ }
+ foreach ($whitespace_matches as $match) {
list($string, $offset) = $match;
$this->raiseLintAtOffset(
$offset,
diff --git a/src/lint/linter/__tests__/text/trailing-whitespace-4.lint-test b/src/lint/linter/__tests__/text/trailing-whitespace-4.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/__tests__/text/trailing-whitespace-4.lint-test
@@ -0,0 +1,23 @@
+Lorem ipsum dolor sit amet,
+
+consectetur adipiscing elit.
+
+Phasellus sodales nibh erat,
+
+in hendrerit nulla dictum interdum.
+~~~~~~~~~~
+error:1:28
+autofix:1:28
+autofix:3:29
+autofix:5:29
+autofix:7:36
+~~~~~~~~~~
+Lorem ipsum dolor sit amet,
+
+consectetur adipiscing elit.
+
+Phasellus sodales nibh erat,
+
+in hendrerit nulla dictum interdum.
+~~~~~~~~~~
+{"config": {"text.trailing-whitespace-non-empty-only": true}}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Oct 3, 1:44 AM (18 h, 17 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
17037830
Default Alt Text
D18814.diff (3 KB)
Attached To
Mode
D18814: Add a option to lint trailing whitespace only on non-empty lines
Attached
Detach File
Event Timeline
Log In to Comment