Skip to content

Commit

Permalink
Update linter and linter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
driftingly committed Nov 22, 2024
1 parent 09ca23d commit 38e0871
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Linters/OneLineBetweenClassVisibilityChanges.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function lint(Parser $parser)
continue;
}

// Ignore nodes with exactly the same visibility
if ($previousNode->flags === $node->flags) {
// If the two nodes are the same type and have the same visibility skip
if ($previousNode::class === $node::class && $previousNode->flags === $node->flags) {
$previousNode = $node;

continue;
Expand Down
34 changes: 34 additions & 0 deletions tests/Linting/Linters/OneLineBetweenClassVisibilityChangesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Thing
{
protected const OK = 1;
private $ok;
private $dokey;
}
file;

Expand All @@ -45,6 +46,7 @@ class Thing
* The description of something.
*/
private $ok;
private $dokey;
}
file;

Expand All @@ -71,6 +73,7 @@ class Thing
* The description of something.
*/
private $ok;
private $dokey;
}
file;

Expand All @@ -94,6 +97,7 @@ class Thing
protected const OK = 1;
// Note to self
private $ok;
private $dokey;
}
file;

Expand All @@ -118,6 +122,7 @@ class Thing
// Note to self
// Another
private $ok;
private $dokey;
}
file;

Expand All @@ -144,6 +149,7 @@ class Thing
// And another
// And another one
private $ok;
private $dokey;
}
file;

Expand All @@ -168,6 +174,7 @@ class Thing
// TODO
private $ok;
private $dokey;
}
file;

Expand All @@ -192,6 +199,7 @@ class Thing
// public const NOT_OK = 2;
private $ok;
private $dokey;
}
file;

Expand Down Expand Up @@ -222,6 +230,7 @@ class Thing
// Hi there
//
private $ok;
private $dokey;
}
file;

Expand All @@ -231,4 +240,29 @@ class Thing

$this->assertEmpty($lints);
}

/** @test */
public function catches_missing_line_between_types()
{
$file = <<<'file'
<?php
namespace App;
class Thing
{
protected const OK = 1;
protected $bar;
private $ok;
private $dokey;
}
file;

$lints = (new TLint)->lint(
new OneLineBetweenClassVisibilityChanges($file)
);

$this->assertEquals(8, $lints[0]->getNode()->getLine());
$this->assertEquals(9, $lints[1]->getNode()->getLine());
}
}

0 comments on commit 38e0871

Please sign in to comment.