Documentation
¶
Overview ¶
Package formatter pretty-prints phpscript ASTs in a gofmt-like style: hard tabs, canonical `function` keywords, parentheses on control structures, semicolons, collapsed blank lines, and a trailing newline. Class, function, and control-structure opening braces stay on the declaration line.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func File ¶
File formats path in place. Reports whether the file contents changed, and returns a *SkipError for a file left as it is.
Types ¶
type Comment ¶ added in v0.3.0
Comment is one comment of the source, with the lines it occupied. The AST holds no comments, so they are read from the source separately and placed by line: a comment is written out before the first statement that starts below it. OwnLine records that nothing but whitespace preceded it, which is what separates a comment written above a statement from one written after it.
func CollectComments ¶ added in v0.3.0
CollectComments returns every comment of src in source order, with the lines it occupied and whether it stood on a line of its own. The AST holds no comments, so this is what keeps them in a file the formatter rewrites.
type Options ¶
type Options struct {
// Comments is every comment of the source file, in source order. The AST
// holds none of them, so the printer places them by line: a comment is
// written out before the first statement that starts below it.
Comments []Comment
}
Options controls AST pretty-printing.
type Result ¶ added in v0.3.0
type Result struct {
Path string
Changed bool
// Skipped is the reason the file was left as it is, and nil when the file
// was formatted.
Skipped error
}
Result is what the formatter did with one file. Formatting rewrites files in place, so a file is only rewritten when the formatter could read all of it and its output held up to the checks in File; every other file is reported as skipped and left as it is.
func NeedFormatting ¶ added in v0.3.0
NeedFormatting reports what Paths would do, writing nothing.
func Paths ¶
Paths formats each path argument in place and reports what happened to every file it looked at. A file it cannot format is skipped rather than failing the run: a directory of PHP holds valid code phpscript does not support yet, and one such file should not stop the rest from being formatted. Only reading and writing errors are returned.
type SkipError ¶ added in v0.3.0
SkipError reports a file the formatter left alone: source it cannot parse, a node it has no spelling for, or output that did not hold up to the checks in File. Formatting rewrites a file in place, so anything the formatter does not fully understand is safer left as it is than rewritten from a partial reading of it.