Skip to content

feat(fmt): add fmt options #28946

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

Merged
merged 12 commits into from
Apr 29, 2025
Merged

feat(fmt): add fmt options #28946

merged 12 commits into from
Apr 29, 2025

Conversation

kt3k
Copy link
Member

@kt3k kt3k commented Apr 17, 2025

closes #26874

This PR adds 14 new options from dprint-plugin-typescript:

  • quoteProps
  • newLineKind
  • useBraces
  • bracePosition
  • singleBodyPosition
  • nextControlFlowPosition
  • trailingCommas
  • operatorPosition
  • jsx.bracketPosition
  • jsx.forceNewLinesSurroundingContent
  • jsx.multiLineParens
  • typeLiteral.separatorKind
  • spaceAround
  • spaceSurroundingProperties

related: denoland/deno_config#162


remaining:

  • write tests

@kt3k kt3k added the ci-draft Run the CI on draft PRs. label Apr 17, 2025
@kt3k kt3k added this to the 2.3.0 milestone Apr 18, 2025
@kt3k kt3k requested a review from dsherret April 18, 2025 03:29
@kt3k kt3k marked this pull request as ready for review April 18, 2025 03:30
@kt3k
Copy link
Member Author

kt3k commented Apr 18, 2025

The fixture files a.ts and d.tsx in tests/testdata/fmt/with_config/subdir/ ensure that newly added options actually have effects.

@petamoriken
Copy link
Contributor

petamoriken commented Apr 18, 2025

The schema should be updated as well.

"fmt": {
"description": "Configuration for formatter",
"type": "object",
"properties": {
"include": {
"type": "array",
"description": "List of files, directories or globs that will be formatted.",
"items": {
"type": "string"
}
},
"exclude": {
"type": "array",
"description": "List of files, directories or globs that will not be formatted.",
"items": {
"type": "string"
}
},
"useTabs": {
"description": "Whether to use tabs (true) or spaces (false) for indentation.",
"type": "boolean",
"default": false
},
"lineWidth": {
"description": "The width of a line the printer will try to stay under. Note that the printer may exceed this width in certain cases.",
"type": "number",
"default": 80
},
"indentWidth": {
"description": "The number of characters for an indent.",
"type": "number",
"default": 2
},
"singleQuote": {
"type": "boolean",
"description": "Whether to use single quote (true) or double quote (false) for quotation.",
"default": false
},
"proseWrap": {
"description": "Define how prose should be wrapped in Markdown files.",
"default": "always",
"enum": ["always", "never", "preserve"]
},
"semiColons": {
"description": "Whether to prefer using semicolons.",
"type": "boolean",
"default": true
},
"options": {
"type": "object",
"properties": {
"useTabs": {
"description": "Whether to use tabs (true) or spaces (false) for indentation.",
"type": "boolean",
"default": false
},
"lineWidth": {
"description": "The width of a line the printer will try to stay under. Note that the printer may exceed this width in certain cases.",
"type": "number",
"default": 80
},
"indentWidth": {
"description": "The number of characters for an indent.",
"type": "number",
"default": 2
},
"singleQuote": {
"type": "boolean",
"description": "Whether to use single quote (true) or double quote (false) for quotation.",
"default": false
},
"proseWrap": {
"description": "Define how prose should be wrapped in Markdown files.",
"default": "always",
"enum": ["always", "never", "preserve"]
},
"semiColons": {
"description": "Whether to prefer using semicolons.",
"type": "boolean",
"default": true
}
}
}
}
},

@kt3k
Copy link
Member Author

kt3k commented Apr 18, 2025

@petamoriken Thanks! Updated

@kt3k
Copy link
Member Author

kt3k commented Apr 22, 2025

@dsherret PTAL

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but look into the defaults as I think some of them are wrong.

Cargo.toml Outdated
@@ -56,7 +56,8 @@ deno_ast = { version = "=0.46.5", features = ["transpiling"] }
deno_core = { version = "0.343.0" }

deno_cache_dir = "=0.18.0"
deno_config = { version = "=0.52.0", features = ["workspace"] }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: remove blank line?

},
"operatorPosition": {
"description": "Where to place the operator for expressions that span multiple lines in JavaScript and TypeScript.",
"default": "nextLine",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you verify these defaults are correct? I think some are wrong like this one: https://github.com/dprint/dprint-plugin-typescript/blob/936cf945ad9f0e69bb31cffe1c85b1cf991fe56e/src/configuration/builder.rs#L54

This is actually the default we should have selected, but we did sameLine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I was using dprint's default. Thanks!

Updated in ba93914

"singleBodyPosition": "nextLine",
"nextControlFlowPosition": "nextLine",
"trailingCommas": "never",
"operatorPosition": "sameLine",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe try with the non-default

Copy link
Member Author

@kt3k kt3k Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this to "nextLine" b16ba74

@kt3k kt3k merged commit e142382 into denoland:main Apr 29, 2025
18 checks passed
@kt3k kt3k deleted the feat-add-fmt-options branch April 29, 2025 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-draft Run the CI on draft PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pass Dprint options directly from deno.json during deno fmt
4 participants