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

Fix Imports should not change order of use groups unless PSR-12 order is enabled #6274

Closed
czukowski opened this issue Jul 30, 2023 · 3 comments · Fixed by #6322
Closed

Fix Imports should not change order of use groups unless PSR-12 order is enabled #6274

czukowski opened this issue Jul 30, 2023 · 3 comments · Fixed by #6322
Assignees
Labels
enhancement kind:feature A feature request PHP [ci] enable extra PHP tests (php/php.editor)
Milestone

Comments

@czukowski
Copy link
Contributor

czukowski commented Jul 30, 2023

Apache NetBeans version

Apache NetBeans 19 release candidate 3

What happened

"Put in PSR-12 order" option is used to make sure use groups (types, functions, constants) are in the correct order as required by the standard. However, the order is changed even if the option is disabled when using "Fix Imports". It probably shouldn't assume any order by default.

Also, "Put in PSR-12 order" only seems to affect "Fix Imports" and not using "Source > Format".

How to reproduce

Disable 'Put in PSR-12 order' and use 'Fix imports' with the following code:

<?php
use Generator;
use Iterator;
use ArrayIterator;
use function sort;
use function next;
use function valid;
use const SORT_NUMERIC;

Expected result:

<?php
use ArrayIterator;
use Generator;
use Iterator;
use function next;
use function sort;
use function valid;
use const SORT_NUMERIC;

Actual result:

<?php

use ArrayIterator;
use Generator;
use Iterator;
use const SORT_NUMERIC;
use function next;
use function sort;
use function valid;

Did this work correctly in an earlier version?

No

Operating System

Windows 10

JDK

18.0.2.1; OpenJDK 64-Bit Server VM 18.0.2.1+1-1

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

Low priority issue.

Are you willing to submit a pull request?

No

@czukowski czukowski added kind:bug Bug report or fix needs:triage Requires attention from one of the committers labels Jul 30, 2023
@junichi11 junichi11 added enhancement PHP [ci] enable extra PHP tests (php/php.editor) kind:feature A feature request and removed kind:bug Bug report or fix needs:triage Requires attention from one of the committers labels Jul 31, 2023
@junichi11
Copy link
Member

junichi11 commented Jul 31, 2023

Not a bug but an enhancement. (It's a correct result, currently. It's the same behavior as before.)

@junichi11 junichi11 self-assigned this Jul 31, 2023
@junichi11
Copy link
Member

It probably shouldn't assume any order by default.

At least, We need default order if there are no existing uses (or if missing use kinds are added).

@czukowski
Copy link
Contributor Author

Okay, you're right about the default order for adding use groups, but it just feels unexpected if the order of something that's already there changes suddenly. If you don't notice and fix it, then you'll have to go back and fix your commits.

I guess ideally new imports should be added in a correct order but at the same time not to make other changes to imports. But I'm not sure how achieve that in a way that wouldn't be complicated.

junichi11 added a commit to junichi11/netbeans that referenced this issue Aug 7, 2023
… possible apache#6274

- apache#6274
- Add the option (Keep existing order of use types(types, functions, constants) if possible)
- Add unit tests
@junichi11 junichi11 added this to the NB20 milestone Aug 10, 2023
junichi11 added a commit that referenced this issue Aug 30, 2023
…existing-order

Keep existing order of use type kinds(types, functions, constants) if possible #6274
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement kind:feature A feature request PHP [ci] enable extra PHP tests (php/php.editor)
Projects
None yet
2 participants