Skip to content

Commit

Permalink
remove indent
Browse files Browse the repository at this point in the history
  • Loading branch information
kuritka committed Mar 18, 2021
1 parent f800e3d commit b98896d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 23 deletions.
16 changes: 8 additions & 8 deletions .golic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,21 @@ golic:
prefix: "/*"
suffix: "*/"
.yaml:
prefix: "#"
prefix: "# "
.yml:
prefix: "#"
prefix: "# "
Dockerfile*:
prefix: "#"
prefix: "# "
Makefile:
prefix: "#"
prefix: "# "
.gitignore:
prefix: "#"
prefix: "# "
.licignore:
prefix: "#"
prefix: "# "
.tf:
prefix: "#"
prefix: "# "
.sh:
prefix: "#"
prefix: "# "
under:
- "!/bin/sh"
- "!/bin/bash"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ create `.licignore` in project root
Install and run **GOLIC**
```shell
# GO 1.16
go install github.com/AbsaOSS/[email protected].5
go install github.com/AbsaOSS/[email protected].6
golic inject -c="2021 MyCompany ltd."
```

Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/spf13/cobra"
)

const version = "v0.4.5"
const version = "v0.4.6"

var versionCmd = &cobra.Command{
Use: "version",
Expand Down
1 change: 0 additions & 1 deletion impl/inject/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type Config struct {
Prefix string `yaml:"prefix"`
Suffix string `yaml:"suffix"`
Under []string `yaml:"under"`
Indent string `yaml:"indent"` // if NO_INDENT value, than indent is ""
} `yaml:"rules"`
} `yaml:"golic"`
}
Expand Down
18 changes: 6 additions & 12 deletions impl/inject/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,13 @@ func getCommentedLicense(config *Config, o Options, file string) (string, error)
nil
}
// `\r\n` -> `\r\n #`, `\n` -> `\n #`
var indent string
switch config.Golic.Rules[rule].Indent {
case "NO_INDENT": indent = ""
case "": indent = " "
default: indent = config.Golic.Rules[rule].Indent
}

content := strings.ReplaceAll(template,"\n",fmt.Sprintf("\n%s%s", config.Golic.Rules[rule].Prefix,indent))
content = strings.TrimSuffix(content, config.Golic.Rules[rule].Prefix+indent)
content = config.Golic.Rules[rule].Prefix + indent + content
content := strings.ReplaceAll(template,"\n",fmt.Sprintf("\n%s", config.Golic.Rules[rule].Prefix))
content = strings.TrimSuffix(content, config.Golic.Rules[rule].Prefix)
content = config.Golic.Rules[rule].Prefix + content
// "# \n" -> "#\n" // "# \r\n" -> "#\r\n"; some environments automatically remove spaces in empty lines. This makes problems in license PR's
content = strings.ReplaceAll(content,fmt.Sprintf("%s \n",config.Golic.Rules[rule].Prefix),fmt.Sprintf("%s\n",config.Golic.Rules[rule].Prefix))
content = strings.ReplaceAll(content,fmt.Sprintf("%s \r\n",config.Golic.Rules[rule].Prefix),fmt.Sprintf("%s\r\n",config.Golic.Rules[rule].Prefix))
cleanedPrefix := strings.TrimSuffix(config.Golic.Rules[rule].Prefix, " ")
content = strings.ReplaceAll(content,fmt.Sprintf("%s \n",cleanedPrefix),fmt.Sprintf("%s\n",cleanedPrefix))
content = strings.ReplaceAll(content,fmt.Sprintf("%s \r\n",cleanedPrefix),fmt.Sprintf("%s\r\n",cleanedPrefix))
return content,nil
}

Expand Down

0 comments on commit b98896d

Please sign in to comment.