mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-25 16:22:42 +01:00
Make spell check linter patching
Test Plan: Wrote "Posible" in the linter, let it change to "Possible". New unit test. Reviewers: jack, epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3469
This commit is contained in:
parent
918eff8ff9
commit
9dd1a87066
2 changed files with 39 additions and 2 deletions
|
@ -111,6 +111,8 @@ final class ArcanistSpellingLinter extends ArcanistLinter {
|
||||||
if ($next === false) {
|
if ($next === false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$original = substr($text, $next, strlen($word));
|
||||||
|
$replacement = self::fixLetterCase($correct_word, $original);
|
||||||
$this->raiseLintAtOffset(
|
$this->raiseLintAtOffset(
|
||||||
$next,
|
$next,
|
||||||
$severity,
|
$severity,
|
||||||
|
@ -118,7 +120,9 @@ final class ArcanistSpellingLinter extends ArcanistLinter {
|
||||||
"Possible spelling error. You wrote '%s', but did you mean '%s'?",
|
"Possible spelling error. You wrote '%s', but did you mean '%s'?",
|
||||||
$word,
|
$word,
|
||||||
$correct_word
|
$correct_word
|
||||||
)
|
),
|
||||||
|
$original,
|
||||||
|
$replacement
|
||||||
);
|
);
|
||||||
$pos = $next + 1;
|
$pos = $next + 1;
|
||||||
}
|
}
|
||||||
|
@ -137,6 +141,8 @@ final class ArcanistSpellingLinter extends ArcanistLinter {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
foreach ($matches[0] as $match) {
|
foreach ($matches[0] as $match) {
|
||||||
|
$original = $match[0];
|
||||||
|
$replacement = self::fixLetterCase($correct_word, $original);
|
||||||
$this->raiseLintAtOffset(
|
$this->raiseLintAtOffset(
|
||||||
$match[1],
|
$match[1],
|
||||||
$severity,
|
$severity,
|
||||||
|
@ -144,8 +150,24 @@ final class ArcanistSpellingLinter extends ArcanistLinter {
|
||||||
"Possible spelling error. You wrote '%s', but did you mean '%s'?",
|
"Possible spelling error. You wrote '%s', but did you mean '%s'?",
|
||||||
$word,
|
$word,
|
||||||
$correct_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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,4 +35,19 @@ final class ArcanistSpellingLinterTestCase extends ArcanistLinterTestCase {
|
||||||
$working_copy);
|
$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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue