Documentation
¶
Overview ¶
Package format lays out PHP source code: indentation, spaces, line breaks, braces, blank lines and the token spellings a style guide fixes.
One pass over the token stream decides the whitespace between every two significant tokens, using the syntax tree for context. The pass yields the formatted output and the list of changes that produce it, so a check reports exactly what a fix writes.
Index ¶
Constants ¶
const DefaultPreset = "per"
DefaultPreset is the preset used when nothing names one.
Variables ¶
This section is empty.
Functions ¶
func PresetReference ¶
PresetReference returns the style guide a preset follows.
Types ¶
type Change ¶
type Change struct {
Rule string // the setting behind the edit
Start uint32
End uint32
New string
// Report marks a finding formatting cannot fix: it edits nothing.
Report bool
// Group, when not 0, links edits that only work together (the two
// brackets of an array, a rebuilt import block): apply all or none.
Group int
}
Change is one edit of the source: [Start, End) becomes New.
type Layer ¶
type Layer struct {
Source string // shown by --show-config, e.g. "custos.json"
Values map[string]any // setting ID → value
}
Layer is one source of setting values, applied over the previous ones.
type Options ¶
type Options struct {
Settings *Settings
PHP phpversion.Version
}
Options configure Source.
type Resolved ¶
type Resolved struct {
Settings
Preset string
Source map[string]string // setting ID → source of its value
}
Resolved are settings plus where each value came from.
type Result ¶
type Result struct {
Output []byte
Changes []Change
// Skipped explains why the file was left as written.
Skipped string
}
Result is the outcome of formatting one file.
type Setting ¶
type Setting struct {
ID string
Group string
Kind Kind
Values []string // allowed values (enum, list)
Max int // largest value (int)
Risky bool
Description string
// contains filtered or unexported fields
}
Setting describes one formatting setting.
type Settings ¶
type Settings struct {
IndentStyle string // space, tab, keep
IndentSize int
TabWidth int
ContinuationIndent string // one, keep
LineEnding string // lf, crlf, cr, keep
FinalNewline bool
TrimTrailingWhitespace bool
RemoveBOM bool
ClosingTag string // remove, keep
OpenTagOwnLine bool
BlankLineAfterOpenTag bool
MaxBlankLines int // 0: no limit
LineLength int
Wrap string // long, off
JoinFittingLists bool
ReportLongLines bool
ClassBrace string // next_line, same_line, keep
FunctionBrace string // next_line, same_line, keep
ClosureBrace string // same_line, next_line, keep
AnonymousClassBrace string // same_line, next_line, keep
ControlBrace string // same_line, next_line, keep
ElsePosition string // same_line, next_line, keep
CatchPosition string // same_line, next_line, keep
EmptyBody string // inline, keep
SingleLineClosures bool
StatementPerLine bool
SingleLineThrow bool
BlankLineAfterNamespace bool
BlankLineAfterImports bool
BlankLineBetweenImportGroups bool
ClassOpenBlankLine string // none, one, keep
ClassCloseBlankLine string // none, one, keep
TrimBlockBlankLines bool
MethodSeparation string // one, keep
BlankLineAfterTraitUse bool
PropertySeparation string // one, none, keep
ConstantSeparation string // one, none, keep
BlankLineBefore []string
CaseSeparation bool
Spacing bool
ConcatSpace string // one, none, keep
BinaryOperatorSpace string // one, at_least_one
CastSpace string // one, none, keep
NotOperatorSpace string // none, one
ArrowFunctionSpace string // none, one, keep
ClosureSpace string // one, none
KeywordCase string // lower, keep
ConstantCase string // lower, upper, keep
TypeCase string // lower, keep
MagicConstantCase string // upper, keep
ShortCast bool
TrailingComma []string
SingleLineTrailingComma bool // false: remove a trailing comma from single-line lists
ArraySyntax string // short, long, keep
ListSyntax string // short, long, keep
ElseIf bool
NewParentheses string // add, remove, keep
StandardizeNotEquals bool
HashComment bool
OperatorLinebreak string // start, start_booleans, keep
ImportOrder string // alpha, length, none
ImportGroups string // class_function_const, const_class_function, none
NoLeadingImportSlash bool
SingleImportPerStatement bool
SingleTraitPerStatement bool
ParameterAttributeLine bool
NullTypeLast bool
SemicolonLine string // join, keep
CommentSpacing bool
HexCase string // upper, keep
BlankLineAfterThrow bool
CatchTypeSpace string // one, none, keep
FunctionSeparation bool
SingleLineClassDefinition bool
TrimBracketBlankLines bool
SplitMultilineArrays bool
BranchComment string // body, next
CaseComment string // body, label
AssignmentChain string // one, stairs
CaseBodyLine bool
Visibility string // all, methods_properties, keep
AnonymousClassSpace string // one, none, keep
// Risky settings change tokens beyond layout; they apply only when
// Risky allows them.
Yoda string // yoda, regular, keep
SingleQuote bool
RemoveUnusedImports bool
DeclareStrictTypes bool
IncrementStyle string // pre, post, keep
HeredocToNowdoc bool
OrderedTraits bool
}
Settings are the resolved formatting settings of one file. Every field is one entry of the registry (see Registry); "keep" leaves the matching layout as written.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package editorconfig resolves the EditorConfig properties of one file following https://spec.editorconfig.org/: it parses `.editorconfig` files, matches their section globs and merges their pairs by precedence.
|
Package editorconfig resolves the EditorConfig properties of one file following https://spec.editorconfig.org/: it parses `.editorconfig` files, matches their section globs and merges their pairs by precedence. |