Skip to content

Commit

Permalink
Feat: Add NoUnneededImportAliasFixer (part of #94)
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed May 23, 2024
1 parent f36ad7f commit 00687a4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
use PhpCsFixer\Fixer\FunctionNotation\ReturnTypeDeclarationFixer;
use PhpCsFixer\Fixer\FunctionNotation\VoidReturnFixer;
use PhpCsFixer\Fixer\Import\NoLeadingImportSlashFixer;
use PhpCsFixer\Fixer\Import\NoUnneededImportAliasFixer;
use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
use PhpCsFixer\Fixer\Import\OrderedImportsFixer;
use PhpCsFixer\Fixer\LanguageConstruct\DeclareEqualNormalizeFixer;
Expand Down Expand Up @@ -281,13 +282,15 @@
ReturnTypeDeclarationFixer::class,

VoidReturnFixer::class,

// Remove leading slashes in `use` clauses.
NoLeadingImportSlashFixer::class,

// Imports should not be aliased as the same name.
NoUnneededImportAliasFixer::class,
// Unused `use` statements must be removed.
NoUnusedImportsFixer::class,

// Order `use` statements.
OrderedImportsFixer::class,

// Equal sign in declare statement should not be surrounded by spaces.
DeclareEqualNormalizeFixer::class,
// Replaces `is_null($var)` expression with `null === $var`
IsNullFixer::class,
Expand Down
5 changes: 5 additions & 0 deletions tests/Integration/Fixtures/Basic.correct.php.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php declare(strict_types=1);

use Bar\Foo; // NoUnneededImportAliasFixer

class Basic
{
public const FOO = 'foo'; // ClassAttributesSeparationFixer
Expand All @@ -20,6 +22,9 @@ class Basic
$className = DateTime::class;
// ClassReferenceNameCasingFixer
$date = new \DateTime();

$aliasedClass = new Foo();

// SingleSpaceAfterConstructFixer, StrictComparisonFixer
if ($a === $b || $bazLength !== 3) {
return true;
Expand Down
5 changes: 5 additions & 0 deletions tests/Integration/Fixtures/Basic.wrong.php.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Bar\Foo as Foo; // NoUnneededImportAliasFixer

class Basic
{
const FOO = 'foo'; // ClassAttributesSeparationFixer
Expand All @@ -19,6 +21,9 @@ class Basic
$className = DateTime :: class;
// ClassReferenceNameCasingFixer
$date = new \datetime();

$aliasedClass = new Foo();

// SingleSpaceAfterConstructFixer, StrictComparisonFixer
if ($a == $b || $bazLength != 3) { return true; }
return false; // BlankLineBeforeStatementFixer
Expand Down

0 comments on commit 00687a4

Please sign in to comment.