]> khamidou — GitHub mirrors - arcanist.git/commitdiff
If the Script-and-Regex linter captures no "line" text, treat the message as affectin...
authorepriestley <git@epriestley.com>
Tue, 12 Jan 2016 01:18:58 +0000 (17:18 -0800)
committerepriestley <git@epriestley.com>
Tue, 12 Jan 2016 01:37:34 +0000 (17:37 -0800)
Summary: Fixes T10124.

Test Plan:
Added this "linter" to `.arclint`:

```
    "thing": {
      "type": "script-and-regex",
      "script-and-regex.script": "echo every file is very bad #",
      "script-and-regex.regex": "/^(?P<message>.*)/"
    }
```

...to produce this diff. Also made a variant of it which matches lines to make sure that still works.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10124

Differential Revision: https://secure.phabricator.com/D15000

src/lint/linter/ArcanistScriptAndRegexLinter.php

index ca8883cbbbe79413ae8242134814860f08360621..0c3d9d9a11ca00e8d6eda36cf6df872b0a22ceb4 100644 (file)
  *     not specified, defaults to the linted file. It is generally not necessary
  *     to capture this unless the linter can raise messages in files other than
  *     the one it is linting.
- *   - `line` (optional) The line number of the message.
+ *   - `line` (optional) The line number of the message. If no text is
+ *     captured, the message is assumed to affect the entire file.
  *   - `char` (optional) The character offset of the message.
  *   - `offset` (optional) The byte offset of the message. If captured, this
  *     supersedes `line` and `char`.
@@ -324,7 +325,7 @@ final class ArcanistScriptAndRegexLinter extends ArcanistLinter {
    * Get the line and character of the message from the regex match.
    *
    * @param dict Captured groups from regex.
-   * @return pair<int,int|null> Line and character of the message.
+   * @return pair<int|null,int|null> Line and character of the message.
    *
    * @task parse
    */
@@ -337,10 +338,13 @@ final class ArcanistScriptAndRegexLinter extends ArcanistLinter {
     }
 
     $line = idx($match, 'line');
-    if ($line) {
+    if (strlen($line)) {
       $line = (int)$line;
+      if (!$line) {
+        $line = 1;
+      }
     } else {
-      $line = 1;
+      $line = null;
     }
 
     $char = idx($match, 'char');