feat(format): Doc-IR core, line_width (120) and where_wrap when_long
This commit is contained in:
@@ -69,6 +69,7 @@ type Style struct {
|
||||
IndentJoin bool // extra indentation for JOIN … ON lines
|
||||
JoinIndentSize int // extra indent levels for JOINs (default 1)
|
||||
WhereWrap WrapMode // always|when_long|never — each AND/OR on its own line
|
||||
LineWidth int // target width for when_long wrapping (0 = unlimited)
|
||||
WhereAndOrIndent bool // AND/OR indented one level under WHERE
|
||||
|
||||
// --- Subqueries ---
|
||||
@@ -120,6 +121,7 @@ func Default() Style {
|
||||
SetAlignEqual: false,
|
||||
IndentJoin: false,
|
||||
JoinIndentSize: 1,
|
||||
LineWidth: 120,
|
||||
WhereWrap: WrapAlways,
|
||||
WhereAndOrIndent: true,
|
||||
|
||||
@@ -169,6 +171,7 @@ type yamlFile struct {
|
||||
IndentJoin *bool `yaml:"indent_join"`
|
||||
JoinIndentSize *int `yaml:"join_indent_size"`
|
||||
WhereWrap *string `yaml:"where_wrap"`
|
||||
LineWidth *int `yaml:"line_width"`
|
||||
WhereAndOrIndent *bool `yaml:"where_and_or_indent"`
|
||||
|
||||
SubqueryOpening *string `yaml:"subquery_opening"`
|
||||
@@ -258,6 +261,12 @@ func Load(startDir string) (Style, error) {
|
||||
if yf.JoinIndentSize != nil {
|
||||
st.JoinIndentSize = *yf.JoinIndentSize
|
||||
}
|
||||
if yf.LineWidth != nil {
|
||||
if *yf.LineWidth < 0 {
|
||||
return st, fmt.Errorf("pgtidy: %s: line_width: must be >= 0", path)
|
||||
}
|
||||
st.LineWidth = *yf.LineWidth
|
||||
}
|
||||
if yf.WhereWrap != nil {
|
||||
wm := WrapMode(*yf.WhereWrap)
|
||||
if err := validWrap(wm); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user