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

Unnecessary line breaks when importOrderSeparation feature is enabled #58

Closed itsjavi closed 1 year ago

itsjavi commented 1 year ago

Your Environment

Describe the bug Under certain situations (like in the screenshot), extra unnecessary empty lines are added in PHPStorm when importOrderSeparation feature is enabled.

To Reproduce

  1. enable importOrderSeparation or add empty strings in the importOrder array
  2. Enable "Run prettier on save" and/or "Run prettier on reformat code" in PHPStorm
    • It doesn't matter if "ESLint fix on save" is enabled or not
  3. Reformat code and save

Expected behavior

No unnecessary new lines should appear.

Screenshots, code sample, etc

image

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

// .prettierrc
{
  "semi": false,
  "printWidth": 100,
  "trailingComma": "es5",
  "tabWidth": 2,
  "singleQuote": true,
  "arrowParens": "avoid",
  "jsxSingleQuote": false,
  "plugins": [
    "@ianvs/prettier-plugin-sort-imports"
  ],
  "importOrderSeparation": true,
  "importOrder": [
    "^[Rr]eact(.*)$",
    "^@?next(.*)$",
    "^@app/(.*)$",
    "^@/(.*)$",
    "^[./]"
  ],
  "importOrderBuiltinModulesToTop": true,
  "importOrderCaseInsensitive": true,
  "importOrderParserPlugins": [
    "typescript",
    "jsx",
    "decorators-legacy"
  ],
  "importOrderMergeDuplicateImports": true,
  "importOrderCombineTypeAndValueImports": true,
  "importOrderSortSpecifiers": false
}
// .eslintrc.json
{
  // "extends": ["next", "turbo", "next/core-web-vitals", "prettier"],
  "extends": ["next", "turbo", "next/core-web-vitals", "prettier"],
  "plugins": ["react-hooks"],
  "rules": {
    // "@next/next/no-html-link-for-pages": "off",
    // images
    "@next/next/no-img-element": "warn",
    "jsx-a11y/alt-text": "error",
    // components
    "react-hooks/exhaustive-deps": "off",
    "react-hooks/rules-of-hooks": "error",
    "react/jsx-key": "error",
    "react/no-unescaped-entities": "off"
  }
}
itsjavi commented 1 year ago

It seems more an IDE issue when "Optimize Imports" is enabled when reformatting code. I think it can be closed

IanVS commented 1 year ago

Thanks for reporting back!