Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arrow function body indentation affected by its type length #2736

Closed
1 task done
kalekseev opened this issue May 6, 2024 · 5 comments · Fixed by #2766
Closed
1 task done

Arrow function body indentation affected by its type length #2736

kalekseev opened this issue May 6, 2024 · 5 comments · Fixed by #2766
Assignees
Labels
A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug

Comments

@kalekseev
Copy link

Environment information

CLI:
  Version:                      1.6.3
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "screen-256color"
  JS_RUNTIME_VERSION:           unset
  JS_RUNTIME_NAME:              unset
  NODE_PACKAGE_MANAGER:         unset

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           false
  Linter disabled:              true
  Organize imports disabled:    true
  VCS disabled:                 true

Formatter:
  Format with errors:           true
  Indent style:                 Space
  Indent size:                  0
  Indent width:                 2
  Line ending:                  Lf
  Line width:                   90
  Attribute position:           Auto
  Ignore:                       []
  Include:                      []

JavaScript Formatter:
  Enabled:                      false
  JSX quote style:              Double
  Quote properties:             AsNeeded
  Trailing comma:               Es5
  Semicolons:                   Always
  Arrow parentheses:            Always
  Bracket spacing:              false
  Bracket same line:            false
  Quote style:                  Single
  Indent style:                 unset
  Indent size:                  unset
  Indent width:                 unset
  Line ending:                  unset
  Line width:                   unset
  Attribute position:           Auto

JSON Formatter:
  Enabled:                      true
  Indent style:                 unset
  Indent width:                 unset
  Indent size:                  unset
  Line ending:                  unset
  Line width:                   unset
  Trailing Commas:              unset

Workspace:
  Open Documents:               0

Configuration

{
  "$schema": "https://biomejs.dev/schemas/1.6.3/schema.json",
  "organizeImports": {
    "enabled": false
  },
  "linter": {
    "enabled": false
  },
  "formatter": {
    "enabled": true,
    "indentStyle": "space",
    "indentWidth": 2,
    "lineWidth": 90,
    "formatWithErrors": true
  },
  "javascript": {
    "formatter": {
      "trailingComma": "es5",
      "quoteStyle": "single"
    }
  }
}

Playground link

https://biomejs.dev/playground/?lineWidth=90&code=YwBvAG4AcwB0ACAAVgBhAGwAdQBlAE0AZQBuAHUARABpAHYAaQBkAGUAcgA6ACAAUgBlAGEAYwB0AC4ARgBDADwAewAgAHYAYQBsAHUAZQA6ACAAcwB0AHIAaQBuAGcAIAB9ACAAJgAgAE8AbQBpAHQAPABNAGUAbgB1AEQAaQB2AGkAZABlAHIAUAByAG8AcABzACwAIAAnAHMAdgBhAGwAdQBlACcAPgA%2BACAAPQAgACgAewAgAHYAYQBsAHUAZQAgAH0AKQAgAD0APgAgAHsACgAgACAAcgBlAHQAdQByAG4AIAA8AE8AcgBpAGcAaQBuAGEAbABNAGUAbgB1AEQAaQB2AGkAZABlAHIAIAAvAD4AOwAKAH0AOwAKAAoACgAKAGMAbwBuAHMAdAAgAFYAYQBsAHUAZQBNAGUAbgB1AEQAaQB2AGkAZABlAHIAMgA6ACAAUgBlAGEAYwB0AC4ARgBDADwAewAgAHYAYQBsAHUAZQA6ACAAcwB0AHIAaQBuAGcAIAB9ACAAJgAgAE8AbQBpAHQAPABNAGUAbgB1AEQAaQB2AGkAZABlAHIAUAByAG8AcABzACwAIAAnAHMAdgBhAGwAdQBlACcALAAgACcAYQBuAG8AdABoAGUAcgB2AGEAbAB1AGUAJwA%2BAD4AIAA9ACAAKAB7ACAAdgBhAGwAdQBlACAAfQApACAAPQA%2BACAAewAKACAAIAByAGUAdAB1AHIAbgAgADwATwByAGkAZwBpAG4AYQBsAE0AZQBuAHUARABpAHYAaQBkAGUAcgAgAC8APgA7AAoAfQA7AAoA

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@ah-yu ah-yu added A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug labels May 6, 2024
@dyc3
Copy link
Contributor

dyc3 commented May 6, 2024

I'd like to give this a shot.

@dyc3
Copy link
Contributor

dyc3 commented May 7, 2024

I've been combing over the code for a while now, and I think I understand what's going on. Mostly notes for myself:

The variable declaration group is higher up in the IR tree than the type annotation group. When the tree gets flattened into FormatElements, the variable declaration group gets evaluated first to see if it breaks (and since it's long enough, it breaks). Then the type annotation group gets evaluated, and its not long enough, so it doesn't break. This evaluation happens here:

// Measure to see if the group fits up on a single line. If that's the case,
// print the group in "flat" mode, otherwise continue in expanded mode
stack.push(TagKind::Group, args.with_print_mode(PrintMode::Flat));
let fits = self.fits(queue, stack, indent_stack)?;
stack.pop(TagKind::Group)?;

I think one way to fix this is to introduce some kind of "break priority" field to the Group struct, and then favor breaking type annotations, but I think that could introduce some complexity.

@ah-yu
Copy link
Contributor

ah-yu commented May 8, 2024

I think one way to fix this is to introduce some kind of "break priority" field to the Group struct, and then favor breaking type annotations, but I think that could introduce some complexity.

It seems that this approach assumes the current generated IR is accurate. Perhaps we could compare the IR generated by Biome and Prettier to identify differences between them and address these disparities to see if the issue is resolved.

@dyc3
Copy link
Contributor

dyc3 commented May 8, 2024

Ok yeah, I was looking at the IR before and it looked identical, but I'm looking at it again and it is definitely not. Biome is emitting an extra group around the left hand side of the assignment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants