Page MenuHomePhabricator

0001-Arcanist-Filename-Linter.patch.txt

Authored By
iangordon
Dec 2 2015, 10:59 PM
Size
3 KB
Referenced Files
None
Subscribers
None

0001-Arcanist-Filename-Linter.patch.txt

From 246a8bba4fe289bc0cb73e0631991a1232d05135 Mon Sep 17 00:00:00 2001
From: Ian Gordon <iangordon@google.com>
Date: Mon, 30 Nov 2015 12:06:56 -0800
Subject: [PATCH] Allow Filename linter to accept a custom Regex to test
filenames against.
---
src/lint/linter/ArcanistFilenameLinter.php | 50 ++++++++++++++++++++++++++----
1 file changed, 44 insertions(+), 6 deletions(-)
diff --git a/src/lint/linter/ArcanistFilenameLinter.php b/src/lint/linter/ArcanistFilenameLinter.php
index b9867c5ae186..428bd292beaf 100644
--- a/src/lint/linter/ArcanistFilenameLinter.php
+++ b/src/lint/linter/ArcanistFilenameLinter.php
@@ -7,14 +7,22 @@ final class ArcanistFilenameLinter extends ArcanistLinter {
const LINT_BAD_FILENAME = 1;
+ const DEFAULT_REGEX = '^[a-zA-Z0-9./\\\\_-]+$';
+ const DEFAULT_DESCRIPTION = 'Name files using only letters, numbers, period, hyphen and underscore.';
+ const REGEX_DELIMITER = '*';
+
+ private $regex = self::DEFAULT_REGEX;
+ private $description = self::DEFAULT_DESCRIPTION;
+
public function getInfoName() {
return pht('Filename');
}
public function getInfoDescription() {
return pht(
- 'Stifles developer creativity by requiring files have uninspired names '.
- 'containing only letters, numbers, period, hyphen and underscore.');
+ 'Stifles developer creativity by requiring files have uninspired '.
+ 'names, by default containing only letters, numbers, period, '.
+ 'hyphen and underscore.');
}
public function getLinterName() {
@@ -25,6 +33,34 @@ final class ArcanistFilenameLinter extends ArcanistLinter {
return 'filename';
}
+ public function getLinterConfigurationOptions() {
+ $options = array(
+ 'filename.regex' => array(
+ 'type' => 'optional string',
+ 'help' => pht(
+ 'Set the regex pattern that filenames must match. By default, '.
+ ' we check against: ' . self::DEFAULT_REGEX),
+ ),
+ );
+
+ return $options + parent::getLinterConfigurationOptions();
+ }
+
+ public function setRegex($new_regex) {
+ $this->regex = $new_regex;
+ return $this;
+ }
+
+ public function setLinterConfigurationValue($key, $value) {
+ switch ($key) {
+ case 'filename.regex':
+ $this->setRegex($value);
+ return;
+ }
+
+ return parent::setLinterConfigurationValue($key, $value);
+ }
+
protected function shouldLintBinaryFiles() {
return true;
}
@@ -36,12 +72,14 @@ final class ArcanistFilenameLinter extends ArcanistLinter {
}
public function lintPath($path) {
- if (!preg_match('@^[a-z0-9./\\\\_-]+$@i', $path)) {
+ $delimited_regex = self::REGEX_DELIMITER . $this->regex . self::REGEX_DELIMITER;
+ if (!preg_match($delimited_regex, $path)) {
+ if ($this->regex != self::DEFAULT_REGEX && $this->description == self::DEFAULT_DESCRIPTION) {
+ $this->description = pht('Regex ' . $this->regex . ' does not match: ' . $path);
+ }
$this->raiseLintAtPath(
self::LINT_BAD_FILENAME,
- pht(
- 'Name files using only letters, numbers, period, hyphen and '.
- 'underscore.'));
+ pht($this->description));
}
}
--
2.6.2

File Metadata

Mime Type
text/x-diff
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/ac/nl/3wwh7fn6bwxxj6jk
Default Alt Text
0001-Arcanist-Filename-Linter.patch.txt (3 KB)

Event Timeline