sort imports does ignore prettier-ignore statements
See original GitHub issueYour Environment
- Prettier version: 2.4.1 / 2.2.1 (both in yarn lock)
- node version: v17.0.1
- package manager: yarn@2
- IDE: Webstorm
- **prettier-plugin-sort-import: 3.1.1 Describe the bug
To Reproduce
Add the prettier config and add a new js or ts file. There add one import to the top that does not belong to the top usually and try to make it stay at the top via // prettier-ignore (and variants).
Expected behavior When ordering imports I would expect it to be possible to ignore imports that need to be at a certain position (e.g. why-did-you-render wanting to be imported at the top). The prettier-ignore should not be ignored.
Screenshots, code sample, etc
// prettier-ignore-start
import "../../scripts/wdyr"; // must be first import!
// prettier-ignore-end
import { ApolloProvider } from "@apollo/client";
import React from "react";
turns into
// prettier-ignore-start
// must be first import!
// prettier-ignore-end
import { ApolloProvider } from "@apollo/client";
import React from "react";
import "../../scripts/wdyr";
and
// prettier-ignore
import "../../scripts/wdyr"; // must be first import!
import { ApolloProvider } from "@apollo/client";
import React from "react";
turns into
// prettier-ignore
// must be first import!
import { ApolloProvider } from "@apollo/client";
import React from "react";
import "../../scripts/wdyr";
As can be seen, the first import does not stay the first import.
Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)
module.exports = {
  importOrder: ["^@/(.*)$", "^[./]"],
  importOrderSeparation: true,
};
Error log No log.
Contribute to @trivago/prettier-plugin-sort-imports
- I’m willing to fix this bug 🥇 (if provided a bit of guidance where to look)
PS: I think I will add an alias @scripts and change the sorting for it to appear at the top. Then maybe importing @scripts/wdyr will stay.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:23
- Comments:12 (3 by maintainers)

 Top Related Medium Post
Top Related Medium Post Top Related StackOverflow Question
Top Related StackOverflow Question
yeah, too bad we can’t use this plugin without this fix 😭
@denik1981 If it’s only the side-effect imports for which you want to preserve the order, you could try this fork https://www.npmjs.com/package/@ianvs/prettier-plugin-sort-imports which includes the PR I made that was not accepted. (Seeing that many people seem to be affected, any chance that PR can get merged? Possibly by incrementing the major version?)
Also, based on how that PR handles side effects, it would be possible to implement ignore comments by marking imports with such a comment as a “side-effect import”.