Closed shalev-kaveh closed 12 months ago
I would like to provide an additional use case for such a rule. I have a singleton configuration object that needs to be imported on the very first line.
// This import MUST be placed before any other app code
import './config';
import { registerRootComponent } from 'expo';
import App from './App';
// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
// It also ensures that whether you load the app in Expo Go or in a native build,
// the environment is set up appropriately
registerRootComponent(App);
Sorry @ayusharma or @byara for the ping, but do you think you'll have a chance to review this PR anytime soon ? https://github.com/trivago/prettier-plugin-sort-imports/pull/237
This PR solves this issue in the simplest way (Sorting will be ignored if we detect this comment : // sort-imports-ignore
)
I'll be happy to help if you need to chance something.
Thanks for your work and your time 🙏
EDIT: Here's a workaround until this feature is implemented.
You can configure the sorting rules, so if you want, you can have the local imports first. Perhaps add a prefix to ensure those are always first, like './!setup-env-vars.ts'
// sort ./!* files first, then normal modules, followed by local files
importOrder: ['^[.]\\/!', '<THIRD_PARTY_MODULES>', '^[.]\\/'],
Although I prefer to avoid relying on side-effects, at least with this naming convention, it will signal to the developer that this is a special file.
I would love to see an ignore rule. The suggested solution, sorting relative first, is absolutely not what I want.
Look, I was just trying to offer a workaround since the plugin doesn't currently support this use case. Not sure why I got the downvotes. I never said we don't need this.
Also, it's not all relative files first, just ones that have the special prefix. Everything else is sorted at the end.
Resolved at https://github.com/trivago/prettier-plugin-sort-imports/pull/237 Thanks!
No new release yet though... :-/
TY!
TY
Is your feature request related to a problem? Yes, I can't ignore this plugin only on certain files. To ignore import sort, we need to ignore it via
.prettierignore
, therefore ignoring prettifying the whole file.Describe the solution you'd like A clear and concise description of what you want to happen.
Describe alternatives you've considered I suggest a simple fixup, similar to other sort imports plugins provide: https://github.com/simonhaenisch/prettier-plugin-organize-imports/blob/d5ac2f4f2dba549a5a55bf05b3f2f0360e2358e4/index.js#L14
Files containing the substring
// sort-imports-ignore
or// tslint:disable:sort-imports
will be skipped.So files with the
sort imports ignore
comment won't be reordered, e.g.Additional context A follow-up on: https://github.com/trivago/prettier-plugin-sort-imports/issues/26 due to the large demand by the community