Skip to content

Commit

Permalink
chore: explicit revive rules
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
  • Loading branch information
mmorel-35 committed Jan 24, 2025
1 parent cc66d6d commit bb1dc3f
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 60 deletions.
39 changes: 39 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,45 @@ linters-settings:
strconcat: false
revive:
ignore-generated-header: true
min-confidence: 0.8
rules:
- name: blank-imports
- name: context-as-argument
arguments:
- allowTypesBefore: "*testing.T"
- name: context-keys-type
- name: dot-imports
- name: early-return
arguments:
- "preserveScope"
- name: empty-block
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: increment-decrement
disabled: true
- name: indent-error-flow
arguments:
- "preserveScope"
- name: range
- name: receiver-naming
disabled: true
- name: redefines-builtin-id
- name: superfluous-else
arguments:
- "preserveScope"
- name: time-naming
- name: unexported-return
disabled: true
- name: unreachable-code
- name: unused-parameter
disabled: true
- name: use-any
- name: var-declaration
disabled: true
- name: var-naming
disabled: true
testifylint:
enable-all: true
linters:
Expand Down
8 changes: 4 additions & 4 deletions magefiles/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ func init() {
}

func version() (string, error) {
if ver, err := sh.Output("git", "describe", "--tags", "--always"); err != nil {
ver, err := sh.Output("git", "describe", "--tags", "--always")
if err != nil {
return "", err
} else {
// Strips the v prefix from the tag
return strings.TrimPrefix(ver, "v"), nil
}
// Strips the v prefix from the tag
return strings.TrimPrefix(ver, "v"), nil
}

func buildLdflags() (string, error) {
Expand Down
7 changes: 3 additions & 4 deletions pkg/dependency/parser/c/conan/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,10 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependenc
if lock.GraphLock.Nodes != nil {
p.logger.Debug("Handling conan lockfile as v1.x")
return p.parseV1(lock)
} else {
// try to parse requirements as conan v2.x
p.logger.Debug("Handling conan lockfile as v2.x")
return p.parseV2(lock)
}
// try to parse requirements as conan v2.x
p.logger.Debug("Handling conan lockfile as v2.x")
return p.parseV2(lock)
}

func parsePackage(text string) (string, string, error) {
Expand Down
15 changes: 6 additions & 9 deletions pkg/dependency/parser/java/pom/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,28 +549,25 @@ func (p *Parser) retrieveParent(currentPath, relativePath string, target artifac
// Try relativePath
if relativePath != "" {
pom, err := p.tryRelativePath(target, currentPath, relativePath)
if err != nil {
errs = multierror.Append(errs, err)
} else {
if err == nil {
return pom, nil
}
errs = multierror.Append(errs, err)
}

// If not found, search the parent director
pom, err := p.tryRelativePath(target, currentPath, "../pom.xml")
if err != nil {
errs = multierror.Append(errs, err)
} else {
if err == nil {
return pom, nil
}
errs = multierror.Append(errs, err)

// If not found, search local/remote remoteRepositories
pom, err = p.tryRepository(target.GroupID, target.ArtifactID, target.Version.String())
if err != nil {
errs = multierror.Append(errs, err)
} else {
if err == nil {
return pom, nil
}
errs = multierror.Append(errs, err)

// Reaching here means the POM wasn't found
return nil, errs
Expand Down
19 changes: 9 additions & 10 deletions pkg/dependency/parser/nodejs/yarn/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,10 @@ func (p *Parser) parseBlock(block []byte, lineNum int) (lib Library, deps []stri
continue
}
continue
} else {
lib.Patterns = patterns
lib.Name = name
continue
}
lib.Patterns = patterns
lib.Name = name
continue
}
}

Expand All @@ -251,23 +250,23 @@ func (p *Parser) parseBlock(block []byte, lineNum int) (lib Library, deps []stri
func parseDependencies(scanner *LineScanner) (deps []string) {
for scanner.Scan() {
line := scanner.Text()
if dep, err := parseDependency(line); err != nil {
dep, err := parseDependency(line)
if err != nil {
// finished dependencies block
return deps
} else {
deps = append(deps, dep)
}
deps = append(deps, dep)
}

return
}

func parseDependency(line string) (string, error) {
if name, version, err := getDependency(line); err != nil {
name, version, err := getDependency(line)
if err != nil {
return "", err
} else {
return packageID(name, version), nil
}
return packageID(name, version), nil
}

func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependency, map[string][]string, error) {
Expand Down
5 changes: 2 additions & 3 deletions pkg/dependency/parser/ruby/bundler/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,10 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependenc
func countLeadingSpace(line string) int {
i := 0
for _, runeValue := range line {
if runeValue == ' ' {
i++
} else {
if runeValue != ' ' {
break
}
i++
}
return i
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/dependency/parser/rust/cargo/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,8 @@ func (p *Parser) parseDependencies(pkgId string, pkg cargoPkg, pkgs map[string]c
ID: pkgId,
DependsOn: dependOn,
}
} else {
return nil
}
return nil
}

func packageID(name, version string) string {
Expand Down
10 changes: 5 additions & 5 deletions pkg/iac/adapters/cloudformation/aws/s3/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ func getLifecycle(resource *parser.Resource) []s3.Rules {
}

func getWebsite(r *parser.Resource) *s3.Website {
if block := r.GetProperty("WebsiteConfiguration"); block.IsNil() {
block := r.GetProperty("WebsiteConfiguration")
if block.IsNil() {
return nil
} else {
return &s3.Website{
Metadata: block.Metadata(),
}
}
return &s3.Website{
Metadata: block.Metadata(),
}
}

Expand Down
5 changes: 2 additions & 3 deletions pkg/iac/scanners/azure/functions/date_time_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ func parseISO8601(from string) (Iso8601Duration, error) {
var match []string
var d Iso8601Duration

if pattern.MatchString(from) {
match = pattern.FindStringSubmatch(from)
} else {
if !pattern.MatchString(from) {
return d, errors.New("could not parse duration string")
}
match = pattern.FindStringSubmatch(from)

for i, name := range pattern.SubexpNames() {
part := match[i]
Expand Down
6 changes: 3 additions & 3 deletions pkg/iac/scanners/cloudformation/parser/fn_find_in_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func ResolveFindInMap(property *Property) (resolved *Property, success bool) {

mapValues := k.(map[string]any)

if prop, ok := mapValues[secondaryLevelKey]; !ok {
prop, ok := mapValues[secondaryLevelKey]
if !ok {
return abortIntrinsic(property, "could not find a value for %s in %s, returning original Property", secondaryLevelKey, topLevelKey)
} else {
return property.deriveResolved(cftypes.String, prop), true
}
return property.deriveResolved(cftypes.String, prop), true
}
3 changes: 1 addition & 2 deletions pkg/iac/scanners/cloudformation/parser/fn_if.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func ResolveIf(property *Property) (resolved *Property, success bool) {

if conditionMet {
return trueState, true
} else {
return falseState, true
}
return falseState, true
}
7 changes: 3 additions & 4 deletions pkg/iac/scanners/cloudformation/parser/fn_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ func ResolveSelect(property *Property) (resolved *Property, success bool) {
list := refValue[1]

if index.IsNotInt() {
if index.IsConvertableTo(cftypes.Int) {
//
index = index.ConvertTo(cftypes.Int)
} else {
if !index.IsConvertableTo(cftypes.Int) {
return abortIntrinsic(property, "index on property [%s] should be an int, returning original Property", property.name)
}
//
index = index.ConvertTo(cftypes.Int)
}

if list.IsNotList() {
Expand Down
3 changes: 1 addition & 2 deletions pkg/iac/scanners/cloudformation/parser/property.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,8 @@ func (p *Property) GetProperty(path string) *Property {
if nestedProperty.isFunction() {
resolved, _ := nestedProperty.resolveValue()
return resolved
} else {
return nestedProperty
}
return nestedProperty
}

return &Property{}
Expand Down
12 changes: 6 additions & 6 deletions pkg/iac/terraform/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,11 @@ func (b *Block) GetNestedAttribute(name string) (*Attribute, *Block) {

working := b
for _, subBlock := range blocks {
if checkBlock := working.GetBlock(subBlock); checkBlock == nil {
checkBlock := working.GetBlock(subBlock)
if checkBlock == nil {
return nil, working
} else {
working = checkBlock
}
working = checkBlock
}

if working != nil {
Expand Down Expand Up @@ -532,11 +532,11 @@ func (b *Block) MissingNestedChild(name string) bool {

working := b
for _, subBlock := range blocks {
if checkBlock := working.GetBlock(subBlock); checkBlock == nil {
checkBlock := working.GetBlock(subBlock)
if checkBlock == nil {
return true
} else {
working = checkBlock
}
working = checkBlock
}
return !working.HasChild(last)

Expand Down
6 changes: 3 additions & 3 deletions pkg/rekortest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,12 @@ func NewServer(t *testing.T) *Server {

resEntries := models.LogEntry{}
for _, uuid := range params.EntryUUIDs {
if e, ok := entries[uuid]; !ok {
e, ok := entries[uuid]
if !ok {
http.Error(w, "no such uuid", http.StatusNotFound)
return
} else {
resEntries[uuid] = e
}
resEntries[uuid] = e
}
w.Header().Set("Content-Type", "application/json")
err = json.NewEncoder(w).Encode([]models.LogEntry{resEntries})
Expand Down

0 comments on commit bb1dc3f

Please sign in to comment.