-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Sniff to Evaluate Usages of imports #1
Comments
@mikeselander Just to make sure we're talking about the same thing: use function MyNamespace\myFunction; // Error.
use function Vendor\YourNamespace\yourFunction as FunctionAlias; // OK.
use function foo\math\sin, foo\math\cos as FooCos, foo\math\cosh; // Error, OK, Error.
use function bar\math\{
Msin, // Error.
level\Mcos as BarCos, // OK.
Mcosh, // Error.
}; Is that what you mean ? |
@jrfnl yes, that's exactly what I meant ❤️ |
@mikeselander In that case: done ;-) It will take a few more weeks before I can put it online as I need PHPCSUtils to be completely online first (and tagged), but you can expect the sniff to be available soonish (via this repo). |
@mikeselander FYI: the implementation I've chosen to go with is as follows:
You can either include the complete sniff or just include a single error code like The sniffs will generate metrics which can be viewed via the The sniff does not currently contain a fixer. |
@jrfnl I don't quite understand how you got that done so fast, but I'm properly impressed 👏 That all looks well-structured and I wouldn't have expected a fixer for this myself. Thank you so much! |
@mikeselander The secret is in the PHPCSUtils utility methods ;-) Basically all the logic needed was already in place, all I needed to do in the sniff was call the appropriate utility method 😀 |
@mikeselander The PRs I just pulled should sort this issue out. Testing appreciated. #7, #8, #9 |
Amazing, thank you! I'll try them out on our ruleset as time allows in the next few weeks. |
@mikeselander Great, let me know how you get on. I was thinking of maybe adding a third error code to the sniffs for when non-namespaced entities are being imported. That way you could use that error code to just forbid non-aliased imports from the global namespace, but allow aliased and namespaced imports. What do you think ? |
@jrfnl that makes a lot of sense to me 👍 |
@mikeselander I've implemented my suggestion above and ended up making the sniffs even more modular. See PR #25, which I've just merged. I've added four new error codes to each of the sniffs:
In all other circumstances, the pre-existing error codes I've also added this information to the metric which can be viewed using
|
I would very much like a sniff that allows you to specifically allow/disallow usage of types of imports and usage of said imports. This sniff could detect types of imports and aliasing or not of imports within files.
Scenario 1:
I want to limit the usage of
use function
, but still allow the usage ofuse {namespace}
oruse const
in our ruleset.Scenario 2:
I want to limit the usage of
use function
, but allowuse function {name} as {moreSpecificName}
aliasing.The most important (for my needs) and, I assume, easiest implementation is just to flag types of importing that are disallowed in a codebases. Do ping me if any of this is confusing or ambiguous!
The text was updated successfully, but these errors were encountered: