mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
vendor: update buildkit to v0.16.0-rc1
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
89
vendor/github.com/moby/buildkit/frontend/dockerfile/linter/linter.go
generated
vendored
89
vendor/github.com/moby/buildkit/frontend/dockerfile/linter/linter.go
generated
vendored
@ -10,42 +10,61 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Warn LintWarnFunc
|
||||
SkipRules []string
|
||||
SkipAll bool
|
||||
ReturnAsError bool
|
||||
ExperimentalAll bool
|
||||
ExperimentalRules []string
|
||||
ReturnAsError bool
|
||||
SkipAll bool
|
||||
SkipRules []string
|
||||
Warn LintWarnFunc
|
||||
}
|
||||
|
||||
type Linter struct {
|
||||
SkippedRules map[string]struct{}
|
||||
CalledRules []string
|
||||
SkipAll bool
|
||||
ReturnAsError bool
|
||||
Warn LintWarnFunc
|
||||
CalledRules []string
|
||||
ExperimentalAll bool
|
||||
ExperimentalRules map[string]struct{}
|
||||
ReturnAsError bool
|
||||
SkipAll bool
|
||||
SkippedRules map[string]struct{}
|
||||
Warn LintWarnFunc
|
||||
}
|
||||
|
||||
func New(config *Config) *Linter {
|
||||
toret := &Linter{
|
||||
SkippedRules: map[string]struct{}{},
|
||||
CalledRules: []string{},
|
||||
Warn: config.Warn,
|
||||
SkippedRules: map[string]struct{}{},
|
||||
ExperimentalRules: map[string]struct{}{},
|
||||
CalledRules: []string{},
|
||||
Warn: config.Warn,
|
||||
}
|
||||
toret.SkipAll = config.SkipAll
|
||||
toret.ExperimentalAll = config.ExperimentalAll
|
||||
toret.ReturnAsError = config.ReturnAsError
|
||||
for _, rule := range config.SkipRules {
|
||||
toret.SkippedRules[rule] = struct{}{}
|
||||
}
|
||||
for _, rule := range config.ExperimentalRules {
|
||||
toret.ExperimentalRules[rule] = struct{}{}
|
||||
}
|
||||
return toret
|
||||
}
|
||||
|
||||
func (lc *Linter) Run(rule LinterRuleI, location []parser.Range, txt ...string) {
|
||||
if lc == nil || lc.Warn == nil || lc.SkipAll || rule.IsDeprecated() {
|
||||
if lc == nil || lc.Warn == nil || rule.IsDeprecated() {
|
||||
return
|
||||
}
|
||||
|
||||
rulename := rule.RuleName()
|
||||
if _, ok := lc.SkippedRules[rulename]; ok {
|
||||
return
|
||||
if rule.IsExperimental() {
|
||||
_, experimentalOk := lc.ExperimentalRules[rulename]
|
||||
if !(lc.ExperimentalAll || experimentalOk) {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
_, skipOk := lc.SkippedRules[rulename]
|
||||
if lc.SkipAll || skipOk {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
lc.CalledRules = append(lc.CalledRules, rulename)
|
||||
rule.Run(lc.Warn, location, txt...)
|
||||
}
|
||||
@ -72,14 +91,16 @@ type LinterRuleI interface {
|
||||
RuleName() string
|
||||
Run(warn LintWarnFunc, location []parser.Range, txt ...string)
|
||||
IsDeprecated() bool
|
||||
IsExperimental() bool
|
||||
}
|
||||
|
||||
type LinterRule[F any] struct {
|
||||
Name string
|
||||
Description string
|
||||
Deprecated bool
|
||||
URL string
|
||||
Format F
|
||||
Name string
|
||||
Description string
|
||||
Deprecated bool
|
||||
Experimental bool
|
||||
URL string
|
||||
Format F
|
||||
}
|
||||
|
||||
func (rule *LinterRule[F]) RuleName() string {
|
||||
@ -98,6 +119,10 @@ func (rule *LinterRule[F]) IsDeprecated() bool {
|
||||
return rule.Deprecated
|
||||
}
|
||||
|
||||
func (rule *LinterRule[F]) IsExperimental() bool {
|
||||
return rule.Experimental
|
||||
}
|
||||
|
||||
func LintFormatShort(rulename, msg string, line int) string {
|
||||
msg = fmt.Sprintf("%s: %s", rulename, msg)
|
||||
if line > 0 {
|
||||
@ -114,9 +139,9 @@ func ParseLintOptions(checkStr string) (*Config, error) {
|
||||
return &Config{}, nil
|
||||
}
|
||||
|
||||
parts := strings.SplitN(checkStr, ";", 2)
|
||||
var skipSet []string
|
||||
var errorOnWarn, skipAll bool
|
||||
parts := strings.SplitN(checkStr, ";", 3)
|
||||
var skipSet, experimentalSet []string
|
||||
var errorOnWarn, skipAll, experimentalAll bool
|
||||
for _, p := range parts {
|
||||
k, v, ok := strings.Cut(p, "=")
|
||||
if !ok {
|
||||
@ -134,6 +159,16 @@ func ParseLintOptions(checkStr string) (*Config, error) {
|
||||
skipSet[i] = strings.TrimSpace(rule)
|
||||
}
|
||||
}
|
||||
case "experimental":
|
||||
v = strings.TrimSpace(v)
|
||||
if v == "all" {
|
||||
experimentalAll = true
|
||||
} else {
|
||||
experimentalSet = strings.Split(v, ",")
|
||||
for i, rule := range experimentalSet {
|
||||
experimentalSet[i] = strings.TrimSpace(rule)
|
||||
}
|
||||
}
|
||||
case "error":
|
||||
v, err := strconv.ParseBool(strings.TrimSpace(v))
|
||||
if err != nil {
|
||||
@ -145,8 +180,10 @@ func ParseLintOptions(checkStr string) (*Config, error) {
|
||||
}
|
||||
}
|
||||
return &Config{
|
||||
SkipRules: skipSet,
|
||||
SkipAll: skipAll,
|
||||
ReturnAsError: errorOnWarn,
|
||||
ExperimentalAll: experimentalAll,
|
||||
ExperimentalRules: experimentalSet,
|
||||
SkipRules: skipSet,
|
||||
SkipAll: skipAll,
|
||||
ReturnAsError: errorOnWarn,
|
||||
}, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user