Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanochShayner committed Jun 27, 2024
1 parent c6a0b50 commit 89dbff4
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 30 deletions.
1 change: 1 addition & 0 deletions src/cloudformation/structure/cloudformation_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func (p *CloudformationParser) extractTagsAndLines(filePath string, lines *struc
func (p *CloudformationParser) GetExistingTags(tagsValue reflect.Value) []tags.ITag {
existingTags := make([]goformationTags.Tag, 0)
if tagsValue.Kind() == reflect.Slice {
//nolint:ineffassign
ok := true
existingTags, ok = tagsValue.Interface().([]goformationTags.Tag)
if !ok {
Expand Down
1 change: 1 addition & 0 deletions src/common/json/json_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func AddTagsToResourceStr(fullOriginStr string, resourceBlock structure.IBlock,
parentIdentifier = FindParentIdentifier(jsonResourceStr, parentIdentifier)
if parentIdentifier == "" {
identifiersToAdd = append(identifiersToAdd, resourceBlock.GetResourceID())
//nolint:ineffassign
parentIdentifier = resourceBlock.GetResourceID()
break
}
Expand Down
11 changes: 5 additions & 6 deletions src/common/logger/logging_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import (
)

type loggingService struct {
logLevel LogLevel
stdout *os.File
stderr *os.File
tempWriter *os.File
disabled bool
muteLock sync.Mutex
logLevel LogLevel
stdout *os.File
stderr *os.File
disabled bool
muteLock sync.Mutex
}

type LogLevel int
Expand Down
4 changes: 2 additions & 2 deletions src/common/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ type Runner struct {
skippedResources []string
workersNum int
dryRun bool
localModuleTag bool
}

const WorkersNumEnvKey = "YOR_WORKER_NUM"
Expand Down Expand Up @@ -92,7 +91,8 @@ func (r *Runner) Init(commands *clioptions.TagOptions) error {
r.reportingService = reports.ReportServiceInst
r.dir = commands.Directory
r.skippedTags = commands.SkipTags
r.skipDirs = append(commands.SkipDirs, ".git")
commands.SkipDirs = append(commands.SkipDirs, ".git")
r.skipDirs = commands.SkipDirs
r.configFilePath = commands.ConfigFile
r.dryRun = commands.DryRun
if utils.InSlice(r.skipDirs, r.dir) {
Expand Down
1 change: 1 addition & 0 deletions src/common/tagging/code2cloud/tag_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package code2cloud

import (
"fmt"

"github.com/bridgecrewio/yor/src/common/logger"
"github.com/bridgecrewio/yor/src/common/structure"
"github.com/bridgecrewio/yor/src/common/tagging"
Expand Down
1 change: 1 addition & 0 deletions src/common/tagging/code2cloud/yor_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package code2cloud

import (
"fmt"

"github.com/bridgecrewio/yor/src/common/structure"
"github.com/bridgecrewio/yor/src/common/tagging/tags"
"reflect"
Expand Down
19 changes: 3 additions & 16 deletions src/common/yaml/yaml_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func WriteYAMLFile(readFilePath string, blocks []structure.IBlock, writeFilePath
}
for _, resourceBlock := range blocks {
rawBlock := resourceBlock.GetRawBlock()
newResourceLines := getYAMLLines(rawBlock, isCfn)
newResourceLines := getYAMLLines(rawBlock)
newResourceTagLineRange, _ := FindTagsLinesYAML(newResourceLines, tagsAttributeName)
oldResourceLinesRange := resourceBlock.GetLines()
oldResourceLines := originLines[oldResourceLinesRange.Start : oldResourceLinesRange.End+1]
Expand Down Expand Up @@ -213,7 +213,7 @@ func computeResourcesLineRange(originLines []string, blocks []structure.IBlock,
return ret
}

func getYAMLLines(rawBlock interface{}, isCfn bool) []string {
func getYAMLLines(rawBlock interface{}) []string {
var textLines []string
yamlBytes, err := yaml.Marshal(rawBlock)
if err != nil {
Expand All @@ -225,20 +225,6 @@ func getYAMLLines(rawBlock interface{}, isCfn bool) []string {
return textLines
}

func removeLineByAttribute(textLines []string, attribute string) []string {
vpcLineIndex := -1
for i, line := range textLines {
if strings.Contains(line, attribute) {
vpcLineIndex = i
break
}
}
if vpcLineIndex != -1 {
textLines = append(textLines[:vpcLineIndex], textLines[vpcLineIndex+1:]...)
}
return textLines
}

func FindTagsLinesYAML(textLines []string, tagsAttributeName string) (structure.Lines, bool) {
tagsLines := structure.Lines{Start: -1, End: -1}
var lineIndent string
Expand Down Expand Up @@ -296,6 +282,7 @@ func MapResourcesLineYAML(filePath string, resourceNames []string, resourcesStar
lineIndent := countLeadingSpaces(line)
if lineIndent <= resourcesIndent && strings.TrimSpace(line) != "" && !strings.Contains(line, "#") {
// No longer inside resources block, get the last line of the previous resource if exists
//nolint:ineffassign
readResources = false
if latestResourceName != "" {
resourceToLines[latestResourceName].End = findLastNonEmptyLine(fileLines, i-1)
Expand Down
4 changes: 2 additions & 2 deletions src/common/yaml/yaml_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ func TestTagReplacement(t *testing.T) {
})

t.Run("Test line computation with duplicate - CFN", func(t *testing.T) {
res := MapResourcesLineYAML("../../../tests/cloudformation/resources/duplicate_entries/duplicate_cfn.yaml", []string{"S3Bucket", "CloudFrontDistribution"}, "Resources")
res, _ := MapResourcesLineYAML("../../../tests/cloudformation/resources/duplicate_entries/duplicate_cfn.yaml", []string{"S3Bucket", "CloudFrontDistribution"}, "Resources")

Check failure on line 231 in src/common/yaml/yaml_writer_test.go

View workflow job for this annotation

GitHub Actions / unit-test (1.19)

assignment mismatch: 2 variables but MapResourcesLineYAML returns 1 value
assert.Equal(t, *res["S3Bucket"], structure.Lines{Start: 14, End: 17})
assert.Equal(t, *res["CloudFrontDistribution"], structure.Lines{Start: 18, End: 60})
})

t.Run("Test line computation with duplicate - SLS", func(t *testing.T) {
res := MapResourcesLineYAML("../../../tests/cloudformation/resources/duplicate_entries/duplicate_sls.yaml", []string{"attribute", "zone", "customer", "apiVersion"}, "functions")
res, _ := MapResourcesLineYAML("../../../tests/cloudformation/resources/duplicate_entries/duplicate_sls.yaml", []string{"attribute", "zone", "customer", "apiVersion"}, "functions")

Check failure on line 237 in src/common/yaml/yaml_writer_test.go

View workflow job for this annotation

GitHub Actions / unit-test (1.19)

assignment mismatch: 2 variables but MapResourcesLineYAML returns 1 value
assert.Equal(t, *res["apiVersion"], structure.Lines{Start: 7, End: 12})
assert.Equal(t, *res["customer"], structure.Lines{Start: 14, End: 24})
assert.Equal(t, *res["zone"], structure.Lines{Start: 26, End: 38})
Expand Down
6 changes: 2 additions & 4 deletions src/serverless/structure/serverless_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package structure
import (
"encoding/json"
"fmt"
"github.com/bridgecrewio/goformation/v5/intrinsics"
"math"
"os"
"path/filepath"
"strings"
"sync"

"github.com/bridgecrewio/goformation/v5/intrinsics"
"github.com/bridgecrewio/yor/src/common"
"github.com/bridgecrewio/yor/src/common/logger"
"github.com/bridgecrewio/yor/src/common/structure"
Expand Down Expand Up @@ -37,9 +37,7 @@ func (p *ServerlessParser) Init(rootDir string, _ map[string]string) {
p.YamlParser.RootDir = rootDir
}

func (p *ServerlessParser) Close() {
return
}
func (p *ServerlessParser) Close() {}

func (p *ServerlessParser) GetSkippedDirs() []string {
return []string{}
Expand Down

0 comments on commit 89dbff4

Please sign in to comment.