skywalking-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kezhenx...@apache.org
Subject [skywalking-eyes] 01/01: enhance: tolerate leading whitespaces in license header
Date Fri, 07 May 2021 07:56:15 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 87a013eeef33b63d2c02c7f609effe1152dfdd37
Author: kezhenxu94 <kezhenxu94@apache.org>
AuthorDate: Fri May 7 15:55:56 2021 +0800

    enhance: tolerate leading whitespaces in license header
---
 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
 }

Mime
View raw message