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 with long type and single param without parens formats to invalid code #1905

Closed
1 task done
arilotter opened this issue Feb 23, 2024 · 6 comments · Fixed by #1934
Closed
1 task done
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

@arilotter
Copy link

arilotter commented Feb 23, 2024

Environment information

CLI:
  Version:                      1.4.1
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           linux

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v21.5.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "pnpm/8.10.5"

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

Workspace:
  Open Documents:               0

Configuration

{
  "$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
  "javascript": {
    "formatter": {
      "arrowParentheses": "asNeeded"
    }
  }
}

Issue information

Biome outputs invalid TS; the => is on a new line, that's not valid.

type InstanceID = string;
type MaybeCardWithAttachment = string;
function outerFunctionToForceIndent() {
	const cardWithAttachment: (id: InstanceID) => MaybeCardWithAttachment =
		id
	=> {
		return `${id}test`;
	};
}

Playground link

https://codesandbox.io/p/devbox/biome-starter-cbs-rky6zq

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@arilotter arilotter changed the title 📝 arrow function with long type and single param without parans formats to invalid code 📝 arrow function with long type and single param without parens formats to invalid code Feb 23, 2024
@togami2864
Copy link
Contributor

The error occurs due to a line break before the arrow. ref

We have two options:

  • Treat it as a special case, accept the error, and format accordingly (as Prettier does. I'm don't know why this error occurs in the Prettier section of the Biome playground 🤔).
  • Treat it as invalid code (as TypeScript and Biome does).

Should we adjust our code to be compatible with Prettier🤔

@togami2864 togami2864 added A-Parser Area: parser L-JavaScript Language: JavaScript and super languages labels Feb 24, 2024
@Sec-ant
Copy link
Member

Sec-ant commented Feb 24, 2024

I think what OP is trying to say is the valid code like below will be formatted into invalid code?

type InstanceID = string;
type MaybeCardWithAttachment = string;
function outerFunctionToForceIndent() {
	const cardWithAttachment: (id: InstanceID) => MaybeCardWithAttachment = (
		id
	) => {
		return `${id}test`;
	};
}

image

Playground Link.

@togami2864
Copy link
Contributor

@Sec-ant Nice catch! Maybe I misunderstood.
@arilotter Could you provide your input? The playground link you attached seems empty.

@arilotter
Copy link
Author

@Sec-ant Nice catch! Maybe I misunderstood.
@arilotter Could you provide your input? The playground link you attached seems empty.

sec-ant has it nailed! biome formats the code into TS that doesn't compile, because it's illegal to have => on its own line.

@togami2864 togami2864 added A-Formatter Area: formatter and removed A-Parser Area: parser labels Feb 24, 2024
@ematipico ematipico added the S-Bug-confirmed Status: report has been confirmed as a valid bug label Feb 24, 2024
@fireairforce
Copy link
Contributor

I am willing to solve this issue~

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
5 participants