Documentation
¶
Index ¶
- type Fixer
- func (f *Fixer) ApplyChanges()
- func (f *Fixer) Changes() map[string][]byte
- func (f *Fixer) FormatChanges()
- func (f *Fixer) HasChanges() bool
- func (f *Fixer) InsertTextAfter(rng hcl.Range, text string) error
- func (f *Fixer) InsertTextBefore(rng hcl.Range, text string) error
- func (f *Fixer) PopChangesFromStash()
- func (f *Fixer) RangeTo(to string, filename string, start hcl.Pos) hcl.Range
- func (f *Fixer) Remove(rng hcl.Range) error
- func (f *Fixer) RemoveAttribute(attr *hcl.Attribute) error
- func (f *Fixer) RemoveBlock(block *hcl.Block) error
- func (f *Fixer) RemoveExtBlock(block *hclext.Block) error
- func (f *Fixer) ReplaceText(rng hcl.Range, texts ...any) error
- func (f *Fixer) StashChanges()
- func (f *Fixer) TextAt(rng hcl.Range) tflint.TextNode
- func (f *Fixer) ValueText(val cty.Value) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fixer ¶
type Fixer struct {
// contains filtered or unexported fields
}
Fixer is a tool to rewrite HCL source code.
func (*Fixer) ApplyChanges ¶
func (f *Fixer) ApplyChanges()
ApplyChanges applies the changes made by the fixer. Note this API is not intended to be used by plugins.
func (*Fixer) Changes ¶
Changes returns the changes made by the fixer. Note this API is not intended to be used by plugins.
func (*Fixer) FormatChanges ¶
func (f *Fixer) FormatChanges()
FormatChanges formats the changes made by the fixer. Note this API is not intended to be used by plugins.
func (*Fixer) HasChanges ¶
HasChanges returns true if the fixer has changes. Note this API is not intended to be used by plugins.
func (*Fixer) InsertTextAfter ¶
InsertTextAfter inserts the given text after the given range.
func (*Fixer) InsertTextBefore ¶
InsertTextBefore inserts the given text before the given range.
func (*Fixer) PopChangesFromStash ¶
func (f *Fixer) PopChangesFromStash()
PopChangesFromStash pops changes from the stash. Note this API is not intended to be used by plugins.
func (*Fixer) RangeTo ¶
RangeTo returns a range from the given start position to the given text. Note that it doesn't check if the text is actually in the range.
func (*Fixer) RemoveAttribute ¶
RemoveAttribute removes the given attribute from the source code. The difference from Remove is that it removes the attribute and the associated newlines, indentations, and comments. This only works for HCL native syntax. JSON syntax is not supported and returns tflint.ErrFixNotSupported.
func (*Fixer) RemoveBlock ¶
RemoveBlock removes the given block from the source code. The difference from Remove is that it removes the block and the associated newlines, indentations, and comments. This only works for HCL native syntax. JSON syntax is not supported and returns tflint.ErrFixNotSupported.
func (*Fixer) RemoveExtBlock ¶
RemoveExtBlock removes the given block from the source code. This is similar to RemoveBlock, but it works for *hclext.Block.
func (*Fixer) ReplaceText ¶
ReplaceText rewrites the given range of source code to a new text. If the range is overlapped with a previous rewrite range, it returns an error.
Either string or tflint.TextNode is valid as an argument. TextNode can be obtained with fixer.TextAt(range). If the argument is a TextNode, and the range is contained in the replacement range, this function automatically minimizes the replacement range as much as possible.
For example, if the source code is "(foo)", ReplaceText(range, "[foo]") rewrites the whole "(foo)". But ReplaceText(range, "[", TextAt(fooRange), "]") rewrites only "(" and ")". This is useful to avoid unintended conflicts.
func (*Fixer) StashChanges ¶
func (f *Fixer) StashChanges()
StashChanges stashes the current changes. Note this API is not intended to be used by plugins.
func (*Fixer) TextAt ¶
TextAt returns a text node at the given range. This is expected to be passed as an argument to ReplaceText. Note this doesn't take into account the changes made by the fixer in a rule.
func (*Fixer) ValueText ¶
ValueText returns a text representation of the given cty.Value. Values are always converted to a single line. For more pretty-printing, implement your own conversion function.
This function is inspired by hclwrite.TokensForValue. https://github.com/hashicorp/hcl/blob/v2.16.2/hclwrite/generate.go#L26