Documentation
¶
Overview ¶
ruleset provides a set of rules and their corresponding validator functions for linting Dockerfile AST elements.
Index ¶
- Constants
- Variables
- func LocationRangeToBKRange(locationRange LocationRange) parser.Range
- func NewCmdCommand(str string, lineNumber int) (*instructions.CmdCommand, error)
- func NewEntrypointCommand(str string, lineNumber int) (*instructions.EntrypointCommand, error)
- func NewMaintainerCommand(str string) (*instructions.MaintainerCommand, error)
- func NewRunCommand(cmd string, locationRange LocationRange) *instructions.RunCommand
- func RegisterTestCaseDocs(string, interface{})
- func SortLocationRanges(locationRangeSlice []LocationRange)
- type DocsReference
- type Location
- type LocationRange
- func BKRangeSliceToLocationRange(parserRange []parser.Range) LocationRange
- func LocationRangeFromCommand(command instructions.Command) LocationRange
- func NewLocationFrom4Int(locationRange [4]int) LocationRange
- func NewLocationFrom4IntSlice(locationRangeSlice [][4]int) []LocationRange
- func NewLocationRange(startLine, startChar, endLine, endChar int) LocationRange
- func ParseLocationFromRawParser(str string, window []parser.Range) LocationRange
- func ParseLocationSliceFromRawParser(strSlice []string, window []parser.Range) []LocationRange
- func UnionOfLocationRanges(locationRangeSlice []LocationRange) LocationRange
- type Rule
- func (rule *Rule) Definition() string
- func (rule *Rule) Description() string
- func (rule *Rule) DocsReference() DocsReference
- func (rule *Rule) ID() string
- func (rule *Rule) MarshalJSON() ([]byte, error)
- func (rule *Rule) Severity() Severity
- func (rule *Rule) UnmarshalJSON(data []byte) error
- func (rule *Rule) Validate(param interface{}) RuleValidationResult
- func (rule *Rule) ValidationFunc() interface{}
- type RuleMapType
- type RuleValidationResult
- func NewRuleValidationResult(rule *Rule, isViolated bool, message string, locationRange LocationRange) *RuleValidationResult
- func ValidateCmd001(cmdCommand *instructions.CmdCommand) RuleValidationResult
- func ValidateCpy001(copyCommand *instructions.CopyCommand) RuleValidationResult
- func ValidateCpy002(copyCommand *instructions.CopyCommand) RuleValidationResult
- func ValidateCpy003(copyCommand *instructions.CopyCommand) RuleValidationResult
- func ValidateCpy004(copyCommand *instructions.CopyCommand) RuleValidationResult
- func ValidateCpy005(copyCommand *instructions.CopyCommand) RuleValidationResult
- func ValidateCpy006(stage instructions.Stage) RuleValidationResult
- func ValidateEnt001(entrypointCommand *instructions.EntrypointCommand) RuleValidationResult
- func ValidateExp001(exposeCommand *instructions.ExposeCommand) RuleValidationResult
- func ValidateMtr001(maintainerCommand *instructions.MaintainerCommand) RuleValidationResult
- func ValidateRun001(runCommand *instructions.RunCommand) RuleValidationResult
- func ValidateRun002(runCommand *instructions.RunCommand) RuleValidationResult
- func ValidateRun003(runCommand *instructions.RunCommand) RuleValidationResult
- func ValidateRun004(runCommand *instructions.RunCommand) RuleValidationResult
- func ValidateRun005(runCommand *instructions.RunCommand) RuleValidationResult
- func ValidateRun006(runCommand *instructions.RunCommand) RuleValidationResult
- func ValidateRun007(runCommand *instructions.RunCommand) RuleValidationResult
- func ValidateRun008(runCommand *instructions.RunCommand) RuleValidationResult
- func ValidateRun009(runCommand *instructions.RunCommand) RuleValidationResult
- func ValidateRun010(runCommand *instructions.RunCommand) RuleValidationResult
- func ValidateStl001(stageList []instructions.Stage) RuleValidationResult
- func ValidateSts001(stage instructions.Stage) RuleValidationResult
- func ValidateSts002(stage instructions.Stage) RuleValidationResult
- func ValidateSts003(stage instructions.Stage) RuleValidationResult
- func ValidateSts004(stage instructions.Stage) RuleValidationResult
- func ValidateUsr001(stageList []instructions.Stage) RuleValidationResult
- func ValidateWkd001(workdirCommand *instructions.WorkdirCommand) RuleValidationResult
- func (ruleValidationResult *RuleValidationResult) Description() string
- func (ruleValidationResult RuleValidationResult) IsViolated() bool
- func (ruleValidationResult *RuleValidationResult) Location() *LocationRange
- func (ruleValidationResult *RuleValidationResult) MarshalJSON() ([]byte, error)
- func (ruleValidationResult *RuleValidationResult) Message() string
- func (ruleValidationResult *RuleValidationResult) RuleID() string
- func (ruleValidationResult *RuleValidationResult) SetLocation(startLineNumber, startCharNumber, endLineNumber, endCharNumber int)
- func (ruleValidationResult *RuleValidationResult) SetLocationRangeFrom(locationRange LocationRange)
- func (ruleValidationResult *RuleValidationResult) SetRule(rule *Rule)
- func (ruleValidationResult *RuleValidationResult) SetViolated(params ...bool)
- func (ruleValidationResult *RuleValidationResult) Severity() Severity
- func (ruleValidationResult *RuleValidationResult) UnmarshalJSON(data []byte) error
- type Severity
Constants ¶
const FORCE = true // used for overriding the latched isViolated flag in SetViolated.
const ToDoReference = DocsReference("TODO")
Variables ¶
var DocsReferenceMap = map[string]DocsReference{ "CPY": DocsReference("https://docs.docker.com/engine/reference/builder/#copy"), "ENV": DocsReference("https://docs.docker.com/engine/reference/builder/#env"), "EXP": DocsReference("https://docs.docker.com/engine/reference/builder/#expose"), "FRM": DocsReference("https://docs.docker.com/engine/reference/builder/#from"), "RUN": DocsReference("https://docs.docker.com/engine/reference/builder/#run"), "STL": DocsReference("https://docs.docker.com/engine/reference/builder/#from"), "STS": DocsReference("https://docs.docker.com/engine/reference/builder/#from"), "USR": DocsReference("https://docs.docker.com/engine/reference/builder/#user"), "WKD": DocsReference("https://docs.docker.com/engine/reference/builder/#workdir"), }
Functions ¶
func LocationRangeToBKRange ¶
func LocationRangeToBKRange(locationRange LocationRange) parser.Range
func NewCmdCommand ¶
func NewCmdCommand(str string, lineNumber int) (*instructions.CmdCommand, error)
func NewEntrypointCommand ¶
func NewEntrypointCommand(str string, lineNumber int) (*instructions.EntrypointCommand, error)
func NewMaintainerCommand ¶
func NewMaintainerCommand(str string) (*instructions.MaintainerCommand, error)
func NewRunCommand ¶
func NewRunCommand(cmd string, locationRange LocationRange) *instructions.RunCommand
func RegisterTestCaseDocs ¶
func RegisterTestCaseDocs(string, interface{})
RegisterTestCaseDocs is a mock function. For details, please see docs.go.
func SortLocationRanges ¶
func SortLocationRanges(locationRangeSlice []LocationRange)
Types ¶
type DocsReference ¶
type DocsReference string
DocsReference is a documentation reference link and/or source. Usually it's a web link.
type Location ¶
type Location struct {
// contains filtered or unexported fields
}
func (*Location) CharNumber ¶
func (*Location) LineNumber ¶
func (Location) MarshalJSON ¶
func (*Location) UnmarshalJSON ¶
type LocationRange ¶
type LocationRange struct {
// contains filtered or unexported fields
}
func BKRangeSliceToLocationRange ¶
func BKRangeSliceToLocationRange(parserRange []parser.Range) LocationRange
func LocationRangeFromCommand ¶
func LocationRangeFromCommand(command instructions.Command) LocationRange
func NewLocationFrom4Int ¶
func NewLocationFrom4Int(locationRange [4]int) LocationRange
func NewLocationFrom4IntSlice ¶
func NewLocationFrom4IntSlice(locationRangeSlice [][4]int) []LocationRange
func NewLocationRange ¶
func NewLocationRange(startLine, startChar, endLine, endChar int) LocationRange
func ParseLocationFromRawParser ¶
func ParseLocationFromRawParser(str string, window []parser.Range) LocationRange
func ParseLocationSliceFromRawParser ¶
func ParseLocationSliceFromRawParser(strSlice []string, window []parser.Range) []LocationRange
func UnionOfLocationRanges ¶
func UnionOfLocationRanges(locationRangeSlice []LocationRange) LocationRange
func (*LocationRange) End ¶
func (locationRange *LocationRange) End() *Location
func (LocationRange) MarshalJSON ¶
func (locationRange LocationRange) MarshalJSON() ([]byte, error)
func (*LocationRange) Start ¶
func (locationRange *LocationRange) Start() *Location
func (*LocationRange) UnmarshalJSON ¶
func (locationRange *LocationRange) UnmarshalJSON(data []byte) error
type Rule ¶
type Rule struct {
// contains filtered or unexported fields
}
Rule represents a Dockerfile lint validation rule. It has the basic id, definition, description, severity attributes and a validation function as an interface. For further details on validateFunc, please see Validate how it is utilized.
func GetRulesForAstElement ¶
func GetRulesForAstElement(astElementInterface interface{}) []Rule
GetRulesForAstElement returns a Rule slice with all the rules that the given Dockerfile AST element needs to be validated against.
func NewRule ¶
func NewRule(id string, definition string, description string, severity Severity, param interface{}) *Rule
NewRule creates a new Rule by joining it's id, definition, description, severity and validation function. It automatically gets assigned into a slice/set of rules corresponding to a specific Dockerfile AST element, inside the ruleMap's corresponding bin, based on the Dockerfile AST element's type. See below, how reflect.TypeOf().String() is used to achieve this.
func (*Rule) Definition ¶
Definition returns the rule's definition, i.e. the rule itself as a statement/guidance.
func (*Rule) Description ¶
Description returns the rule's description, the idea behind the definition.
func (*Rule) DocsReference ¶
func (rule *Rule) DocsReference() DocsReference
DocsReference returns an official reference link connected to the rule itself, most likely directly linking to a Docker documentation webpage.
func (*Rule) MarshalJSON ¶
MarshalJSON converts a Rule instance to JSON.
func (*Rule) Severity ¶
Severity returns the rule's severity, e.g. error, warning, info, deprecation.
func (*Rule) UnmarshalJSON ¶
func (*Rule) Validate ¶
func (rule *Rule) Validate(param interface{}) RuleValidationResult
Validation calls the the rule's validationFunc validation function in the correct form, after converting from interface{} to the concrete type.
example: func(runCommand *instructions.RunCommand) RuleValidationResult where runCommand is asserted param as *instructions.RunCommand.
func (*Rule) ValidationFunc ¶
func (rule *Rule) ValidationFunc() interface{}
type RuleMapType ¶
RuleMapType represents a set of rules for each Dockerfile AST element identified by its type's string value (through reflect).
func (RuleMapType) Count ¶
func (ruleMap RuleMapType) Count() int
Count gives back the total number of rules in the ruleset. Note: each AST element has a set of corresponding rules in the rule map.
func (RuleMapType) GetRuleByName ¶
func (ruleMap RuleMapType) GetRuleByName(ruleName string, astElement interface{}) Rule
GetRuleByName searches for the rule by its ExampleName in the main rule map.
type RuleValidationResult ¶
type RuleValidationResult struct { LocationRange LocationRange // contains filtered or unexported fields }
func NewRuleValidationResult ¶
func NewRuleValidationResult(rule *Rule, isViolated bool, message string, locationRange LocationRange) *RuleValidationResult
func ValidateCmd001 ¶
func ValidateCmd001(cmdCommand *instructions.CmdCommand) RuleValidationResult
func ValidateCpy001 ¶
func ValidateCpy001(copyCommand *instructions.CopyCommand) RuleValidationResult
checks COPY options format for obvious errors --[option]=...
func ValidateCpy002 ¶
func ValidateCpy002(copyCommand *instructions.CopyCommand) RuleValidationResult
checks COPY --chmod option format for obvious errors --chmod=XXXX, where XXXX is a valid permission set value.
func ValidateCpy003 ¶
func ValidateCpy003(copyCommand *instructions.CopyCommand) RuleValidationResult
func ValidateCpy004 ¶
func ValidateCpy004(copyCommand *instructions.CopyCommand) RuleValidationResult
func ValidateCpy005 ¶
func ValidateCpy005(copyCommand *instructions.CopyCommand) RuleValidationResult
func ValidateCpy006 ¶
func ValidateCpy006(stage instructions.Stage) RuleValidationResult
func ValidateEnt001 ¶
func ValidateEnt001(entrypointCommand *instructions.EntrypointCommand) RuleValidationResult
func ValidateExp001 ¶
func ValidateExp001(exposeCommand *instructions.ExposeCommand) RuleValidationResult
func ValidateMtr001 ¶
func ValidateMtr001(maintainerCommand *instructions.MaintainerCommand) RuleValidationResult
func ValidateRun001 ¶
func ValidateRun001(runCommand *instructions.RunCommand) RuleValidationResult
func ValidateRun002 ¶
func ValidateRun002(runCommand *instructions.RunCommand) RuleValidationResult
nolint:funlen
func ValidateRun003 ¶
func ValidateRun003(runCommand *instructions.RunCommand) RuleValidationResult
func ValidateRun004 ¶
func ValidateRun004(runCommand *instructions.RunCommand) RuleValidationResult
func ValidateRun005 ¶
func ValidateRun005(runCommand *instructions.RunCommand) RuleValidationResult
func ValidateRun006 ¶
func ValidateRun006(runCommand *instructions.RunCommand) RuleValidationResult
func ValidateRun007 ¶
func ValidateRun007(runCommand *instructions.RunCommand) RuleValidationResult
func ValidateRun008 ¶
func ValidateRun008(runCommand *instructions.RunCommand) RuleValidationResult
func ValidateRun009 ¶
func ValidateRun009(runCommand *instructions.RunCommand) RuleValidationResult
nolint: funlen, nestif
func ValidateRun010 ¶
func ValidateRun010(runCommand *instructions.RunCommand) RuleValidationResult
func ValidateStl001 ¶
func ValidateStl001(stageList []instructions.Stage) RuleValidationResult
func ValidateSts001 ¶
func ValidateSts001(stage instructions.Stage) RuleValidationResult
func ValidateSts002 ¶
func ValidateSts002(stage instructions.Stage) RuleValidationResult
func ValidateSts003 ¶
func ValidateSts003(stage instructions.Stage) RuleValidationResult
func ValidateSts004 ¶
func ValidateSts004(stage instructions.Stage) RuleValidationResult
func ValidateUsr001 ¶
func ValidateUsr001(stageList []instructions.Stage) RuleValidationResult
func ValidateWkd001 ¶
func ValidateWkd001(workdirCommand *instructions.WorkdirCommand) RuleValidationResult
func (*RuleValidationResult) Description ¶
func (ruleValidationResult *RuleValidationResult) Description() string
func (RuleValidationResult) IsViolated ¶
func (ruleValidationResult RuleValidationResult) IsViolated() bool
func (*RuleValidationResult) Location ¶
func (ruleValidationResult *RuleValidationResult) Location() *LocationRange
func (*RuleValidationResult) MarshalJSON ¶
func (ruleValidationResult *RuleValidationResult) MarshalJSON() ([]byte, error)
func (*RuleValidationResult) Message ¶
func (ruleValidationResult *RuleValidationResult) Message() string
func (*RuleValidationResult) RuleID ¶
func (ruleValidationResult *RuleValidationResult) RuleID() string
func (*RuleValidationResult) SetLocation ¶
func (ruleValidationResult *RuleValidationResult) SetLocation(startLineNumber, startCharNumber, endLineNumber, endCharNumber int)
func (*RuleValidationResult) SetLocationRangeFrom ¶
func (ruleValidationResult *RuleValidationResult) SetLocationRangeFrom(locationRange LocationRange)
func (*RuleValidationResult) SetRule ¶
func (ruleValidationResult *RuleValidationResult) SetRule(rule *Rule)
func (*RuleValidationResult) SetViolated ¶
func (ruleValidationResult *RuleValidationResult) SetViolated(params ...bool)
func (*RuleValidationResult) Severity ¶
func (ruleValidationResult *RuleValidationResult) Severity() Severity
func (*RuleValidationResult) UnmarshalJSON ¶
func (ruleValidationResult *RuleValidationResult) UnmarshalJSON(data []byte) error
type Severity ¶
type Severity int
Severity type represents a severity, with an int level and a String function.
func GetSeverityList ¶
func GetSeverityList() []Severity
GetSeverityList returns a list of all the Severity values.
func (Severity) MarshalJSON ¶
func (Severity) String ¶
Severity.String() converts the raw Severity into a string. Chose not to use "go:generate stringer -type=Severity" due this being much more readable.
func (*Severity) UnmarshalJSON ¶
Source Files
¶
- cmd001.go
- cpy001.go
- cpy002.go
- cpy003.go
- cpy004.go
- cpy005.go
- cpy006.go
- docs_mock.go
- docsreference.go
- ent001.go
- exp001.go
- locationrange.go
- mtr001.go
- newcommand.go
- rule.go
- run001.go
- run002.go
- run003.go
- run004.go
- run005.go
- run006.go
- run007.go
- run008.go
- run009.go
- run010.go
- stl001.go
- sts001.go
- sts002.go
- sts003.go
- sts004.go
- usr001.go
- validationresult.go
- wkd001.go