Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/github/codeql-acti…
Browse files Browse the repository at this point in the history
…on-2.22.9
  • Loading branch information
Saarett authored Dec 17, 2023
2 parents 31b0737 + 9667e17 commit d88783d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,15 @@ jobs:
linter:
name: golangci-lint
runs-on: [self-hosted, public, linux, x64]
permissions:
checks: write
contents: read
pull-requests: write
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
- name: golangci-lint
uses: reviewdog/action-golangci-lint@79d32f10b2ea0d4cebb755d849b048c4b40c3d50 # v2
uses: reviewdog/action-golangci-lint@94d61e3205b61acf4ddabfeb13c5f8a13eb4167b # v2
with:
tool_name: golangci-lint
fail_on_error: true
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ jobs:
linter:
name: golangci-lint
runs-on: ubuntu-latest
permissions:
checks: write
contents: read
pull-requests: write
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
- name: golangci-lint
uses: reviewdog/action-golangci-lint@79d32f10b2ea0d4cebb755d849b048c4b40c3d50 # v2
uses: reviewdog/action-golangci-lint@94d61e3205b61acf4ddabfeb13c5f8a13eb4167b # v2
with:
tool_name: golangci-lint
fail_on_error: true
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<img src="https://raw.githubusercontent.com/bridgecrewio/yor/master/docs/yor-logo.png?" width="350">

![Coverage](https://img.shields.io/badge/Coverage-81.2%25-brightgreen)
![Coverage](https://img.shields.io/badge/Coverage-81.1%25-brightgreen)
[![Maintained by Bridgecrew.io](https://img.shields.io/badge/maintained%20by-bridgecrew.io-blueviolet)](https://bridgecrew.io/?utm_source=github&utm_medium=organic_oss&utm_campaign=yor)
![golangci-lint](https://github.com/bridgecrewio/yor/workflows/tests/badge.svg)
[![security](https://github.com/bridgecrewio/yor/actions/workflows/security.yml/badge.svg)](https://github.com/bridgecrewio/yor/actions/workflows/security.yml)
Expand Down
18 changes: 14 additions & 4 deletions src/common/yaml/yaml_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,16 @@ func WriteYAMLFile(readFilePath string, blocks []structure.IBlock, writeFilePath
if isCfn {
tagIndent += SingleIndent
}
resourcesLines = append(resourcesLines, IndentLines(newResourceLines[newResourceTagLineRange.Start+1:newResourceTagLineRange.End+1], tagIndent)...)
resourcesLines = append(resourcesLines, IndentLines(newResourceLines[newResourceTagLineRange.Start+1:newResourceTagLineRange.End+1], tagIndent, 0)...)
resourcesLines = append(resourcesLines, oldResourceLines[lastIndex+1:]...)
continue
}

oldTagsIndent := ExtractIndentationOfLine(oldResourceLines[oldResourceTagLines.Start-oldResourceLinesRange.Start])
oldTagsValueIndent := len(ExtractIndentationOfLine(oldResourceLines[oldResourceTagLines.Start-oldResourceLinesRange.Start+1])) - len(oldTagsIndent)
if isCfn {
oldTagsValueIndent = 0
}
if isCfn {
oldTagsIndent += SingleIndent
}
Expand All @@ -87,7 +91,7 @@ func WriteYAMLFile(readFilePath string, blocks []structure.IBlock, writeFilePath
} else {
UpdateExistingSLSTags(tagLines, diff.Updated)
}
allNewResourceTagLines := IndentLines(newResourceLines[newResourceTagLineRange.Start+1:newResourceTagLineRange.End+1], oldTagsIndent)
allNewResourceTagLines := IndentLines(newResourceLines[newResourceTagLineRange.Start+1:newResourceTagLineRange.End+1], oldTagsIndent, oldTagsValueIndent)
var netNewResourceLines []string
for i := 0; i < len(allNewResourceTagLines); i += linesPerTag {
l := allNewResourceTagLines[i]
Expand Down Expand Up @@ -337,13 +341,19 @@ func findLastNonEmptyLine(fileLines []string, maxIndex int) int {
return 0
}

func IndentLines(textLines []string, indent string) []string {
func IndentLines(textLines []string, indent string, valueIndent int) []string {
for i, originLine := range textLines {
var blankSpaces string
if valueIndent == 0 {
blankSpaces = SingleIndent
} else {
blankSpaces = strings.Repeat(" ", valueIndent)
}
noLeadingWhitespace := strings.TrimLeft(originLine, "\t \n")
if strings.Contains(originLine, "- Key") {
textLines[i] = indent + noLeadingWhitespace
} else {
textLines[i] = indent + SingleIndent + noLeadingWhitespace
textLines[i] = indent + blankSpaces + noLeadingWhitespace
}
}

Expand Down

0 comments on commit d88783d

Please sign in to comment.