Page MenuHomePhabricator

D16085.id38702.diff
No OneTemporary

D16085.id38702.diff

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 $allowUTF8 = 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.allow-utf8' => array(
+ 'type' => 'optional bool',
+ 'help' => pht(
+ 'Allow any valid UTF-8 character. By default, only ASCII bytes '.
+ 'with ordinal decimal values between 32 and 126 inclusive, plus '.
+ 'linefeed are allowed.'),
+ ),
);
return $options + parent::getLinterConfigurationOptions();
@@ -54,6 +62,9 @@
case 'text.max-line-length':
$this->setMaxLineLength($value);
return;
+ case 'text.allow-utf8':
+ $this->allowUTF8 = $value;
+ return;
}
return parent::setLinterConfigurationValue($key, $value);
@@ -149,6 +160,7 @@
protected function lintNewlines($path) {
$data = $this->getData($path);
+ $allow_utf8 = $this->allowUTF8;
$pos = strpos($this->getData($path), "\r");
if ($pos !== false) {
@@ -210,11 +222,21 @@
protected function lintCharset($path) {
$data = $this->getData($path);
+ $allow_utf8 = $this->allowUTF8;
$matches = null;
- $bad = '[^\x09\x0A\x20-\x7E]';
+ // Allow newline, tab, 32 to 126, Letters, Marks, Numbers,
+ // Punctuation and Symbols
+ $bad_utf8 = '[^\x09\x0A\x20-\x7E\p{L}\p{M}\p{N}\p{P}\p{S}]';
+ $bad_utf8_regex = "/{$bad_utf8}(.*{$bad_utf8})?/u";
+
+ $bad_ascii = '[^\x09\x0A\x20-\x7E]';
+ $bad_ascii_regex = "/{$bad_ascii}(.*{$bad_ascii})?/";
+
+ $bad_regex = ($allow_utf8 ? $bad_utf8_regex : $bad_ascii_regex);
+
$preg = preg_match_all(
- "/{$bad}(.*{$bad})?/",
+ $bad_regex,
$data,
$matches,
PREG_OFFSET_CAPTURE);
@@ -223,15 +245,21 @@
return;
}
+ $bad_ascii_help_text = pht('Source code should contain only ASCII bytes '.
+ 'with ordinal decimal values between 32 and 126 inclusive, plus '.
+ 'linefeed. Do not use UTF-8 or other multibyte charsets.');
+
+ $bad_utf8_help_text = pht('Source code should contain only printable '.
+ 'UTF-8 characters.');
+
+ $help_text = ($allow_utf8 ? $bad_utf8_help_text : $bad_ascii_help_text);
+
foreach ($matches[0] as $match) {
list($string, $offset) = $match;
$this->raiseLintAtOffset(
$offset,
self::LINT_BAD_CHARSET,
- pht(
- 'Source code should contain only ASCII bytes with ordinal '.
- 'decimal values between 32 and 126 inclusive, plus linefeed. '.
- 'Do not use UTF-8 or other multibyte charsets.'),
+ $help_text,
$string);
}

File Metadata

Mime Type
text/plain
Expires
Sat, Mar 15, 12:25 PM (1 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7527999
Default Alt Text
D16085.id38702.diff (2 KB)

Event Timeline