trivago / prettier-plugin-sort-imports

A prettier plugin to sort imports in typescript and javascript files by the provided RegEx order.
Apache License 2.0
3.37k stars 133 forks source link

whitespace on top #115

Open artola opened 2 years ago

artola commented 2 years ago

Your Environment

Describe the bug

The plugin removes the whitespace before the imports' block, but it should not be affected at all.

To Reproduce

Input:

/* istanbul ignore file */

import foo from 'foo';

Output:

/* istanbul ignore file */
import foo from 'foo';

Expected behavior

/* istanbul ignore file */

import foo from 'foo';

Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)

{
  "printWidth": 80,
  "tabWidth": 2,
  "useTabs": false,
  "semi": true,
  "singleQuote": true,
  "trailingComma": "all",
  "bracketSpacing": false,
  "jsxBracketSameLine": false,
  "arrowParens": "always",
  "importOrder": ["^@(.*)/(.*)$", "^#/(.*)$", "^[./]"],
  "importOrderSeparation": true,
  "importOrderSortSpecifiers": true
}
artola commented 2 years ago

@byara The "input" example above is properly handled by Prettier (if several lines added between the comment and the first import, then just 1 empty line remains) but once added this plugin, it removes all the whitespace. Same behaviour using single or multi-line comments (// ... or /* ... */).

JuhG commented 2 years ago

Looks like this PR wanted to fix this issue: https://github.com/trivago/prettier-plugin-sort-imports/pull/24 @ayusharma @byara Can you provide any info why that PR was closed? Is this planned to be fixed? Thanks!

g1eny0ung commented 2 years ago

Looks like this PR wanted to fix this issue: #24 @ayusharma @byara Can you provide any info why that PR was closed? Is this planned to be fixed? Thanks!

Same. Hope this feature can be considered. In the projects I work on, we put the Apache License at the top. So we want to have a blank line between it and the actual code.

Thank you for creating this project. ❤️ It's very useful.

michaelfaith commented 2 years ago

I'm seeing the same issues with copyright blocks on top of our files. It's removing the blank separator line.

skalinkin commented 1 year ago

Same problem with copyright blocks in our project.