From b98896d3be2e2ca6d70fbf1edb593d14032268e1 Mon Sep 17 00:00:00 2001 From: kuritka Date: Thu, 18 Mar 2021 12:16:38 +0100 Subject: [PATCH] remove indent --- .golic.yaml | 16 ++++++++-------- README.md | 2 +- cmd/version.go | 2 +- impl/inject/config.go | 1 - impl/inject/inject.go | 18 ++++++------------ 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/.golic.yaml b/.golic.yaml index bdd8a05..03dfa0e 100644 --- a/.golic.yaml +++ b/.golic.yaml @@ -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" diff --git a/README.md b/README.md index d6f093e..18e708f 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ create `.licignore` in project root Install and run **GOLIC** ```shell # GO 1.16 -go install github.com/AbsaOSS/golic@v0.4.5 +go install github.com/AbsaOSS/golic@v0.4.6 golic inject -c="2021 MyCompany ltd." ``` diff --git a/cmd/version.go b/cmd/version.go index 7152722..1e4277b 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -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", diff --git a/impl/inject/config.go b/impl/inject/config.go index 0e06bc0..f233d3a 100644 --- a/impl/inject/config.go +++ b/impl/inject/config.go @@ -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"` } diff --git a/impl/inject/inject.go b/impl/inject/inject.go index 9bee023..2d6cb45 100644 --- a/impl/inject/inject.go +++ b/impl/inject/inject.go @@ -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 }