diff options
| author | Shulhan <ms@kilabit.info> | 2026-01-12 20:26:01 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2026-01-12 21:23:09 +0700 |
| commit | bf35b0b8ab23f07c491e1c6b97c90b772942b7b7 (patch) | |
| tree | 47ede156fea419bf58fec10723645405f033fa62 | |
| parent | 1d6f8cfc60be1ada414ac1a9ce8eb6f61a527a0f (diff) | |
| download | spdxconv-bf35b0b8ab23f07c491e1c6b97c90b772942b7b7.tar.xz | |
all: remove prefix config from struct matchCopyright and matchLicense
| -rw-r--r-- | README.md | 8 | ||||
| -rw-r--r-- | config.go | 4 | ||||
| -rw-r--r-- | file.go | 4 | ||||
| -rw-r--r-- | match_copyright.go (renamed from config_match_copyright.go) | 8 | ||||
| -rw-r--r-- | match_license.go (renamed from config_match_license.go) | 4 | ||||
| -rw-r--r-- | spdxconv_test.go | 6 |
6 files changed, 17 insertions, 17 deletions
@@ -74,7 +74,7 @@ max_line_match = 10 [match-file-comment] pattern = "^.*\\.(adoc|asciidoc|c|cc|cpp|cs|dart|go|h|hh|hpp|java|js|jsx|jsonc|kt|kts|php|rs|sass|scss|swift|ts|tsx)$" -comment_prefix = "//" +prefix = "//" [match-file-comment] pattern = "^.*\\.(bash|csh|dockerfile|env|gitignore|hcl|ipynb|make|pl|pm|py|ps1|rb|sh|tf|yaml|yml|zsh)$" @@ -147,11 +147,11 @@ The default values is 10. ### match-file-comment section -The first thing that the program do is to detect which comment string to be -used when inserting SPDX identifiers in the file. +The first thing that the program do is to detect which comment prefix and +suffix to be used when inserting SPDX identifiers in the file. For each pattern in the "match-file-comment" section, the program will match -it with file name to get the comment prefix and suffix to be used later. +it with file name to get the comment `prefix` and `suffix`. User can add their own "match-file-comment" section as they like or modify the existing one. @@ -67,8 +67,8 @@ type config struct { MatchFileComment []*matchFileComment `ini:"match-file-comment"` - MatchLicense []*configMatchLicense `ini:"match-license"` - MatchCopyright []*configMatchCopyright `ini:"match-copyright"` + MatchLicense []*matchLicense `ini:"match-license"` + MatchCopyright []*matchCopyright `ini:"match-copyright"` MaxLineMatch int `ini:"default::max_line_match"` } @@ -35,7 +35,7 @@ var reCopyrightText = regexp.MustCompile(`^(//+|#+|/\*+|<!--+)?\s?SPDX-FileCopyr // REUSE-IgnoreEnd type file struct { - matchLicense *configMatchLicense + matchLicense *matchLicense path string @@ -357,7 +357,7 @@ func (f *file) applyCopyrightText(conv *SPDXConv) (err error) { } // Verify that the line actually match with one of // match-copyright pattern. - var cmc *configMatchCopyright + var cmc *matchCopyright for _, cmc = range conv.cfg.MatchCopyright { if cmc.match(string(line)) { f.copyrightYear = cmc.year diff --git a/config_match_copyright.go b/match_copyright.go index 1dc9dfd..aa35950 100644 --- a/config_match_copyright.go +++ b/match_copyright.go @@ -8,7 +8,7 @@ import ( "regexp" ) -type configMatchCopyright struct { +type matchCopyright struct { rePattern *regexp.Regexp // Pattern to be searched in file. @@ -19,7 +19,7 @@ type configMatchCopyright struct { contact string } -func (cmc *configMatchCopyright) init() (err error) { +func (cmc *matchCopyright) init() (err error) { var logp = `match-copyright` if cmc.Pattern != `` { cmc.rePattern, err = regexp.Compile(cmc.Pattern) @@ -30,7 +30,7 @@ func (cmc *configMatchCopyright) init() (err error) { return nil } -func (cmc *configMatchCopyright) match(line string) bool { +func (cmc *matchCopyright) match(line string) bool { matches := cmc.rePattern.FindStringSubmatch(line) if len(matches) == 0 { return false @@ -47,6 +47,6 @@ func (cmc *configMatchCopyright) match(line string) bool { return len(namedMatches) >= 1 } -func (cmc *configMatchCopyright) String() string { +func (cmc *matchCopyright) String() string { return fmt.Sprintf(`%s <%s>`, cmc.author, cmc.contact) } diff --git a/config_match_license.go b/match_license.go index 818e806..1d15d7f 100644 --- a/config_match_license.go +++ b/match_license.go @@ -8,7 +8,7 @@ import ( "regexp" ) -type configMatchLicense struct { +type matchLicense struct { rePattern *regexp.Regexp reDeleteLine []*regexp.Regexp @@ -26,7 +26,7 @@ type configMatchLicense struct { DeleteLinePattern []string `ini:"match-license::delete_line_pattern"` } -func (cml *configMatchLicense) init() (err error) { +func (cml *matchLicense) init() (err error) { var logp = `match-license` if cml.Pattern != `` { cml.rePattern, err = regexp.Compile(cml.Pattern) diff --git a/spdxconv_test.go b/spdxconv_test.go index c057a71..194276e 100644 --- a/spdxconv_test.go +++ b/spdxconv_test.go @@ -63,15 +63,15 @@ func TestInit(t *testing.T) { }, { Pattern: `^.*\.(apk|app|bz2|csv|doc|docx|exe|gif|gz|jpeg|jpg|json|pdf|png|ppt|pptx|svg|svgz|tar|tgz|xls|xlsx|zip)$`, }}, - MatchLicense: []*configMatchLicense{{ + MatchLicense: []*matchLicense{{ Pattern: `^(//+|#+)\s+(.*)governed by a BSD-style(.*)$`, LicenseIdentifier: `BSD-3-Clause`, DeleteLinePattern: []string{ `^(//+|#+)\s+license that(.*)$`, }, }}, - MatchCopyright: []*configMatchCopyright{{ - Pattern: `^(//+|#+)?\s*Copyright\s+(?<year>\d{4}),?\s+(?<author>.*)\s+<*(?<contact>.*)>.*$`, + MatchCopyright: []*matchCopyright{{ + Pattern: `^(//+|#+)\s+Copyright\s+(?<year>\d{4}),?\s+(?<author>.*)\s+<*(?<contact>.*)>.*$`, }}, } for _, mfc := range exp.MatchFileComment { |
