IanVS / prettier-plugin-sort-imports

An opinionated but flexible prettier plugin to sort import statements
Apache License 2.0
1.02k stars 25 forks source link

Imports with special regex are not moved to end group #46

Closed obriankevin11 closed 2 years ago

obriankevin11 commented 2 years ago

Hi!

I'm having the following issue: Imports containing ".css" string are not moved to end group

Configuration

To Reproduce

tsx file:

import './test.css'
import '@lib/tables/dist/bla.css'
import * as React from 'react';
import { FormattedMessage } from 'react-intl';
import { Foo } from 'types/models'

.prettierrc

  "importOrder": [
    "(react|redux)",
    "(components|pages)/(.*)$",
    "<THIRD_PARTY_MODULES>",
    "(\\.css)"
  ],
  "importOrderBuiltinModulesToTop": true,
  "importOrderCaseInsensitive": true,
  "importOrderMergeDuplicateImports": true,
  "importOrderCombineTypeAndValueImports": true,
  "importOrderSeparation": true,
  "importOrderSortSpecifiers": true

Result

import './test.css';
import '@lib/tables/dist/bla.css';

import { Foo } from 'types/models';

import * as React from 'react';
import { FormattedMessage } from 'react-intl';

Expected behavior

import * as React from 'react';
import { FormattedMessage } from 'react-intl';

import { Foo } from 'types/models';

import './test.css';
import '@lib/tables/dist/bla.css';

Thank you!

IanVS commented 2 years ago

@obriankevin11 Could you try using ".css$" as the pattern, instead of "(\\.css)"?

fbartho commented 2 years ago

I wonder if side-effect-only-imports are an edge case that isn’t being sorted fully?

fbartho commented 2 years ago

I think side-effect-imports might be assumed to have a purpose in a specific order?

IanVS commented 2 years ago

Oh, I missed that it was a side effect import. Yes, we do not sort side effect imports, since in general it is not safe to do so. I'm closing since this is working as intended, but happy to chat more about it with you @obriankevin11.

obriankevin11 commented 2 years ago

ok I understand but is there a way to bypass side-effect-only-imports rule/restriction as I know it won't have side effects? it would be nice to have the choice :)

IanVS commented 2 years ago

No, sorry but there is not. You can use the @trivago plugin that this is forked from. It does not treat side effect nodes differently from others.