Skip to content

887 integrate lint in flow #891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions pkg/linter/linterExecute.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func IsValidLintersNames(name string) bool {
_, ok := linterGenerators[name]
return ok
}
func generateLinters(configs map[string]*vpcmodel.VPCConfig, nodeConn map[string]*vpcmodel.VPCConnectivity) []linter {
func generateLinters(configs map[string]*vpcmodel.VPCConfig, nodeConn map[string]*vpcmodel.VPCConnectivity) Linters {
res := make([]linter, len(linterGenerators))
i := 0
for name, generator := range linterGenerators {
Expand All @@ -65,17 +65,27 @@ func computeConnectivity(configs map[string]*vpcmodel.VPCConfig) (map[string]*vp
return nodesConn, nil
}

// //////////////////////////////////////////////////////////////////////////////////////////////
// LinterExecute executes linters one by one
// LinterExecute performs the lint analysis and then prints the string result; should be redundant once lint is
// integrated in the general flow
func LinterExecute(configs map[string]*vpcmodel.VPCConfig, printAllFindings bool,
enableList, disableList []string) (issueFound bool, resString string, err error) {
nodesConn, err := computeConnectivity(configs)
linters, err := linterAnalysis(configs, enableList, disableList)
if err != nil {
return false, "", err
}
resString = linters.String(printAllFindings)
fmt.Println(resString)
return issueFound, resString, nil
}

linters := generateLinters(configs, nodesConn)
strPerLint := []string{}
// linterAnalysis executes linters one by one and collects their results
func linterAnalysis(configs map[string]*vpcmodel.VPCConfig, enableList, disableList []string) (linters Linters, err error) {
nodesConn, err := computeConnectivity(configs)
if err != nil {
return nil, err
}

linters = generateLinters(configs, nodesConn)
for _, thisLinter := range linters {
name := thisLinter.lintName()
enable := thisLinter.enableByDefault()
Expand All @@ -84,14 +94,20 @@ func LinterExecute(configs map[string]*vpcmodel.VPCConfig, printAllFindings bool
if !enable {
continue
}
thisLintStr := ""
err := thisLinter.check()
if err != nil {
return false, "", err
return nil, err
}
}
return linters, nil
}

func (linters Linters) String(printAllFindings bool) (resString string) {
strPerLint := []string{}
for _, thisLinter := range linters {
thisLintStr := ""
lintFindings := thisLinter.getFindings()
if len(lintFindings) > 0 {
issueFound = true
thisLintStr = thisLinter.string(thisLinter.lintDescription(), printAllFindings)
strPerLint = append(strPerLint, thisLintStr)
}
Expand All @@ -100,5 +116,5 @@ func LinterExecute(configs map[string]*vpcmodel.VPCConfig, printAllFindings bool
delimBetweenLints := strings.Repeat("_", delimBetweenLintsChars)
resString = strings.Join(strPerLint, "\n"+delimBetweenLints+"\n\n")
fmt.Println(resString)
return issueFound, resString, nil
return resString
}
2 changes: 2 additions & 0 deletions pkg/linter/linterTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (

const numFindingToPrint = 3

type Linters []linter

type linter interface {
check() error
getFindings() []finding // returns all findings detected by the linter
Expand Down