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

It doesn't respect the order under group #17

Open
nowycondro opened this issue Aug 9, 2019 · 4 comments
Open

It doesn't respect the order under group #17

nowycondro opened this issue Aug 9, 2019 · 4 comments

Comments

@nowycondro
Copy link

Lets say I have this configuration

'rules': {
      'import-helpers/order-imports': ['error',
        {
          newlinesBetween: 'always',
          groups: ['module', ['/aaa/', '/bbb/', '/ccc/']],
        },
      ],
    },
import {...} from '@external-module';

import {...} from '../ccc/';  // <= It doesn't complain about this line. It suppose to be placed after '/bbb/'.
import {...} from '../aaa/';
import {...} from '../bbb/';

import {...} from '../../somewhere/local';
@willhoney7
Copy link
Owner

Hi!

So, currently, ordering within a subgroup is not enforced. In your example, /aaa/, /bbb/, and /ccc/ are merged into a single group.

Since you do not have the alphabetize setting, the rule will allow you to do any order of imports within that subgroup. If you set alphabetize: { order: 'asc', ignoreCase: true }, you will get your desired order... However that only works because your desired order in this example is alphabetical order.

It sounds like you think the order of the items in a subgroup should be enforced? Hmm, I can see the value in that... I personally prefer to sort alphabetically for all groups. I'm on the fence. Any additional arguments for/against it?

@nowycondro
Copy link
Author

In the beginning I though the behavior of Regex should be the same other group (e.g, parent, siblings, etc). It took me quite sometime to realise it doesn't respect the order for Regex.

In my case, alphabetically sort doesn't solve the problem

groups: [
      'module', 
      [
             '/name/',
             '/relatively_short_folder_name/',
             '/a_extremely_long_folder_name_that_is_hard_to_read/'
      ]
],

In other case, it might be sort by string length 🤷‍♂ and lead me to think is there any possibility to allow custom sort function as an item under groups.

function sort(a, b) {
    // sort the import whatever you want 
}
...
groups: ['module', sort];
...

@mateushnsoares
Copy link

mateushnsoares commented Aug 19, 2020

In the beginning I though the behavior of Regex should be the same other group (e.g, parent, siblings, etc). It took me quite sometime to realise it doesn't respect the order for Regex.

In my case, alphabetically sort doesn't solve the problem

groups: [
      'module', 
      [
             '/name/',
             '/relatively_short_folder_name/',
             '/a_extremely_long_folder_name_that_is_hard_to_read/'
      ]
],

In other case, it might be sort by string length 🤷‍♂ and lead me to think is there any possibility to allow custom sort function as an item under groups.

function sort(a, b) {
    // sort the import whatever you want 
}
...
groups: ['module', sort];
...

Good idea but sometimes is not necessary. I suppose that beyond it this rule should support an Object like this:

  "groups": [
    {
      "group": [
          "some_same_values_here"
       ],
       "order": "asc|desc|asc-by-type|desc-by-type" // default is alphabetize.order
     }
  ]

@ssharifdev
Copy link

ssharifdev commented Sep 10, 2021

any update on this @Tibfib ?

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

No branches or pull requests

4 participants