-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
739 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Indent\LaravelLinter\Linters; | ||
|
||
use Closure; | ||
use PhpParser\Node; | ||
use PhpParser\Node\Name; | ||
use Tighten\TLint\BaseLinter; | ||
use Tighten\TLint\Concerns\IdentifiesFacades; | ||
|
||
class ImportFacades extends BaseLinter | ||
{ | ||
use IdentifiesFacades; | ||
|
||
public const DESCRIPTION = "Import facades (don't use aliases)."; | ||
|
||
protected function visitor(): Closure | ||
{ | ||
return function (Node $node) { | ||
static $hasNamespace = false; | ||
|
||
if ($node instanceof Node\Stmt\Namespace_) { | ||
$hasNamespace = true; | ||
} | ||
|
||
static $useNames = []; | ||
static $useAliases = []; | ||
|
||
if ($node instanceof Node\Stmt\GroupUse) { | ||
foreach ($node->uses as $use) { | ||
$useNames[] = Name::concat($node->prefix, $use->name)->toString(); | ||
$useAliases[] = $use->getAlias(); | ||
} | ||
} elseif ($node instanceof Node\Stmt\UseUse) { | ||
$useNames[] = $node->name->toString(); | ||
$useAliases[] = $node->getAlias(); | ||
} | ||
|
||
return $node instanceof Node\Expr\StaticCall | ||
&& $hasNamespace | ||
&& $node->class instanceof Node\Name | ||
&& in_array($node->class->toString(), array_keys(static::$aliases), false) | ||
&& ! in_array($node->class->toString(), $useAliases, false) | ||
&& ! in_array(static::$aliases[$node->class->toString()], $useNames, false); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Indent\LaravelLinter\Linters; | ||
|
||
use Closure; | ||
use PhpParser\Node; | ||
use PhpParser\Node\Expr\FuncCall; | ||
use Tighten\TLint\BaseLinter; | ||
use Tighten\TLint\Linters\Concerns\LintsControllers; | ||
|
||
class NoCompact extends BaseLinter | ||
{ | ||
use LintsControllers; | ||
|
||
public const DESCRIPTION = 'There should be no calls to `compact()` in controllers'; | ||
|
||
protected function visitor(): Closure | ||
{ | ||
return function (Node $node) { | ||
return $node instanceof FuncCall && ! empty($node->name->parts) && $node->name->parts[0] === 'compact'; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Indent\LaravelLinter\Linters; | ||
|
||
use Closure; | ||
use PhpParser\Node; | ||
use PhpParser\Node\Expr\FuncCall; | ||
use PhpParser\Node\Identifier; | ||
use Tighten\TLint\BaseLinter; | ||
|
||
class NoDump extends BaseLinter | ||
{ | ||
public const DESCRIPTION = 'There should be no calls to `dd()`, `dump()`, `ray()`, or `var_dump()`'; | ||
|
||
protected function visitor(): Closure | ||
{ | ||
return function (Node $node) { | ||
return ($node instanceof FuncCall && ! empty($node->name->parts) && in_array($node->name->parts[0], ['dd', 'dump', 'var_dump', 'ray'], true)) | ||
|| ($node instanceof Identifier && in_array($node->name, ['dump', 'dd'], true)); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Indent\LaravelLinter\Linters; | ||
|
||
use Closure; | ||
use PhpParser\Node; | ||
use Tighten\TLint\BaseLinter; | ||
|
||
class NoStringInterpolationWithoutBraces extends BaseLinter | ||
{ | ||
public const DESCRIPTION = 'Never use string interpolation without braces'; | ||
|
||
protected function visitor(): Closure | ||
{ | ||
return function (Node $node) { | ||
if ($node instanceof Node\Scalar\Encapsed) { | ||
foreach ($node->parts as $part) { | ||
if ($part instanceof Node\Expr\Variable) { | ||
$line = $this->getCodeLinesFromNode($node); | ||
$name = $part->name; | ||
|
||
return ! (strpos($line, "{\${$name}}") !== false); | ||
} elseif ($part instanceof Node\Expr\PropertyFetch) { | ||
$line = $this->getCodeLinesFromNode($node); | ||
$propertyFetchString = $this->constructPropertyFetchString($part); | ||
|
||
return ! (strpos($line, "{\${$propertyFetchString}") !== false); | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
}; | ||
} | ||
|
||
private function constructPropertyFetchString($next, $string = '') | ||
{ | ||
if (property_exists($next, 'var')) { | ||
return $this->constructPropertyFetchString( | ||
$next->var, | ||
$next->name->name . ($string ? ('->' . $string) : $string) | ||
); | ||
} | ||
|
||
return $next->name . '->' . $string; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Indent\LaravelLinter\Linters; | ||
|
||
use Closure; | ||
use PhpParser\Node; | ||
use Tighten\TLint\BaseLinter; | ||
use Tighten\TLint\Linters\Concerns\LintsNonConfigFiles; | ||
|
||
class UseConfigOverEnv extends BaseLinter | ||
{ | ||
use LintsNonConfigFiles; | ||
|
||
public const DESCRIPTION = 'Don’t use environment variables directly; instead, use them in config files and call config vars from code'; | ||
|
||
protected function visitor(): Closure | ||
{ | ||
return function (Node $node) { | ||
return $node instanceof Node\Expr\FuncCall | ||
&& $node->name instanceof Node\Name | ||
&& $node->name->toString() === 'env'; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.