Skip to content

Range formatting of imports introduces extra spacing #212

@denbezrukov

Description

@denbezrukov

Your Environment

  • Prettier version: 3.5.3
  • node version: 20
  • package manager: npm@10
  • IDE: WebStorm & CLI

Describe the bug

When using --range-start / --range-end to format for example a single import statement.
Extra blank lines are added after the import.

To Reproduce

  1. Install dependencies:

    {
      "devDependencies": {
        "@ianvs/prettier-plugin-sort-imports": "^4.4.1",
        "prettier": "^3.5.3",
        "typescript": "^5.4.3"
      },
    }
  2. Create a file hello.ts:

import { Component, OnInit } from "@angular/core";

//
  1. Create config
trailingComma: "es5"
semi: true
singleQuote: false
arrowParens: always
bracketSpacing: true
quoteProps: as-needed
htmlWhitespaceSensitivity: ignore
plugins:
  - "@ianvs/prettier-plugin-sort-imports"
importOrderParserPlugins:
  - "typescript"
  - "classProperties"
  - "decorators"
importOrder:
  - "^@angular(/.*)?$"
  - ""
  - "^primeng(/.*)?$"
  - ""
  - <THIRD_PARTY_MODULES>
  - ""
  - "^@app(/.*)?$"
  - ""
  - "^(\\.).*$"
importOrderTypeScriptVersion: 4.7.4
  1. Run Prettier with this command:
prettier --range-start=0 --range-end=53 hello.ts
  1. Actual output:
import { Component, OnInit } from "@angular/core";



//

Expected behavior

import { Component, OnInit } from "@angular/core";

//

Error log

No error — just unexpected formatting.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions