diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 300be0de..daf1cc42 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 64f8c672..7a61f7f9 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -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 diff --git a/README.md b/README.md index 23aea785..fce36db2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -![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) diff --git a/src/common/yaml/yaml_writer.go b/src/common/yaml/yaml_writer.go index e7aebc00..eac89036 100644 --- a/src/common/yaml/yaml_writer.go +++ b/src/common/yaml/yaml_writer.go @@ -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 } @@ -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] @@ -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 } }