Repository: tightenco/tlint (php)

Issue:
No `dd` lint

Pull request description:
Add linter `NoDd`
Added a linter to check for calls to `dd()`, and tests to go with it. This PR fixes #26.

Patch:
diff --git a/src/Commands/LintCommand.php b/src/Commands/LintCommand.php
index 704b19a..58e6c7d 100644
--- a/src/Commands/LintCommand.php
+++ b/src/Commands/LintCommand.php
@@ -23,6 +23,7 @@ use Tighten\Linters\ClassThingsOrder;
 use Tighten\Linters\ImportFacades;
 use Tighten\Linters\MailableMethodsInBuild;
 use Tighten\Linters\ModelMethodOrder;
+use Tighten\Linters\NoDd;
 use Tighten\Linters\NoDocBlocksForMigrationUpDown;
 use Tighten\Linters\NoLeadingSlashesOnRoutePaths;
 use Tighten\Linters\NoParensEmptyInstantiations;
@@ -304,6 +305,7 @@ class LintCommand extends Command
                 OneLineBetweenClassVisibilityChanges::class => '.php',
                 NoStringInterpolationWithoutBraces::class => '.php',
                 ConcatenationSpacing::class => '.php',
+                NoDd::class => '.php',
             ],
             $this->getRoutesFilesLinters($path),
             $this->getControllerFilesLinters($path),
diff --git a/src/Linters/NoDd.php b/src/Linters/NoDd.php
new file mode 100644
index 0000000..c73d701
--- /dev/null
+++ b/src/Linters/NoDd.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Tighten\Linters;
+
+use PhpParser\Node;
+use PhpParser\Node\Expr\FuncCall;
+use PhpParser\NodeTraverser;
+use PhpParser\NodeVisitor\FindingVisitor;
+use PhpParser\Parser;
+use Tighten\BaseLinter;
+
+class NoDd extends BaseLinter
+{
+    protected $description = 'There should be no calls to `dd()`';
+
+    public function lint(Parser $parser)
+    {
+        $traverser = new NodeTraverser;
+
+        $visitor = new FindingVisitor(function (Node $node) {
+            return $node instanceof FuncCall && $node->name->parts[0] === 'dd';
+        });
+
+        $traverser->addVisitor($visitor);
+
+        $traverser->traverse($parser->parse($this->code));
+
+        return $visitor->getFoundNodes();
+    }
+}


Test patch:
diff --git a/tests/Linters/NoDdTest.php b/tests/Linters/NoDdTest.php
new file mode 100644
index 0000000..2f8eefa
--- /dev/null
+++ b/tests/Linters/NoDdTest.php
@@ -0,0 +1,48 @@
+<?php
+
+use PHPUnit\Framework\TestCase;
+use Tighten\Linters\NoDd;
+use Tighten\TLint;
+
+class NoDdTest extends TestCase
+{
+    /** @test */
+    public function catches_dd_call()
+    {
+        $file = <<<file
+<?php
+
+\$foo = "abc";
+dd(\$foo);
+
+file;
+
+        $lints = (new TLint)->lint(
+            new NoDd($file)
+        );
+
+        $this->assertEquals(4, $lints[0]->getNode()->getLine());
+    }
+
+    /** @test */
+    public function does_not_trigger_on_dd_call_in_comments()
+    {
+        $file = <<<file
+<?php
+
+\$foo = "abc";
+//dd(\$foo);
+
+/**
+* dd(\$foo);
+*/
+
+file;
+
+        $lints = (new TLint)->lint(
+            new NoDd($file)
+        );
+
+        $this->assertEmpty($lints);
+    }
+}