From 68e4c8e01edaa31844d59b32606bf347fa040774 Mon Sep 17 00:00:00 2001
From: zzjc1234 <2359047351@qq.com>
Date: Mon, 21 Oct 2024 16:21:12 +0800
Subject: [PATCH] fix(healthcheck/nonasciifile): comment, code style and check
 range

---
 cmd/repo-health-checker/main.go |  4 ++--
 pkg/healthcheck/nonascii.go     | 18 ++++++------------
 2 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/cmd/repo-health-checker/main.go b/cmd/repo-health-checker/main.go
index 5396fd4..aedcb16 100644
--- a/cmd/repo-health-checker/main.go
+++ b/cmd/repo-health-checker/main.go
@@ -43,12 +43,12 @@ func main() {
 	showVersion := flag.Bool("version", false, "print current version")
 	rootDir := flag.String("root", ".", "root dir for forbidden files check")
 	repoSize := flag.Float64("repoSize", 2, "maximum size of the repo in MiB")
-	// TODO: remove gitWhitelist, it is only for backward compatibility now
+	// TODO: remove git whitelist, it is only for backward compatibility now
 	localList := flag.String("localList", "", "local file list for non-ascii file check")
 	checkFileNameList := flag.String("checkFileNameList", "", "comma-separated list of files to check")
 	checkFileSumList := flag.String("checkFileSumList", "", "comma-separated list of expected checksums")
 	parseMultiValueFlag(&metaFile, "meta", "meta files to check")
-	// TODO: remove gitWhitelist, it is only for backward compatibility now
+	// TODO: remove git whitelist, it is only for backward compatibility now
 	var gitWhitelist []string
 	parseMultiValueFlag(&gitWhitelist, "whitelist", "[DEPRECATED] will be ignored")
 	flag.Parse()
diff --git a/pkg/healthcheck/nonascii.go b/pkg/healthcheck/nonascii.go
index 8dff2cd..838069c 100644
--- a/pkg/healthcheck/nonascii.go
+++ b/pkg/healthcheck/nonascii.go
@@ -16,14 +16,14 @@ import (
 // It searches for non-ASCII characters in each file's content and returns a list of paths to files containing non-ASCII characters.
 func getNonAscii(root string) ([]string, error) {
 	var nonAscii []string
-	noAttri := false
+	gitattrExist := true
 	var matcher gitattributes.Matcher
 	_, err := os.Stat(".gitattributes")
 	if os.IsNotExist(err) {
-		noAttri = true
+		gitattrExist = false
 	}
 
-	if !noAttri {
+	if gitattrExist {
 		fs := os.DirFS(".")
 		f, err := fs.Open(".gitattributes")
 		if err != nil {
@@ -43,25 +43,19 @@ func getNonAscii(root string) ([]string, error) {
 		}
 
 		if info.IsDir() {
-			if info.Name() == ".git" || info.Name() == ".gitea" {
+			if info.Name() == ".git" {
 				return filepath.SkipDir
 			} else {
 				return nil
 			}
 		}
 
-		if info.Name() == "healthcheck" {
-			return nil
-		}
-
-		if !noAttri {
+		if gitattrExist {
 			relPath, err := filepath.Rel(root, path)
 			if err != nil {
 				return err
 			}
-			str := strings.Split(relPath, "/")
-			_, ret := matcher.Match(str, nil)
-			if ret {
+			if _, ret := matcher.Match(strings.Split(relPath, "/"), nil); ret {
 				return nil
 			}
 		}