import-verifier: use yaml for inline comments

This commit is contained in:
Dr. Stefan Schimanski
2017-10-25 16:21:54 +02:00
parent d51d7fd26f
commit 024122a9c6
5 changed files with 82 additions and 103 deletions

View File

@@ -16,6 +16,7 @@ go_library(
name = "go_default_library",
srcs = ["importverifier.go"],
importpath = "k8s.io/kubernetes/cmd/importverifier",
deps = ["//vendor/gopkg.in/yaml.v2:go_default_library"],
)
filegroup(

View File

@@ -27,15 +27,17 @@ import (
"os/exec"
"path/filepath"
"strings"
"gopkg.in/yaml.v2"
)
// Package is a subset of cmd/go.Package
type Package struct {
Dir string `json:",omitempty"` // directory containing package sources
ImportPath string `json:",omitempty"` // import path of package in dir
Imports []string `json:",omitempty"` // import paths used by this package
TestImports []string `json:",omitempty"` // imports from TestGoFiles
XTestImports []string `json:",omitempty"` // imports from XTestGoFiles
Dir string `yaml:",omitempty"` // directory containing package sources
ImportPath string `yaml:",omitempty"` // import path of package in dir
Imports []string `yaml:",omitempty"` // import paths used by this package
TestImports []string `yaml:",omitempty"` // imports from TestGoFiles
XTestImports []string `yaml:",omitempty"` // imports from XTestGoFiles
}
// ImportRestriction describes a set of allowable import
@@ -44,17 +46,17 @@ type ImportRestriction struct {
// BaseDir is the root of the package tree that is
// restricted by this configuration, given as a
// relative path from the root of the repository
BaseDir string `json:"baseImportPath"`
BaseDir string `yaml:"baseImportPath"`
// IgnoredSubTrees are roots of sub-trees of the
// BaseDir for which we do not want to enforce
// any import restrictions whatsoever, given as
// relative paths from the root of the repository
IgnoredSubTrees []string `json:"ignoredSubTrees,omitempty"`
IgnoredSubTrees []string `yaml:"ignoredSubTrees,omitempty"`
// AllowedImports are roots of package trees that
// are allowed to be imported from the BaseDir,
// given as paths that would be used in a Go
// import statement
AllowedImports []string `json:"allowedImports"`
AllowedImports []string `yaml:"allowedImports"`
}
// ForbiddenImportsFor determines all of the forbidden
@@ -164,7 +166,7 @@ var rootPackage string
func main() {
if len(os.Args) != 3 {
log.Fatalf("Usage: %s ROOT RESTRICTIONS.json", os.Args[0])
log.Fatalf("Usage: %s ROOT RESTRICTIONS.yaml", os.Args[0])
}
rootPackage = os.Args[1]
@@ -214,7 +216,7 @@ func loadImportRestrictions(configFile string) ([]ImportRestriction, error) {
}
var importRestrictions []ImportRestriction
if err := json.Unmarshal(config, &importRestrictions); err != nil {
if err := yaml.Unmarshal(config, &importRestrictions); err != nil {
return nil, fmt.Errorf("failed to unmarshal from %s: %v", configFile, err)
}