-
Notifications
You must be signed in to change notification settings - Fork 29
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
Sort use by length #22
Comments
Out of curiosity, why sorting by length ? Personally I like to sort alphabetically because this reduces the chances of merge conflicts when many people work on the same file: If everyone added Also, sorting alphabetically naturally groups use statements with common namespaces together. |
In the Laravel community it's a common convention. It's mainly aesthetic, but as you noted it still reduces merge conflicts. When you're mostly working with small classes with just a few use statements there isn't much of a benefit to grouping statements with relevant namespaces, so I don't mind going with the more aesthetic option. I also think when visually examining use statements I typically am only looking at the actual class name, and sorting by length makes it easier to do that. Take for example: use App\Apples\Foo\Bar\Baz;
use App\Bar;
use App\Charlie\Delta\Foo\Bar\Baz\Product;
use App\Foo\Green;
use App\Foo\Yellow\Foo\Bar\Order; Not only does this look ugly, but if you're just looking at the class names your eyes are constantly moving left to right to find the end of the line. Now look at this: use App\Bar;
use App\Foo\Green;
use App\Apples\Foo\Bar\Baz;
use App\Foo\Yellow\Foo\Bar\Order;
use App\Charlie\Delta\Foo\Bar\Baz\Product; Your eyes only have to gradually move right to find the class name. |
Makes sense, thanks. Replacing |
you can set: let g:php_namespace_sort = "'{,'}-1!awk '{print length, $0}' | sort -n -s | cut -d' ' -f2-" |
The new sort function is great (and much easier than other solutions I've found that require selecting the lines manually), but an option to sort by line length would be another awesome addition.
The text was updated successfully, but these errors were encountered: