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 2021/05/07 08:05:27 UTC

[skywalking-eyes] branch main updated: enhance: tolerate leading whitespaces in license header (#30)

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 b49aa12  enhance: tolerate leading whitespaces in license header (#30)
b49aa12 is described below

commit b49aa124edcd9460d3ecc6d03f1e71efe9be9732
Author: Zhenxu Ke <ke...@apache.org>
AuthorDate: Fri May 7 16:05:17 2021 +0800

    enhance: tolerate leading whitespaces in license header (#30)
---
 pkg/license/norm.go | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/pkg/license/norm.go b/pkg/license/norm.go
index f18daa1..1b1bd74 100644
--- a/pkg/license/norm.go
+++ b/pkg/license/norm.go
@@ -19,8 +19,12 @@
 package license
 
 import (
+	"reflect"
 	"regexp"
+	"runtime"
 	"strings"
+
+	"github.com/apache/skywalking-eyes/license-eye/internal/logger"
 )
 
 type Normalizer func(string) string
@@ -127,7 +131,7 @@ var (
 	}{
 		// BSD-3-Clause
 		{
-			regexp.MustCompile(`(?im)(^(Copyright \(c\)) (\d{4}) (.+?) (All rights reserved\.)?$\n?)+`),
+			regexp.MustCompile(`(?im)(^(\s*Copyright \(c\)) (\d{4}) (.+?) (All rights reserved\.)?$\n?)+`),
 			"$2 [year] [owner]. $5",
 		},
 		{
@@ -136,11 +140,11 @@ var (
 		},
 		// MIT
 		{ // remove optional header
-			regexp.MustCompile(`(?im)^The MIT License \(MIT\)$`),
+			regexp.MustCompile(`(?im)^\s*The MIT License \(MIT\)$`),
 			"",
 		},
 		{
-			regexp.MustCompile(`(?im)^(Copyright \(c\)) (\d{4}) (.+?)$`),
+			regexp.MustCompile(`(?im)^(\s*Copyright \(c\)) (\d{4}) (.+?)$`),
 			"$1 [year] [owner]",
 		},
 		{
@@ -162,7 +166,9 @@ func NormalizePattern(pattern string) string {
 func NormalizeHeader(header string) string {
 	ns := append([]Normalizer{CommentIndicatorNormalizer}, normalizers...)
 	for _, normalize := range ns {
+		logger.Log.Debugf("After normalized by %+v:", runtime.FuncForPC(reflect.ValueOf(normalize).Pointer()).Name())
 		header = normalize(header)
+		logger.Log.Debugln(header)
 	}
 	return header
 }