prettier / prettier/prettier

The rangeStart and rangeEnd of prettier.format do not take work

Open
#14,692 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:ranges lang:css/scss/less
Dominant language
JavaScript
Stars
52.3k
Forks
5k
Avg merge
19h 2m
Merged PRs (30d)
117

Description

Environments:

  • Prettier Version: 2.8.7
  • Running Prettier via: Node.js API
  • Runtime:Node.js v16.13.1
  • Operating System: Windows
  • Prettier plugins : prettier

Steps to reproduce:

  1. test text (index.less | scss | css)
.d42-visible {
        display: block;
}
.d42-visible {
  display: block;
}
.d42-visible {
    display: block; 
}

.d42-visible {
  display: block;
}
  1. code
prettier.format(text, {
  tabWidth: 2,
  useTabs: false,
  rangeStart: 76,
  rangeEnd: 112,
  parser: 'less'
})

Expected behavior:
Remove extra spaces in the third d42-visible

Actual behavior:
The text has not been entered with any changes

PS:(question)

  1. The following judgments are undefined.
    AW1@0PCTUBRDYDIWNNNT2N4

2.Why can't rangeStart be equal to 0? The cursor position I obtained through codemirror can start at 0
image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied LESS sample through the prettier.format Node.js API with rangeStart 76 and rangeEnd 112, then compare the output with the expected formatting of the third d42-visible block. Done means the selected range is formatted as expected and the documented behavior for a rangeStart of 0 is clarified or covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.