Skip to content

Commit

Permalink
BIGTOP-4361: Add Chinese check
Browse files Browse the repository at this point in the history
  • Loading branch information
wuchunfu committed Feb 15, 2025
1 parent 9052425 commit d12a516
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions .github/check_chinese_character.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from pathlib import Path
from typing import List, Set

class ChineseCharacterCheckTest:
class chinese_character_check_test:
CHINESE_CHAR_PATTERN = re.compile(r'[\u4e00-\u9fa5]')
# Exclude directories or files. If it is a file, just write the file name. The same is true for directories, just write the directory name.
EXCLUDED_DIRS_AND_FILES = {
Expand All @@ -44,10 +44,10 @@ class ChineseCharacterCheckTest:
}

def should_not_contain_chinese_in_comments(self):
violations = self.scan_for_chinese_characters(ScanTarget.COMMENTS)
violations = self.scan_for_chinese_characters(scan_target.COMMENTS)
self.assert_no_chinese_characters(violations)

def scan_for_chinese_characters(self, target: 'ScanTarget') -> List[str]:
def scan_for_chinese_characters(self, target: 'scan_target') -> List[str]:
violations = []
for ext in self.SUPPORTED_EXTENSIONS:
for path in Path("..").rglob(f"*{ext}"):
Expand All @@ -63,7 +63,7 @@ def is_valid_file(self, path: Path) -> bool:
path_str = str(path)
return any(path_str.endswith(ext) for ext in self.SUPPORTED_EXTENSIONS)

def process_file(self, path: Path, target: 'ScanTarget', violations: List[str]):
def process_file(self, path: Path, target: 'scan_target', violations: List[str]):
try:
with open(path, 'r', encoding='utf-8') as file:
content = file.read()
Expand Down Expand Up @@ -104,7 +104,7 @@ def format_violation(self, path: Path, location: str, content: str) -> str:
def assert_no_chinese_characters(self, violations: List[str]):
assert len(violations) == 0, f"Found Chinese characters in files:\n{os.linesep.join(violations)}"

class ScanTarget:
class scan_target:
def __init__(self, check_comments: bool, check_code: bool):
self.check_comments = check_comments
self.check_code = check_code
Expand All @@ -115,10 +115,10 @@ def include_comments(self) -> bool:
def include_code(self) -> bool:
return self.check_code

ScanTarget.COMMENTS = ScanTarget(True, False)
ScanTarget.CODE = ScanTarget(False, True)
ScanTarget.ALL = ScanTarget(True, True)
scan_target.COMMENTS = scan_target(True, False)
scan_target.CODE = scan_target(False, True)
scan_target.ALL = scan_target(True, True)

if __name__ == "__main__":
test = ChineseCharacterCheckTest()
test = chinese_character_check_test()
test.should_not_contain_chinese_in_comments()

0 comments on commit d12a516

Please sign in to comment.