internal

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2024 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

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 NewFixer

func NewFixer(sources map[string][]byte) *Fixer

NewFixer creates a new Fixer instance.

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

func (f *Fixer) Changes() map[string][]byte

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

func (f *Fixer) HasChanges() bool

HasChanges returns true if the fixer has changes. Note this API is not intended to be used by plugins.

func (*Fixer) InsertTextAfter

func (f *Fixer) InsertTextAfter(rng hcl.Range, text string) error

InsertTextAfter inserts the given text after the given range.

func (*Fixer) InsertTextBefore

func (f *Fixer) InsertTextBefore(rng hcl.Range, text string) error

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

func (f *Fixer) RangeTo(to string, filename string, start hcl.Pos) hcl.Range

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) Remove

func (f *Fixer) Remove(rng hcl.Range) error

Remove removes the given range of source code.

func (*Fixer) RemoveAttribute

func (f *Fixer) RemoveAttribute(attr *hcl.Attribute) error

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

func (f *Fixer) RemoveBlock(block *hcl.Block) error

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

func (f *Fixer) RemoveExtBlock(block *hclext.Block) error

RemoveExtBlock removes the given block from the source code. This is similar to RemoveBlock, but it works for *hclext.Block.

func (*Fixer) ReplaceText

func (f *Fixer) ReplaceText(rng hcl.Range, texts ...any) error

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

func (f *Fixer) TextAt(rng hcl.Range) tflint.TextNode

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

func (f *Fixer) ValueText(val cty.Value) string

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL