rules

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MPL-2.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

Rules is a list of all rules

Functions

func AssertIssues

func AssertIssues(t *testing.T, expected helper.Issues, actual helper.Issues)

AssertIssues is an assertion helper for comparing issues.

func AssertIssuesWithoutRange

func AssertIssuesWithoutRange(t *testing.T, expected helper.Issues, actual helper.Issues)

AssertIssuesWithoutRange is an assertion helper for comparing issues except for range.

func ForFiles

func ForFiles(runner tflint.Runner, action func(tflint.Runner, *hcl.File) error) error

func IsHeadMeta

func IsHeadMeta(argName string) bool

IsHeadMeta checks whether a name represents a type of head Meta arg

func IsTailMeta

func IsTailMeta(argName string) bool

IsTailMeta checks whether a name represents a type of tail Meta arg

func PrintSortedAttrTxt

func PrintSortedAttrTxt(src []byte, attr *hclsyntax.Attribute) (string, bool)

PrintSortedAttrTxt print the sorted hcl text of an attribute

func RemoveSpaceAndLine

func RemoveSpaceAndLine(str string) string

RemoveSpaceAndLine remove space, "\t" and "\n" from the given string

Types

type Arg

type Arg struct {
	Name  string
	Range hcl.Range
	File  *hcl.File
}

Arg is a wrapper of the attribute

func (*Arg) ToString

func (a *Arg) ToString() string

ToString prints the arg content

type Args

type Args struct {
	Args  []*Arg
	Range *hcl.Range
}

Args is the collection of args with the same type

func (*Args) CheckOrder

func (a *Args) CheckOrder() bool

CheckOrder checks whether this type of args are sorted

func (*Args) GetRange

func (a *Args) GetRange() *hcl.Range

GetRange returns the entire range of this type of args

func (*Args) ToString

func (a *Args) ToString() string

ToString prints this type of args in order

type Block

type Block interface {
	// CheckBlock checks the resourceBlock/nestedBlock recursively to find the block not in order,
	// and invoke the emit function on that block
	CheckBlock() error

	// ToString prints the sorted block
	ToString() string

	// DefRange gets the definition range of the block
	DefRange() hcl.Range
}

Block is an interface offering general APIs on resource/nested block

type HeadMetaArgs

type HeadMetaArgs struct {
	Args  []*Arg
	Range *hcl.Range
}

HeadMetaArgs is the collection of head meta args

func (*HeadMetaArgs) CheckOrder

func (a *HeadMetaArgs) CheckOrder() bool

CheckOrder checks whether the head meta args are sorted

func (*HeadMetaArgs) GetRange

func (a *HeadMetaArgs) GetRange() *hcl.Range

GetRange returns the entire range of head meta args

func (*HeadMetaArgs) ToString

func (a *HeadMetaArgs) ToString() string

ToString prints the head meta args in order

type NestedBlock

type NestedBlock struct {
	File             *hcl.File
	Block            *hclsyntax.Block
	Name             string
	SortField        string
	Range            hcl.Range
	HeadMetaArgs     *HeadMetaArgs
	Args             *Args
	NestedBlocks     *NestedBlocks
	ParentBlockNames []string
	// contains filtered or unexported fields
}

NestedBlock is a wrapper of the nested block

func (*NestedBlock) CheckBlock

func (b *NestedBlock) CheckBlock() error

CheckBlock checks the nestedBlock recursively to find the block not in order, and invoke the emit function on that block

func (*NestedBlock) CheckOrder

func (b *NestedBlock) CheckOrder() bool

CheckOrder checks whether the nestedBlock is sorted

func (*NestedBlock) DefRange

func (b *NestedBlock) DefRange() hcl.Range

DefRange gets the definition range of the nested block

func (*NestedBlock) ToString

func (b *NestedBlock) ToString() string

ToString prints the sorted block

type NestedBlocks

type NestedBlocks struct {
	Blocks []*NestedBlock
	Range  *hcl.Range
}

NestedBlocks is the collection of nestedBlocks with the same type

func (*NestedBlocks) CheckOrder

func (b *NestedBlocks) CheckOrder() bool

CheckOrder checks whether this type of nestedBlocks are sorted

func (*NestedBlocks) GetRange

func (b *NestedBlocks) GetRange() *hcl.Range

GetRange returns the entire range of this type of nestedBlocks

func (*NestedBlocks) ToString

func (b *NestedBlocks) ToString() string

ToString prints this type of nestedBlocks in order

type ResourceBlock

type ResourceBlock struct {
	File                 *hcl.File
	Block                *hclsyntax.Block
	HeadMetaArgs         *HeadMetaArgs
	Args                 *Args
	NestedBlocks         *NestedBlocks
	TailMetaArgs         *Args
	TailMetaNestedBlocks *NestedBlocks
	ParentBlockNames     []string
	// contains filtered or unexported fields
}

ResourceBlock is the wrapper of a resource block

func BuildResourceBlock

func BuildResourceBlock(block *hclsyntax.Block, file *hcl.File,
	emitter func(block Block) error) *ResourceBlock

BuildResourceBlock Build the root block wrapper using hclsyntax.Block

func (*ResourceBlock) CheckBlock

func (b *ResourceBlock) CheckBlock() error

CheckBlock checks the resource block and nested block recursively to find the block not in order, and invoke the emit function on that block

func (*ResourceBlock) CheckOrder

func (b *ResourceBlock) CheckOrder() bool

CheckOrder checks whether the resourceBlock is sorted

func (*ResourceBlock) DefRange

func (b *ResourceBlock) DefRange() hcl.Range

DefRange gets the definition range of the resource block

func (*ResourceBlock) ToString

func (b *ResourceBlock) ToString() string

ToString prints the sorted resource block

type Section

type Section interface {
	// CheckOrder checks whether the arguments in the collection is sorted
	CheckOrder() bool

	// ToString prints arguments in the collection in order
	ToString() string

	// GetRange returns the entire range of the argument collection
	GetRange() *hcl.Range
}

Section is an interface offering general APIs of argument collections

type TerraformCountIndexUsageRule

type TerraformCountIndexUsageRule struct {
	tflint.DefaultRule
}

TerraformCountIndexUsageRule checks whether count.index is used as subscript of list/map

func NewTerraformCountIndexUsageRule

func NewTerraformCountIndexUsageRule() *TerraformCountIndexUsageRule

NewTerraformCountIndexUsageRule returns a new rule

func (*TerraformCountIndexUsageRule) Check

func (*TerraformCountIndexUsageRule) CheckFile

func (r *TerraformCountIndexUsageRule) CheckFile(runner tflint.Runner, file *hcl.File) error

func (*TerraformCountIndexUsageRule) Enabled

func (r *TerraformCountIndexUsageRule) Enabled() bool

func (*TerraformCountIndexUsageRule) Name

Name returns the rule name

func (*TerraformCountIndexUsageRule) Severity

Severity returns the rule severity

type TerraformHeredocUsageRule

type TerraformHeredocUsageRule struct {
	tflint.DefaultRule
}

TerraformHeredocUsageRule checks whether HEREDOC is used for JSON/YAML

func NewTerraformHeredocUsageRule

func NewTerraformHeredocUsageRule() *TerraformHeredocUsageRule

NewTerraformHeredocUsageRule returns a new rule

func (*TerraformHeredocUsageRule) Check

func (r *TerraformHeredocUsageRule) Check(runner tflint.Runner) error

func (*TerraformHeredocUsageRule) CheckFile

func (r *TerraformHeredocUsageRule) CheckFile(runner tflint.Runner, file *hcl.File) error

func (*TerraformHeredocUsageRule) Enabled

func (r *TerraformHeredocUsageRule) Enabled() bool

func (*TerraformHeredocUsageRule) Name

Name returns the rule name

func (*TerraformHeredocUsageRule) Severity

type TerraformLocalsOrderRule

type TerraformLocalsOrderRule struct {
	tflint.DefaultRule
}

TerraformLocalsOrderRule checks whether comments use the preferred syntax

func NewTerraformLocalsOrderRule

func NewTerraformLocalsOrderRule() *TerraformLocalsOrderRule

NewTerraformLocalsOrderRule returns a new rule

func (*TerraformLocalsOrderRule) Check

func (r *TerraformLocalsOrderRule) Check(runner tflint.Runner) error

Check checks whether single line comments is used

func (*TerraformLocalsOrderRule) Enabled

func (r *TerraformLocalsOrderRule) Enabled() bool

Enabled returns whether the rule is enabled by default

func (r *TerraformLocalsOrderRule) Link() string

Link returns the rule reference link

func (*TerraformLocalsOrderRule) Name

func (r *TerraformLocalsOrderRule) Name() string

Name returns the rule name

func (*TerraformLocalsOrderRule) Severity

Severity returns the rule severity

type TerraformModuleProviderDeclarationRule

type TerraformModuleProviderDeclarationRule struct {
	tflint.DefaultRule
}

TerraformModuleProviderDeclarationRule checks whether local variables are sorted in alphabetic order

func NewTerraformModuleProviderDeclarationRule

func NewTerraformModuleProviderDeclarationRule() *TerraformModuleProviderDeclarationRule

NewTerraformModuleProviderDeclarationRule returns a new rule

func (*TerraformModuleProviderDeclarationRule) Check

func (*TerraformModuleProviderDeclarationRule) CheckFile

func (r *TerraformModuleProviderDeclarationRule) CheckFile(runner tflint.Runner, file *hcl.File) error

func (*TerraformModuleProviderDeclarationRule) Enabled

func (*TerraformModuleProviderDeclarationRule) Name

Name returns the rule name

func (*TerraformModuleProviderDeclarationRule) Severity

Severity returns the rule severity

type TerraformOutputOrderRule

type TerraformOutputOrderRule struct {
	tflint.DefaultRule
}

TerraformOutputOrderRule checks whether the outputs are sorted in expected order

func NewTerraformOutputOrderRule

func NewTerraformOutputOrderRule() *TerraformOutputOrderRule

NewTerraformOutputOrderRule returns a new rule

func (*TerraformOutputOrderRule) Check

func (r *TerraformOutputOrderRule) Check(runner tflint.Runner) error

Check checks whether the outputs are sorted in expected order

func (*TerraformOutputOrderRule) Enabled

func (r *TerraformOutputOrderRule) Enabled() bool

Enabled returns whether the rule is enabled by default

func (r *TerraformOutputOrderRule) Link() string

Link returns the rule reference link

func (*TerraformOutputOrderRule) Name

func (r *TerraformOutputOrderRule) Name() string

Name returns the rule name

func (*TerraformOutputOrderRule) Severity

Severity returns the rule severity

type TerraformOutputSeparateRule

type TerraformOutputSeparateRule struct {
	tflint.DefaultRule
}

TerraformOutputSeparateRule checks whether the outputs are separated from other types of blocks

func NewTerraformOutputSeparateRule

func NewTerraformOutputSeparateRule() *TerraformOutputSeparateRule

NewTerraformOutputSeparateRule returns a new rule

func (*TerraformOutputSeparateRule) Check

Check checks whether the variables are separated from other types of blocks

func (*TerraformOutputSeparateRule) Enabled

func (r *TerraformOutputSeparateRule) Enabled() bool

Enabled returns whether the rule is enabled by default

Link returns the rule reference link

func (*TerraformOutputSeparateRule) Name

Name returns the rule name

func (*TerraformOutputSeparateRule) Severity

Severity returns the rule severity

type TerraformRequiredProvidersDeclarationRule

type TerraformRequiredProvidersDeclarationRule struct {
	tflint.DefaultRule
}

TerraformRequiredProvidersDeclarationRule checks whether the required_providers block is declared in terraform block and whether the args of it are sorted in alphabetic order

func NewTerraformRequiredProvidersDeclarationRule

func NewTerraformRequiredProvidersDeclarationRule() *TerraformRequiredProvidersDeclarationRule

NewTerraformRequiredProvidersDeclarationRule returns a new rule

func (*TerraformRequiredProvidersDeclarationRule) Check

func (*TerraformRequiredProvidersDeclarationRule) CheckFile

func (r *TerraformRequiredProvidersDeclarationRule) CheckFile(runner tflint.Runner, file *hcl.File) error

func (*TerraformRequiredProvidersDeclarationRule) Enabled

func (*TerraformRequiredProvidersDeclarationRule) Name

Name returns the rule name

func (*TerraformRequiredProvidersDeclarationRule) Severity

type TerraformRequiredVersionDeclarationRule

type TerraformRequiredVersionDeclarationRule struct {
	tflint.DefaultRule
}

TerraformRequiredVersionDeclarationRule checks whether required_version field is declared at the beginning of terraform block

func NewTerraformRequiredVersionDeclarationRule

func NewTerraformRequiredVersionDeclarationRule() *TerraformRequiredVersionDeclarationRule

NewTerraformRequiredVersionDeclarationRule returns a new rule

func (*TerraformRequiredVersionDeclarationRule) Check

func (*TerraformRequiredVersionDeclarationRule) CheckFile

func (r *TerraformRequiredVersionDeclarationRule) CheckFile(runner tflint.Runner, file *hcl.File) error

func (*TerraformRequiredVersionDeclarationRule) Enabled

func (*TerraformRequiredVersionDeclarationRule) Name

Name returns the rule name

func (*TerraformRequiredVersionDeclarationRule) Severity

type TerraformResourceDataArgLayoutRule

type TerraformResourceDataArgLayoutRule struct {
	tflint.DefaultRule
}

func NewTerraformResourceDataArgLayoutRule

func NewTerraformResourceDataArgLayoutRule() *TerraformResourceDataArgLayoutRule

NewTerraformResourceDataArgLayoutRule returns a new rule

func (*TerraformResourceDataArgLayoutRule) Check

Check checks whether the arguments/attributes in a block are sorted in azure doc Layout

func (*TerraformResourceDataArgLayoutRule) Enabled

Enabled returns whether the rule is enabled by default

Link returns the rule reference link

func (*TerraformResourceDataArgLayoutRule) Name

Name returns the rule name

func (*TerraformResourceDataArgLayoutRule) Severity

Severity returns the rule severity

type TerraformSensitiveVariableNoDefaultRule

type TerraformSensitiveVariableNoDefaultRule struct {
	tflint.DefaultRule
}

TerraformSensitiveVariableNoDefaultRule checks whether default value is set for sensitive variables

func NewTerraformSensitiveVariableNoDefaultRule

func NewTerraformSensitiveVariableNoDefaultRule() *TerraformSensitiveVariableNoDefaultRule

NewTerraformSensitiveVariableNoDefaultRule returns a new rule

func (*TerraformSensitiveVariableNoDefaultRule) Check

func (*TerraformSensitiveVariableNoDefaultRule) CheckFile

func (r *TerraformSensitiveVariableNoDefaultRule) CheckFile(runner tflint.Runner, file *hcl.File) error

func (*TerraformSensitiveVariableNoDefaultRule) Enabled

func (*TerraformSensitiveVariableNoDefaultRule) Name

Name returns the rule name

func (*TerraformSensitiveVariableNoDefaultRule) Severity

Severity returns the rule severity

type TerraformVariableNullableFalseRule

type TerraformVariableNullableFalseRule struct {
	tflint.DefaultRule
}

func NewTerraformVariableNullableFalseRule

func NewTerraformVariableNullableFalseRule() *TerraformVariableNullableFalseRule

func (*TerraformVariableNullableFalseRule) Check

func (*TerraformVariableNullableFalseRule) Enabled

func (*TerraformVariableNullableFalseRule) Name

func (*TerraformVariableNullableFalseRule) Severity

type TerraformVariableOrderRule

type TerraformVariableOrderRule struct {
	tflint.DefaultRule
}

TerraformVariableOrderRule checks whether the variables are sorted in expected order

func NewTerraformVariableOrderRule

func NewTerraformVariableOrderRule() *TerraformVariableOrderRule

NewTerraformVariableOrderRule returns a new rule

func (*TerraformVariableOrderRule) Check

func (r *TerraformVariableOrderRule) Check(runner tflint.Runner) error

Check checks whether the variables are sorted in expected order

func (*TerraformVariableOrderRule) Enabled

func (r *TerraformVariableOrderRule) Enabled() bool

Enabled returns whether the rule is enabled by default

Link returns the rule reference link

func (*TerraformVariableOrderRule) Name

Name returns the rule name

func (*TerraformVariableOrderRule) Severity

Severity returns the rule severity

type TerraformVariableSeparateRule

type TerraformVariableSeparateRule struct {
	tflint.DefaultRule
}

TerraformVariableSeparateRule checks whether the variables are separated from other types of blocks

func NewTerraformVariableSeparateRule

func NewTerraformVariableSeparateRule() *TerraformVariableSeparateRule

NewTerraformVariableSeparateRule returns a new rule

func (*TerraformVariableSeparateRule) Check

Check checks whether the variables are separated from other types of blocks

func (*TerraformVariableSeparateRule) Enabled

func (r *TerraformVariableSeparateRule) Enabled() bool

Enabled returns whether the rule is enabled by default

Link returns the rule reference link

func (*TerraformVariableSeparateRule) Name

Name returns the rule name

func (*TerraformVariableSeparateRule) Severity

Severity returns the rule severity

type TerraformVersionsFileRule

type TerraformVersionsFileRule struct {
	tflint.DefaultRule
}

TerraformVersionsFileRule checks whether `versions.tf` only has 1 `terraform` block

func NewTerraformVersionsFileRule

func NewTerraformVersionsFileRule() *TerraformVersionsFileRule

NewTerraformVersionsFileRule returns a new rule

func (*TerraformVersionsFileRule) Check

func (r *TerraformVersionsFileRule) Check(runner tflint.Runner) error

func (*TerraformVersionsFileRule) CheckFile

func (r *TerraformVersionsFileRule) CheckFile(runner tflint.Runner, file *hcl.File) error

func (*TerraformVersionsFileRule) Enabled

func (r *TerraformVersionsFileRule) Enabled() bool

func (*TerraformVersionsFileRule) Name

Name returns the rule name

func (*TerraformVersionsFileRule) Severity

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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