prettier / prettier/prettier

Range formatting doesn't work

Open
#16,140 1 comment 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:ranges status:needs investigation
Dominant language
JavaScript
Stars
52.3k
Forks
5k
Avg merge
19h 2m
Merged PRs (30d)
117

Description

Prettier 3.2.5
Playground link

--parser babel
--tab-width 4
--range-start 598
--range-end 678

Input:

module.exports = grammar({
    name: 'rpmspec',

    rules: {
        name: ($) =>
            choice('AutoProv', 'AutoReq', 'AutoReqProv', 'AutoRequires', 'BuildArch', 'BuildArchitectures', 'BuildConflicts', 'BuildPreReq', 'BuildRequires', 'BuildRoot', 'Conflicts', 'Distribution', 'Enhances', 'Epoch', 'ExcludeArch', 'ExclusiveArch', 'ExclusiveOS', 'Group', 'License', 'Name', 'Obsoletes', 'Packager', 'Prereq', 'Provides', 'Recommends', 'Release', 'Requires', 'Suggests', 'Summary', 'Supplements', 'URL', 'Url', 'Vendor', 'Version', /Patch\d*/, /Source\d*/),

        _value: ($) =>
            repeat(choice( $.simple_expansion, $.expansion, $.integer, $.float, $.string )),
    },
});

Output:

module.exports = grammar({
    name: "rpmspec",

    rules: {
        name: ($) =>
            choice(
                "AutoProv",
                "AutoReq",
                "AutoReqProv",
                "AutoRequires",
                "BuildArch",
                "BuildArchitectures",
                "BuildConflicts",
                "BuildPreReq",
                "BuildRequires",
                "BuildRoot",
                "Conflicts",
                "Distribution",
                "Enhances",
                "Epoch",
                "ExcludeArch",
                "ExclusiveArch",
                "ExclusiveOS",
                "Group",
                "License",
                "Name",
                "Obsoletes",
                "Packager",
                "Prereq",
                "Provides",
                "Recommends",
                "Release",
                "Requires",
                "Suggests",
                "Summary",
                "Supplements",
                "URL",
                "Url",
                "Vendor",
                "Version",
                /Patch\d*/,
                /Source\d*/,
            ),

        _value: ($) =>
            repeat(
                choice(
                    $.simple_expansion,
                    $.expansion,
                    $.integer,
                    $.float,
                    $.string,
                ),
            ),
    },
});

Expected output:

module.exports = grammar({
    name: 'rpmspec',

    rules: {
        name: ($) =>
            choice('AutoProv', 'AutoReq', 'AutoReqProv', 'AutoRequires', 'BuildArch', 'BuildArchitectures', 'BuildConflicts', 'BuildPreReq', 'BuildRequires', 'BuildRoot', 'Conflicts', 'Distribution', 'Enhances', 'Epoch', 'ExcludeArch', 'ExclusiveArch', 'ExclusiveOS', 'Group', 'License', 'Name', 'Obsoletes', 'Packager', 'Prereq', 'Provides', 'Recommends', 'Release', 'Requires', 'Suggests', 'Summary', 'Supplements', 'URL', 'Url', 'Vendor', 'Version', /Patch\d*/, /Source\d*/),

        _value: ($) =>
            repeat(
                choice(
                    $.simple_expansion,
                    $.expansion,
                    $.integer,
                    $.float,
                    $.string,
                ),
            ),
    },
});

Why?
As I select a range for formatting, only the given range should be formatted, but instead it formats the complete file.

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

Reproduce the issue in the linked Prettier Playground using Prettier 3.2.5, the babel parser, and the supplied range-start and range-end values. Compare the formatted result with the expected output and verify that formatting changes only the selected range, not the complete file.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.