]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve autofixing of double quotes in XHPAST linter.
authorJoshua Spence <josh@joshuaspence.com>
Mon, 19 May 2014 14:49:51 +0000 (07:49 -0700)
committerepriestley <git@epriestley.com>
Mon, 19 May 2014 14:49:51 +0000 (07:49 -0700)
Summary: The XHPAST double quotes rule autofixes strings which use double quotes where single quotes would suffice. In the case in which the double-quoted string contained an escaped double quote, the autofix string can be improved by removing the escape symbol.

Test Plan: Modified existing unit tests to cover this case.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

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

src/lint/linter/ArcanistXHPASTLinter.php
src/lint/linter/__tests__/xhpast/double-quote.lint-test

index 7e364d47bec2cb800e75cdd39f1891ba8693febc..06b983b187f482bd49f2c60b79a9447cb231b7e2 100644 (file)
@@ -2428,7 +2428,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
           $valid = true;
         } else if (!$contains_special_chars && !$single_quoted) {
           $invalid_nodes[] = $string;
-          $fixes[$string->getID()] = "'".$contents."'";
+          $fixes[$string->getID()] = "'".str_replace('\"', '"', $contents)."'";
         }
       }
 
index de452462d124ae24fc6839a3537a6e3ee62eabe9..0c9f619d6de8bbdbb8ccd0a4f0c10f60e65bee94 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 'foobar';
-"foobar";
+"foo\"bar";
 "foobar\n";
 "'foobar'";
 "foo{$bar}";
@@ -16,7 +16,7 @@ advice:3:1
 ~~~~~~~~~~
 <?php
 'foobar';
-'foobar';
+'foo"bar';
 "foobar\n";
 "'foobar'";
 "foo{$bar}";