Documentation
¶
Index ¶
Constants ¶
View Source
const ( // CommentModeProse greedily reflows all standalone prose-like comment // blocks. This preserves the historical formatter behavior. CommentModeProse = "prose" // CommentModeOverflow only reflows standalone comment blocks when at // least one physical line exceeds the column limit. Blocks that already // fit, or that look preformatted, are preserved verbatim. CommentModeOverflow = "overflow" // CommentModeOff disables comment reflow. CommentModeOff = "off" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CommentConfig ¶
type CommentConfig struct {
ColumnLimit int
TabStop int
// Mode controls how aggressively standalone comments are reflowed.
// Empty defaults to CommentModeProse for compatibility.
Mode string
// MoveInlineAbove hoists trailing inline comments (// and single-line
// /* */) above the code line as standalone comment lines for reflowing.
MoveInlineAbove bool
}
CommentConfig holds configuration for comment reflowing.
type CommentFormatter ¶
type CommentFormatter struct {
// contains filtered or unexported fields
}
CommentFormatter reflows standalone comment blocks greedily.
Rules (summary):
- Only format pure comment lines: lines that begin with "//" after optional indentation, or standalone block comments that begin with "/*" on their own line and end with "*/" on their own line. Trailing comments after code are left intact.
- Preserve indentation. Normalize markers:
- Line comments: non-empty lines as "// ", empty lines as "//".
- Block comments: keep opening "/*" and closing "*/" lines intact; interior lines emit as " * " for non-empty, " *" for empty.
- Preserve empty lines within a comment block as paragraph breaks.
- Lists ("- ") inside comments are reflowed as items: first line gets "- ", continuation lines align with two spaces instead of the dash.
- Greedy reflow by words; no hyphenation. A single word longer than the available width is placed on its own line.
func NewCommentFormatter ¶
func NewCommentFormatter(cfg CommentConfig) *CommentFormatter
NewCommentFormatter creates a new comment formatter with defaults.
func (*CommentFormatter) FormatFile ¶
func (f *CommentFormatter) FormatFile(src []byte) []byte
FormatFile implements greedy reflowing of comment-only lines.
Click to show internal directories.
Click to hide internal directories.