Skip to content

Commit 32dbef8

Browse files
committedNov 16, 2023
feat: add side-effect-style import group
1 parent 75cd84f commit 32dbef8

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed
 

‎docs/rules/sort-imports.md

+3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ type Group =
9999
| 'parent'
100100
| 'sibling'
101101
| 'side-effect'
102+
| 'side-effect-style'
102103
| 'index'
103104
| 'object'
104105
| 'style'
@@ -170,6 +171,8 @@ import formatNumber from '../utils/format-number'
170171
import config from './config'
171172
// 'side-effect' - Side effect imports
172173
import './set-production-env.js'
174+
// side-effect-style - Side effect style imports
175+
import './styles.scss'
173176
// 'index' - Main file from the current directory
174177
import main from '.'
175178
// 'object' - TypeScript object-imports

‎rules/sort-imports.ts

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export enum NewlinesBetweenValue {
3232
}
3333

3434
type Group<T extends string[]> =
35+
| 'side-effect-style'
3536
| 'external-type'
3637
| 'internal-type'
3738
| 'builtin-type'
@@ -308,6 +309,10 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
308309
if (node.type === 'ImportDeclaration') {
309310
setCustomGroups(options['custom-groups'].value, node.source.value)
310311

312+
if (isSideEffectImport(node) && isStyle(node.source.value)) {
313+
defineGroup('side-effect-style')
314+
}
315+
311316
if (isSideEffectImport(node)) {
312317
defineGroup('side-effect')
313318
}

‎test/sort-imports.test.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -3736,10 +3736,12 @@ describe(RULE_NAME, () => {
37363736
import { useClient } from '~/hooks/useClient'
37373737
37383738
import '~/css/globals.css'
3739+
3740+
import '~/data'
37393741
`,
37403742
options: [
37413743
{
3742-
groups: ['internal', 'side-effect'],
3744+
groups: ['internal', 'side-effect-style', 'side-effect'],
37433745
},
37443746
],
37453747
},
@@ -3748,24 +3750,27 @@ describe(RULE_NAME, () => {
37483750
{
37493751
code: dedent`
37503752
import { useClient } from '~/hooks/useClient'
3753+
import '~/data'
37513754
import '~/css/globals.css'
37523755
`,
37533756
output: dedent`
37543757
import { useClient } from '~/hooks/useClient'
37553758
37563759
import '~/css/globals.css'
3760+
3761+
import '~/data'
37573762
`,
37583763
options: [
37593764
{
3760-
groups: ['internal', 'side-effect'],
3765+
groups: ['internal', 'side-effect-style', 'side-effect'],
37613766
},
37623767
],
37633768
errors: [
37643769
{
37653770
messageId: 'missedSpacingBetweenImports',
37663771
data: {
37673772
left: '~/hooks/useClient',
3768-
right: '~/css/globals.css',
3773+
right: '~/data',
37693774
},
37703775
},
37713776
],

0 commit comments

Comments
 (0)
Please sign in to comment.