Releases: secforge/dprint-plugin-typescript
Releases · secforge/dprint-plugin-typescript
Enhanced useBraces modes, structural indentation, and nextControlFlowPosition fixes
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, andwhile(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, butstatement; 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
Enhanced dprint TypeScript formatter with custom useBraces logic and additional configuration options.
- Enhanced UseBraces modes:
onlyNeededto use only when strictly needed andwhenFormattedMultiLinewhen the formatted content stricktly needs it or spans multiple lines. - Structural indentation: For conditional expressions (ternary operators) using
conditionalExpression.indentStylewith optionsalignandstructural.alignis the default and keeps all conditions aligned, whilestructuralindents 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:
nextLineExceptAfterBraceallowselseto 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
Enhanced dprint TypeScript formatter with custom useBraces logic and additional configuration options.
- Enhanced UseBraces modes:
onlyNeededto use only when strictly needed andwhenFormattedMultiLinewhen the formatted content stricktly needs it or spans multiple lines. - Structural indentation: For conditional expressions (ternary operators) using
conditionalExpression.indentStylewith optionsalignandstructural.alignis the default and keeps all conditions aligned, whilestructuralindents 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:
nextLineExceptAfterBraceallowselseto 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"
}
}