Skip to content

Releases: secforge/dprint-plugin-typescript

Enhanced useBraces modes, structural indentation, and nextControlFlowPosition fixes

20 Oct 08:31
4bcb75e

Choose a tag to compare

This fork enhances formatting control with new configuration options and modes.

New Features

Enhanced useBraces Modes

  • whenFormattedMultiLine: Only adds braces when the body would be formatted across multiple lines
  • onlyNeeded: Only adds braces when syntactically required (stricter than whenNeeded)

These modes provide finer control over brace usage in control flow statements.

NextLineExceptAfterBrace Control Flow Positioning

  • NextLineExceptAfterBrace: New nextControlFlowPosition option that places keywords like else, catch, finally, and while (do-while) on the same line as closing braces, but uses newlines otherwise
  • Fully supported for if-else, try-catch-finally, and do-while statements
  • Example: } else { stays on one line, but statement; else { uses a newline

Structural Indentation for Ternary Operators

  • conditionalExpressionIndentStyle: structural: Prevents deep nesting in ternary operators by using a flatter indentation structure
  • Particularly useful for complex nested ternary expressions

Expression Parentheses Control

  • forceParentheses option: Controls when wrapping parentheses are added around expressions
  • Helps avoid unnecessary parentheses while maintaining clarity

Configuration

  • Version: 0.95.11+sf.2
  • Plugin URLs configurable via Cargo.toml metadata
  • Dependencies use version ranges for better compatibility

Test Coverage

  • Added 25 new test files covering edge cases in brace usage, empty statements, and control flow positioning
  • All 671 tests passing

Custom dprint TypeScript Formatter v0.95.11+sf.1

08 Sep 15:47

Choose a tag to compare

Enhanced dprint TypeScript formatter with custom useBraces logic and additional configuration options.

  • Enhanced UseBraces modes: onlyNeeded to use only when strictly needed and whenFormattedMultiLine when the formatted content stricktly needs it or spans multiple lines.
  • Structural indentation: For conditional expressions (ternary operators) using conditionalExpression.indentStyle with options align and structural. align is the default and keeps all conditions aligned, while structural indents by structural depth.
  • Enforced Parantheses: It is now configurable, if parentheses are introduced around expressions in statement context using expressionStatement.forceParentheses
  • Next Control Flow Position: nextLineExceptAfterBrace allows else to appear behind `}``
  • CLI binary: Standalone formatter with config file support
  • Bug fix: NextControlFlowPosition::Maintain for else positioning after brace removal

Usage

Add this WASM plugin to your dprint.json:

{
  "plugins": [
    "https://github.com/secforge/dprint-plugin-typescript/releases/download/0.95.11+sf/dprint_plugin_typescript.wasm"
  ],
  "typescript": {
    "$schema": "https://github.com/secforge/dprint-plugin-typescript/releases/download/0.95.11+sf/schema.json"
    "useBraces": "whenNeeded",
    "conditionalExpression.indentStyle": "structural",
    "forStatement.useBraces": "whenNeeded"
  }
}

Custom dprint TypeScript Formatter v0.95.11+sf

08 Sep 11:09

Choose a tag to compare

Enhanced dprint TypeScript formatter with custom useBraces logic and additional configuration options.

  • Enhanced UseBraces modes: onlyNeeded to use only when strictly needed and whenFormattedMultiLine when the formatted content stricktly needs it or spans multiple lines.
  • Structural indentation: For conditional expressions (ternary operators) using conditionalExpression.indentStyle with options align and structural. align is the default and keeps all conditions aligned, while structural indents by structural depth.
  • Enforced Parantheses: It is now configurable, if parentheses are introduced around expressions in statement context using expressionStatement.forceParentheses
  • Next Control Flow Position: nextLineExceptAfterBrace allows else to appear behind `}``
  • CLI binary: Standalone formatter with config file support
  • Bug fix: NextControlFlowPosition::Maintain for else positioning after brace removal

Usage

Add this WASM plugin to your dprint.json:

{
  "plugins": [
    "https://github.com/secforge/dprint-plugin-typescript/releases/download/0.95.11+sf/dprint_plugin_typescript.wasm"
  ],
  "typescript": {
    "$schema": "https://github.com/secforge/dprint-plugin-typescript/releases/download/0.95.11+sf/schema.json"
    "useBraces": "whenNeeded",
    "conditionalExpression.indentStyle": "structural",
    "forStatement.useBraces": "whenNeeded"
  }
}