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
import/order: don't force new line on specific pathGroup #1746
Comments
Disabling alphabetization on a specific group (even when it's enabled on all the groups) is absolutely an option that makes sense to me; a PR is welcome. It also maybe seems reasonable for |
Do you prefer to only disable alphabetization on a specific group or to define a specific alphabetization for a group, the same way the global alphabetization is defined? I'm happy to take a go at this! On the subject of the newline, I thought an alternative could be to define it on the |
When I read this the first time, what I understood was disabling alphabetization on a specific |
re the alphabetization: good point; really it needs to apply to the whole group, which does make the schema tricky. We could extend Re the newlines, in a similar way, I think the setting needs to go on the group, not the pathGroup - the point of |
I understand your point on the whole logic on groups, and I agree with the part on alphabetization. I think having the groups support objects for additional settings is a good approach. The newlines part, however, is a bit more tricky, because when we define I'm sorry if I'm only coming up with problems and not much of a good suggestion, but I've only started recently to use this plugin and don't have such a big picture of the use cases 😅 |
I'm still not clear on what a good solution would be. I'm happy to review a PR, but I don't want to suggest that just yet because we might discover that all the code needs to be thrown out and replaced with another approach :-) |
This comment has been minimized.
This comment has been minimized.
It is will be good soluion "with-newline": false |
Just an FYI if someone is searching for a solution, this was partially fixed in #2395. The |
Interested in this feature. This is my config: const config = {
alphabetize: { order: 'asc' },
groups: ['builtin', 'external', 'internal', ['parent', 'sibling', 'index']],
pathGroups: [
{
pattern: '{react,react-*,react-*/**}',
group: 'builtin',
position: 'before'
},
{
pattern: '{cozy-*,cozy-*/**}',
group: 'external',
position: 'after'
}
],
distinctGroup: true,
pathGroupsExcludedImportTypes: [
'{react,react-*,react-*/**,cozy-*,cozy-*/**}'
],
'newlines-between': 'always',
warnOnUnassignedImports: true
} It will lint succeed on import order looking exactly like that: import React from 'react'
import cx from 'classnames'
import PropTypes from 'prop-types'
import Icon, { iconPropType } from 'cozy-ui/transpiled/react/Icon'
import { makeStyles } from 'cozy-ui/transpiled/react/styles'
import Account from '../../assets/icons/Account.svg' but what I really want is this, as you can see the only difference is that React has no newline after it, but it's still on top, while the cozy-** imports still have their newline after them: import React from 'react'
import cx from 'classnames'
import PropTypes from 'prop-types'
import Icon, { iconPropType } from 'cozy-ui/transpiled/react/Icon'
import { makeStyles } from 'cozy-ui/transpiled/react/styles'
import Account from '../../assets/icons/Account.svg' In terms of API I'm not sure, I've seen "with-newline" suggested. I think that would be good for me, but maybe using Like: {
pattern: '{react,react-*,react-*/**}',
group: 'builtin',
position: 'before',
distinctGroup: false
}, In any case, is this feature something you would like to add? I'm interested in implementing it if we can find a suitable API? |
The "help wanted" label indicates that. I agree that a suitable schema would need to be decided in order to implement it. |
I would like to be able to have a specific
pathGroup
that doesn't force a newline.My objective would be to have the imports ordered in the following manner (with
react
before all, but together with theexternal
imports):At the moment I have this config:
Which forces me to alphabetize all the imports, to something like this:
The only alternative I find is to add a specific
pathGroup
forreact
, with:But this forces me to have a line between the
react
import and all otherexternal
imports.Is there a way to have a specific
pathGroup
without newlines at the end?As an alternative, I would be ok with not alphabetizing the imports on the
external
group, but I don't think this is possible either.The text was updated successfully, but these errors were encountered: