tlint icon indicating copy to clipboard operation
tlint copied to clipboard

`AlphabeticalImports` reports imported functions at the end as not alphabetically sorted

Open Gummibeer opened this issue 2 years ago • 5 comments

use Closure;
use Illuminate\Http\Request;
use Sentry\State\Scope;
use function Sentry\configureScope;

This is reported by the AlphabeticalImports rule - I assume that it's because of the imported function at the end!? Is this intended? So should the function be imported between the classes to be alphabetical?

Gummibeer avatar Apr 27 '22 14:04 Gummibeer

Interesting. To fix the lint, yes, function namespaces and names should be sorted alphabetically mixed in with classes. Not sure what we actually want here though.

Does adding a blank line between the class and function use statements make the lint go away? Apparently under PSR-12 they should actually be used separately: https://www.php-fig.org/psr/psr-12/#3-declare-statements-namespace-and-import-statements.

bakerkretzmar avatar May 01 '22 03:05 bakerkretzmar

We've worked around it by using the container binding instead of global helper function. 🙈 So no real issue for us anymore. And you are absolutely right that there should be a spacing line between the import types.

Will give it try with the spacing line.

Gummibeer avatar May 04 '22 16:05 Gummibeer

Okay, spacing line doesn't help.

use Closure;
use Illuminate\Http\Request;
use Sentry\State\HubInterface;
use Sentry\State\Scope;

use function Sentry\configureScope;

! Imports should be ordered alphabetically. 5 : use Closure;

Gummibeer avatar May 04 '22 16:05 Gummibeer

Good to know, thanks 👍🏻

bakerkretzmar avatar May 04 '22 16:05 bakerkretzmar

For me to reference later:

  • Related to blank line https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/6365
  • Add to standards

driftingly avatar May 06 '22 15:05 driftingly