Use PHP_CodeSniffer as a formatter
parent
552d645cc4
commit
8de18847ee
|
@ -46,12 +46,12 @@ class Formatter
|
||||||
do {
|
do {
|
||||||
$default = $currentDir . DIRECTORY_SEPARATOR . 'phpcs.xml';
|
$default = $currentDir . DIRECTORY_SEPARATOR . 'phpcs.xml';
|
||||||
if (is_file($default) === true) {
|
if (is_file($default) === true) {
|
||||||
return array($default);
|
return [$default];
|
||||||
}
|
}
|
||||||
|
|
||||||
$default = $currentDir . DIRECTORY_SEPARATOR . 'phpcs.xml.dist';
|
$default = $currentDir . DIRECTORY_SEPARATOR . 'phpcs.xml.dist';
|
||||||
if (is_file($default) === true) {
|
if (is_file($default) === true) {
|
||||||
return array($default);
|
return [$default];
|
||||||
}
|
}
|
||||||
|
|
||||||
$lastDir = $currentDir;
|
$lastDir = $currentDir;
|
||||||
|
|
|
@ -23,7 +23,7 @@ class TextEdit
|
||||||
*/
|
*/
|
||||||
public $newText;
|
public $newText;
|
||||||
|
|
||||||
public function __construct(Range $range = null, string $newText)
|
public function __construct(Range $range = null, string $newText = null)
|
||||||
{
|
{
|
||||||
$this->range = $range;
|
$this->range = $range;
|
||||||
$this->newText = $newText;
|
$this->newText = $newText;
|
||||||
|
|
|
@ -41,10 +41,6 @@ function pathToUri(string $filepath): string {
|
||||||
*/
|
*/
|
||||||
function uriToPath(string $uri)
|
function uriToPath(string $uri)
|
||||||
{
|
{
|
||||||
$position = strpos($uri, '://');
|
$path = urldecode(parse_url($uri)['path']);
|
||||||
if (! $position) {
|
return strpos($path, ':') ? str_replace(\DIRECTORY_SEPARATOR, '\\', substr($path, 1)) : $path;
|
||||||
return $uri;
|
|
||||||
}
|
|
||||||
$path = substr($uri, $position + 3);
|
|
||||||
return strpos($path, ':') ? str_replace('/', "\\", substr($path, 1)) : $path;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ class FormatterTest extends TestCase
|
||||||
$input = file_get_contents(__DIR__ . '/../fixtures/format.php');
|
$input = file_get_contents(__DIR__ . '/../fixtures/format.php');
|
||||||
$output = file_get_contents(__DIR__ . '/../fixtures/format_expected.php');
|
$output = file_get_contents(__DIR__ . '/../fixtures/format_expected.php');
|
||||||
|
|
||||||
$edits = $formatter->format($input, "whatever");
|
$edits = $formatter->format($input, 'whatever');
|
||||||
$this->assertTrue($edits[0]->newText === $output);
|
$this->assertTrue($edits[0]->newText === $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class FormatterTest extends TestCase
|
||||||
$formatter = new Formatter();
|
$formatter = new Formatter();
|
||||||
$expected = file_get_contents(__DIR__ . '/../fixtures/format_expected.php');
|
$expected = file_get_contents(__DIR__ . '/../fixtures/format_expected.php');
|
||||||
|
|
||||||
$edits = $formatter->format($expected, "whatever");
|
$edits = $formatter->format($expected, 'whatever');
|
||||||
$this->assertTrue($edits == []);
|
$this->assertTrue($edits == []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,24 +34,24 @@ class FileUriTest extends TestCase
|
||||||
$this->assertEquals('file:///c%3A/foo/bar.baz', $uri);
|
$this->assertEquals('file:///c%3A/foo/bar.baz', $uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUriToPathUnix()
|
public function testUriToPath()
|
||||||
{
|
{
|
||||||
$uri = "file:///home/foo/bar/Test.php";
|
$uri = 'file:///var/log';
|
||||||
$this->assertEquals("/home/foo/bar/Test.php", \LanguageServer\uriToPath($uri));
|
$this->assertEquals('/var/log', \LanguageServer\uriToPath($uri));
|
||||||
|
|
||||||
$uri = "/home/foo/bar/Test.php";
|
$uri = 'file:///usr/local/bin';
|
||||||
$this->assertEquals("/home/foo/bar/Test.php", \LanguageServer\uriToPath($uri));
|
$this->assertEquals('/usr/local/bin', \LanguageServer\uriToPath($uri));
|
||||||
|
|
||||||
$uri = "/home/foo space/bar/Test.php";
|
$uri = 'file:///d/e/f';
|
||||||
$this->assertEquals("/home/foo space/bar/Test.php", \LanguageServer\uriToPath($uri));
|
$this->assertEquals('/d/e/f', \LanguageServer\uriToPath($uri));
|
||||||
}
|
|
||||||
|
|
||||||
public function testUriToPathWindows()
|
$uri = 'file:///a/b/c/test.txt';
|
||||||
{
|
$this->assertEquals('/a/b/c/test.txt', \LanguageServer\uriToPath($uri));
|
||||||
$uri = "file:///c:/home/foo/bar/Test.php";
|
|
||||||
$this->assertEquals("c:\\home\\foo\\bar\\Test.php", \LanguageServer\uriToPath($uri));
|
|
||||||
|
|
||||||
$uri = "c:\\home\\foo\\bar\\Test.php";
|
$uri = 'file:///c%3A/foo/bar.baz';
|
||||||
$this->assertEquals("c:\\home\\foo\\bar\\Test.php", \LanguageServer\uriToPath($uri));
|
$this->assertEquals('c:\\foo\\bar.baz', \LanguageServer\uriToPath($uri));
|
||||||
|
|
||||||
|
$uri = 'file:///c%3A/path/to/file/d%C3%BCr%C3%BCm+d%C3%B6ner.php';
|
||||||
|
$this->assertEquals('c:\\path\\to\\file\\dürüm döner.php', \LanguageServer\uriToPath($uri));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue