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 2020/12/22 15:05:14 UTC

[skywalking-eyes] 01/01: Enhance `check` command to automatically skip non-text (binary) files

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

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

commit d951e97ec128ca4cf0f259ad77fccb6fd0193e93
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Tue Dec 22 23:04:00 2020 +0800

    Enhance `check` command to automatically skip non-text (binary) files
---
 .licenserc.yaml                 |  2 --
 license-eye/pkg/header/check.go | 11 +++++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/.licenserc.yaml b/.licenserc.yaml
index dc3b932..e4494c7 100644
--- a/.licenserc.yaml
+++ b/.licenserc.yaml
@@ -61,9 +61,7 @@ header: # `header` section is configurations for source codes license header.
   paths-ignore: # `paths-ignore` are the path list that will be ignored by license-eye.
     - 'dist'
     - 'licenses'
-    - '**/bin/**'
     - '**/*.md'
-    - '**/.DS_Store'
     - '**/testdata/**'
     - '**/go.mod'
     - '**/go.sum'
diff --git a/license-eye/pkg/header/check.go b/license-eye/pkg/header/check.go
index 5325692..8053cd3 100644
--- a/license-eye/pkg/header/check.go
+++ b/license-eye/pkg/header/check.go
@@ -19,6 +19,8 @@ package header
 
 import (
 	"bufio"
+	"io/ioutil"
+	"net/http"
 	"os"
 	"path/filepath"
 	"regexp"
@@ -122,6 +124,15 @@ func CheckFile(file string, config *ConfigHeader, result *Result) error {
 
 	var lines []string
 
+	bs, err := ioutil.ReadFile(file)
+	if err != nil {
+		return err
+	}
+	if t := http.DetectContentType(bs); !strings.HasPrefix(t, "text/") {
+		logger.Log.Debugln("Ignoring file:", file, "; type:", t)
+		return nil
+	}
+
 	scanner := bufio.NewScanner(reader)
 	for scanner.Scan() {
 		line := strings.ToLower(Punctuations.ReplaceAllString(scanner.Text(), " "))