11import type { Node } from "web-tree-sitter" ;
2- import type { EndOfLine } from "../types.js" ;
2+ import type { FormatterOptions } from "../types.js" ;
33import {
44 DEFAULT_INSERT_FINAL_NEWLINE ,
5- DEFAULT_LINE_WIDTH ,
5+ DEFAULT_MAX_LINE_LENGTH ,
66} from "../util/constants.js" ;
77import { getColumnWidth } from "../util/getColumnWidth.js" ;
88import { getEndOfLine } from "../util/getEndOfLine.js" ;
99import { getIndentation } from "../util/getIndentation.js" ;
1010
11- interface Options {
12- readonly endOfLine ?: EndOfLine ;
13- readonly indentTabs ?: boolean ;
14- readonly indentWidth ?: number ;
15- readonly lineWidth ?: number ;
16- readonly columnWidth ?: number ;
17- readonly insertFinalNewline ?: boolean ;
18- readonly preserveMultiline ?: boolean ;
19- }
11+ type Options = FormatterOptions <
12+ | " endOfLine"
13+ | " indentTabs"
14+ | "indentSize"
15+ | "maxLineLength"
16+ | " columnWidth"
17+ | " insertFinalNewline"
18+ | " preserveMultiline"
19+ > ;
2020
2121export function talonFormatter ( node : Node , options : Options = { } ) : string {
2222 const columnWidth = getColumnWidth ( node . text ) ?? options . columnWidth ;
23- const indentation = getIndentation ( options . indentTabs , options . indentWidth ) ;
23+ const indentation = getIndentation ( options . indentTabs , options . indentSize ) ;
2424 const eol = getEndOfLine ( options . endOfLine ) ;
2525 const formatter = new TalonFormatter (
2626 indentation ,
2727 eol ,
28- options . lineWidth ?? DEFAULT_LINE_WIDTH ,
28+ options . maxLineLength ?? DEFAULT_MAX_LINE_LENGTH ,
2929 columnWidth ,
3030 options . insertFinalNewline ?? DEFAULT_INSERT_FINAL_NEWLINE ,
3131 options . preserveMultiline ?? false ,
@@ -39,7 +39,7 @@ class TalonFormatter {
3939 constructor (
4040 private indent : string ,
4141 private eol : string ,
42- private lineWidth : number ,
42+ private maxLineLength : number ,
4343 private columnWidth : number | undefined ,
4444 private insertFinalNewline : boolean ,
4545 private preserveMultiline : boolean ,
@@ -77,7 +77,7 @@ class TalonFormatter {
7777 : `${ left } : ` ;
7878 if (
7979 leftWithPadding . length + right . length <=
80- this . lineWidth
80+ this . maxLineLength
8181 ) {
8282 return leftWithPadding + right ;
8383 }
0 commit comments