]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve `LINT_DOS_NEWLINE` behavior
authorJoshua Spence <josh@joshuaspence.com>
Wed, 24 Sep 2014 21:13:10 +0000 (07:13 +1000)
committerJoshua Spence <josh@joshuaspence.com>
Wed, 24 Sep 2014 21:14:58 +0000 (07:14 +1000)
Summary: Improve the behavior of `ArcanistTextLinter` in dealing with `LINT_DOS_NEWLINE`. In particular, provide replacement text so that these linter issues can be autofixed.

Test Plan: Added a unit test.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin

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

src/lint/linter/ArcanistTextLinter.php
src/lint/linter/__tests__/text/dos-newline.lint-test [new file with mode: 0644]

index f7d8206db4c415be376ad67bdf22713c168fc462..e1b9f6c27eead2d9da4437b49eb18b8ec261d8a0 100644 (file)
@@ -123,13 +123,17 @@ final class ArcanistTextLinter extends ArcanistLinter {
   }
 
   protected function lintNewlines($path) {
-    $pos = strpos($this->getData($path), "\r");
+    $data = $this->getData($path);
+    $pos  = strpos($this->getData($path), "\r");
+
     if ($pos !== false) {
       $this->raiseLintAtOffset(
-        $pos,
+        0,
         self::LINT_DOS_NEWLINE,
         pht('You must use ONLY Unix linebreaks ("%s") in source code.', '\n'),
-        "\r");
+        $data,
+        str_replace("\r\n", "\n", $data));
+
       if ($this->isMessageEnabled(self::LINT_DOS_NEWLINE)) {
         $this->stopAllLinters();
       }
diff --git a/src/lint/linter/__tests__/text/dos-newline.lint-test b/src/lint/linter/__tests__/text/dos-newline.lint-test
new file mode 100644 (file)
index 0000000..5ff143d
--- /dev/null
@@ -0,0 +1,7 @@
+The quick brown fox\r
+jumps over the lazy dog.\r
+~~~~~~~~~~
+error:1:1
+~~~~~~~~~~
+The quick brown fox
+jumps over the lazy dog.