diff --git a/src/lint/linter/ArcanistSpellingLinter.php b/src/lint/linter/ArcanistSpellingLinter.php index 7d043238..bfd81f6a 100644 --- a/src/lint/linter/ArcanistSpellingLinter.php +++ b/src/lint/linter/ArcanistSpellingLinter.php @@ -111,6 +111,8 @@ final class ArcanistSpellingLinter extends ArcanistLinter { if ($next === false) { return; } + $original = substr($text, $next, strlen($word)); + $replacement = self::fixLetterCase($correct_word, $original); $this->raiseLintAtOffset( $next, $severity, @@ -118,7 +120,9 @@ final class ArcanistSpellingLinter extends ArcanistLinter { "Possible spelling error. You wrote '%s', but did you mean '%s'?", $word, $correct_word - ) + ), + $original, + $replacement ); $pos = $next + 1; } @@ -137,6 +141,8 @@ final class ArcanistSpellingLinter extends ArcanistLinter { return; } foreach ($matches[0] as $match) { + $original = $match[0]; + $replacement = self::fixLetterCase($correct_word, $original); $this->raiseLintAtOffset( $match[1], $severity, @@ -144,8 +150,24 @@ final class ArcanistSpellingLinter extends ArcanistLinter { "Possible spelling error. You wrote '%s', but did you mean '%s'?", $word, $correct_word - ) + ), + $original, + $replacement ); } } + + public static function fixLetterCase($string, $case) { + if ($case == strtolower($case)) { + return strtolower($string); + } + if ($case == strtoupper($case)) { + return strtoupper($string); + } + if ($case == ucwords(strtolower($case))) { + return ucwords(strtolower($string)); + } + return null; + } + } diff --git a/src/lint/linter/__tests__/ArcanistSpellingLinterTestCase.php b/src/lint/linter/__tests__/ArcanistSpellingLinterTestCase.php index 7afe118e..0cd4c3e4 100644 --- a/src/lint/linter/__tests__/ArcanistSpellingLinterTestCase.php +++ b/src/lint/linter/__tests__/ArcanistSpellingLinterTestCase.php @@ -35,4 +35,19 @@ final class ArcanistSpellingLinterTestCase extends ArcanistLinterTestCase { $working_copy); } + public function testFixLetterCase() { + $tests = array( + 'tst' => 'test', + 'Tst' => 'Test', + 'TST' => 'TEST', + 'tSt' => null, + ); + foreach ($tests as $case => $expect) { + foreach (array('test', 'TEST') as $string) { + $result = ArcanistSpellingLinter::fixLetterCase($string, $case); + $this->assertEqual($expect, $result, $case); + } + } + } + }