Skip to content

Commit

Permalink
feat: add side-effect-style import group
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Nov 16, 2023
1 parent 75cd84f commit 32dbef8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/rules/sort-imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type Group =
| 'parent'
| 'sibling'
| 'side-effect'
| 'side-effect-style'
| 'index'
| 'object'
| 'style'
Expand Down Expand Up @@ -170,6 +171,8 @@ import formatNumber from '../utils/format-number'
import config from './config'
// 'side-effect' - Side effect imports
import './set-production-env.js'
// side-effect-style - Side effect style imports
import './styles.scss'
// 'index' - Main file from the current directory
import main from '.'
// 'object' - TypeScript object-imports
Expand Down
5 changes: 5 additions & 0 deletions rules/sort-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export enum NewlinesBetweenValue {
}

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

if (isSideEffectImport(node) && isStyle(node.source.value)) {
defineGroup('side-effect-style')
}

if (isSideEffectImport(node)) {
defineGroup('side-effect')
}
Expand Down
11 changes: 8 additions & 3 deletions test/sort-imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3736,10 +3736,12 @@ describe(RULE_NAME, () => {
import { useClient } from '~/hooks/useClient'
import '~/css/globals.css'
import '~/data'
`,
options: [
{
groups: ['internal', 'side-effect'],
groups: ['internal', 'side-effect-style', 'side-effect'],
},
],
},
Expand All @@ -3748,24 +3750,27 @@ describe(RULE_NAME, () => {
{
code: dedent`
import { useClient } from '~/hooks/useClient'
import '~/data'
import '~/css/globals.css'
`,
output: dedent`
import { useClient } from '~/hooks/useClient'
import '~/css/globals.css'
import '~/data'
`,
options: [
{
groups: ['internal', 'side-effect'],
groups: ['internal', 'side-effect-style', 'side-effect'],
},
],
errors: [
{
messageId: 'missedSpacingBetweenImports',
data: {
left: '~/hooks/useClient',
right: '~/css/globals.css',
right: '~/data',
},
},
],
Expand Down

0 comments on commit 32dbef8

Please sign in to comment.