Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unused use statement rule #801

Open
alexwhitman opened this issue Dec 3, 2015 · 9 comments · May be fixed by #1106
Open

Unused use statement rule #801

alexwhitman opened this issue Dec 3, 2015 · 9 comments · May be fixed by #1106

Comments

@alexwhitman
Copy link

Is there a rule to detect unused use statements? For example:

<?php

use Foo\Bar;
use Foo\Baz; // This should be detected as unused

class MyClass
{
    public function doSomething(Bar $bar)
    {
        // .....
    }
}

PHP-CS-Fixer has an unused_use fixer but I'd prefer to use the one tool if possible.

@aik099
Copy link
Contributor

aik099 commented Dec 3, 2015

Nope.

For a questions you can use our Gitter channel: https://gitter.im/squizlabs/PHP_CodeSniffer

@klausi
Copy link
Contributor

klausi commented Dec 28, 2015

There is a sniff for that in Drupal's coder: https://www.drupal.org/project/coder

@ExplodingCabbage
Copy link

I just wanted this feature and was considering writing my own sniff. @klausi, as the owner of coder would you have any objection to PHPCS nicking the UnusedUseStatementSniff and putting it into the generic section of PHPCS? It looks pretty solid to my (non-expert) eye, and I'm sure that more people would be able to benefit from it if it were put into the core of PHPCS; I'd prefer not to replicate your work by writing my own to PR into here.

(If you're okay with it, I'm also interested to look over coder for other non-Drupal-specific sniffs that could happily live in PHPCS and start migrating them. It looks like you've got a lot of cool stuff over there!)

@klausi
Copy link
Contributor

klausi commented Aug 7, 2016

Coder is GPLv2+ licensed and PHPCS is MIT, so you need to get copyright permission from all authors of a sniff when you want to pull in sniffs from Coder to PHPCS for MIT relicensing. Which is totally fine with me, so you have my permission to do that. In the case of UnusedUseStatementSniff we also need to ask @alexpott (the only other author).

@alexpott
Copy link

alexpott commented Aug 7, 2016

Fine by me.

@ExplodingCabbage ExplodingCabbage linked a pull request Aug 8, 2016 that will close this issue
6 tasks
@patrickallaert
Copy link

Looks like @alexpott agreed, can it be included?
Thanks in advance.

@ExplodingCabbage
Copy link

@TomasVotruba
Copy link
Contributor

Alread in no_unused_imports [@Symfony]: https://github.com/friendsofphp/php-cs-fixer

@juuuuuu
Copy link

juuuuuu commented Jan 20, 2021

I think this issue can be closed. Or is it still in disucssion? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.

9 participants