You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@skywalking.apache.org by ke...@apache.org on 2022/04/06 01:54:22 UTC

[skywalking-eyes] branch main updated: [config]Support config license header comment style. (#97)

This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-eyes.git


The following commit(s) were added to refs/heads/main by this push:
     new 66a8bd6  [config]Support config license header comment style. (#97)
66a8bd6 is described below

commit 66a8bd6aa7e8246c061b2d9baf7ebe646f9eb475
Author: Zonglei Dong <do...@apache.org>
AuthorDate: Wed Apr 6 09:54:17 2022 +0800

    [config]Support config license header comment style. (#97)
---
 .licenserc.yaml                                    |  6 ++++
 pkg/comments/config.go                             | 39 ++++++++++++++--------
 pkg/header/config.go                               |  6 +++-
 .../testdata/.licenserc_language_config_test.yaml  | 25 ++++++++++++++
 4 files changed, 61 insertions(+), 15 deletions(-)

diff --git a/.licenserc.yaml b/.licenserc.yaml
index e93e885..c2248d5 100644
--- a/.licenserc.yaml
+++ b/.licenserc.yaml
@@ -80,6 +80,12 @@ header: # `header` section is configurations for source codes license header.
   # after all, a "header" cannot be TOO far from the file start.
   license-location-threshold: 80
 
+  language:
+    Go:
+      extensions:
+        - ".go"
+      comment_style_id: DoubleSlash
+
 dependency:
   files:
     - go.mod
diff --git a/pkg/comments/config.go b/pkg/comments/config.go
index 8639b3e..3bc7ece 100644
--- a/pkg/comments/config.go
+++ b/pkg/comments/config.go
@@ -59,20 +59,7 @@ func init() {
 
 	initCommentStyles()
 
-	for _, lang := range languages {
-		for _, extension := range lang.Extensions {
-			if lang.CommentStyleID == "" {
-				continue
-			}
-			commentStyles[extension] = comments[lang.CommentStyleID]
-		}
-		for _, filename := range lang.Filenames {
-			if lang.CommentStyleID == "" {
-				continue
-			}
-			commentStyles[filename] = comments[lang.CommentStyleID]
-		}
-	}
+	initLanguageCommentStyles(languages)
 }
 
 func initLanguages() {
@@ -106,6 +93,26 @@ func initCommentStyles() {
 	}
 }
 
+func initLanguageCommentStyles(languages map[string]Language) {
+	if len(languages) == 0 {
+		return
+	}
+	for _, lang := range languages {
+		for _, extension := range lang.Extensions {
+			if lang.CommentStyleID == "" {
+				continue
+			}
+			commentStyles[extension] = comments[lang.CommentStyleID]
+		}
+		for _, filename := range lang.Filenames {
+			if lang.CommentStyleID == "" {
+				continue
+			}
+			commentStyles[filename] = comments[lang.CommentStyleID]
+		}
+	}
+}
+
 func FileCommentStyle(filename string) *CommentStyle {
 	for extension, style := range commentStyles {
 		if strings.HasSuffix(filename, extension) {
@@ -114,3 +121,7 @@ func FileCommentStyle(filename string) *CommentStyle {
 	}
 	return nil
 }
+
+func OverrideLanguageCommentStyle(languages map[string]Language) {
+	initLanguageCommentStyles(languages)
+}
diff --git a/pkg/header/config.go b/pkg/header/config.go
index 73f95d7..b2f98e3 100644
--- a/pkg/header/config.go
+++ b/pkg/header/config.go
@@ -28,6 +28,7 @@ import (
 
 	"github.com/apache/skywalking-eyes/assets"
 	"github.com/apache/skywalking-eyes/internal/logger"
+	"github.com/apache/skywalking-eyes/pkg/comments"
 	"github.com/apache/skywalking-eyes/pkg/license"
 
 	"github.com/bmatcuk/doublestar/v2"
@@ -59,7 +60,8 @@ type ConfigHeader struct {
 
 	// LicenseLocationThreshold specifies the index threshold where the license header can be located,
 	// after all, a "header" cannot be TOO far from the file start.
-	LicenseLocationThreshold int `yaml:"license-location-threshold"`
+	LicenseLocationThreshold int                          `yaml:"license-location-threshold"`
+	Languages                map[string]comments.Language `yaml:"language"`
 }
 
 // NormalizedLicense returns the normalized string of the license content,
@@ -104,6 +106,8 @@ func (config *ConfigHeader) Finalize() error {
 		config.Paths = []string{"**"}
 	}
 
+	comments.OverrideLanguageCommentStyle(config.Languages)
+
 	config.PathsIgnore = append(config.PathsIgnore, ".git", "**/*.txt")
 
 	if file, err := os.Open(".gitignore"); err == nil {
diff --git a/.licenserc.yaml b/test/testdata/.licenserc_language_config_test.yaml
similarity index 88%
copy from .licenserc.yaml
copy to test/testdata/.licenserc_language_config_test.yaml
index e93e885..2ad0dee 100644
--- a/.licenserc.yaml
+++ b/test/testdata/.licenserc_language_config_test.yaml
@@ -80,6 +80,31 @@ header: # `header` section is configurations for source codes license header.
   # after all, a "header" cannot be TOO far from the file start.
   license-location-threshold: 80
 
+  language:
+    Go:
+      extensions:
+        - ".go"
+      comment_style_id: SlashAsterisk
+    YAML:
+      extensions:
+        - ".yml"
+        - ".mir"
+        - ".reek"
+        - ".rviz"
+        - ".sublime-syntax"
+        - ".syntax"
+        - ".yaml"
+        - ".yaml-tmlanguage"
+        - ".yaml.sed"
+        - ".yml.mysql"
+      filenames:
+        - ".clang-format"
+        - ".clang-tidy"
+        - ".gemrc"
+        - glide.lock
+        - yarn.lock
+      comment_style_id: Hashtag
+
 dependency:
   files:
     - go.mod