mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-06-08 09:26:59 +00:00
Refactor
This commit is contained in:
parent
13ab6fcd6f
commit
df65004597
@ -6,7 +6,7 @@ import argparse
|
|||||||
|
|
||||||
# Customize as needed
|
# Customize as needed
|
||||||
I18N_FUNCTIONS = ['t', 'i18next.t']
|
I18N_FUNCTIONS = ['t', 'i18next.t']
|
||||||
FILE_EXTENSIONS = ['.tsx']
|
FILE_EXTENSIONS = ['.tsx', '.ts']
|
||||||
EXCLUDED_DIRS = ['node_modules', 'build', 'dist']
|
EXCLUDED_DIRS = ['node_modules', 'build', 'dist']
|
||||||
|
|
||||||
# Regex patterns
|
# Regex patterns
|
||||||
@ -16,11 +16,11 @@ JSX_TEXT_REGEX = re.compile(r'>\s*([A-Z][a-z].*?)\s*<')
|
|||||||
def is_excluded(path):
|
def is_excluded(path):
|
||||||
return any(excluded in path for excluded in EXCLUDED_DIRS)
|
return any(excluded in path for excluded in EXCLUDED_DIRS)
|
||||||
|
|
||||||
def is_ignorable(text):
|
def is_ignorable(text, line):
|
||||||
return (
|
if re.fullmatch(r'[A-Z0-9_]+', text):
|
||||||
re.fullmatch(r'[A-Z0-9_]+', text) and
|
if re.search(r'\b(case|action|status)\b', line, re.IGNORECASE):
|
||||||
any(keyword in text.lower() for keyword in ['action', 'status'])
|
return True
|
||||||
)
|
return False
|
||||||
|
|
||||||
def is_console_log_line(line):
|
def is_console_log_line(line):
|
||||||
return any(kw in line for kw in ['console.log', 'console.error', 'console.warn'])
|
return any(kw in line for kw in ['console.log', 'console.error', 'console.warn'])
|
||||||
@ -38,7 +38,7 @@ def find_untranslated_strings(file_path):
|
|||||||
# Match suspicious string literals
|
# Match suspicious string literals
|
||||||
for match in STRING_LITERAL_REGEX.finditer(line):
|
for match in STRING_LITERAL_REGEX.finditer(line):
|
||||||
string = match.group(1).strip()
|
string = match.group(1).strip()
|
||||||
if is_ignorable(string):
|
if is_ignorable(string, line):
|
||||||
continue
|
continue
|
||||||
if not any(fn + '(' in line[:match.start()] for fn in I18N_FUNCTIONS):
|
if not any(fn + '(' in line[:match.start()] for fn in I18N_FUNCTIONS):
|
||||||
issues.append({
|
issues.append({
|
||||||
@ -51,7 +51,7 @@ def find_untranslated_strings(file_path):
|
|||||||
# Match JSX text nodes
|
# Match JSX text nodes
|
||||||
for match in JSX_TEXT_REGEX.finditer(line):
|
for match in JSX_TEXT_REGEX.finditer(line):
|
||||||
text = match.group(1).strip()
|
text = match.group(1).strip()
|
||||||
if is_ignorable(text):
|
if is_ignorable(text, line):
|
||||||
continue
|
continue
|
||||||
if not text.startswith('{t('):
|
if not text.startswith('{t('):
|
||||||
issues.append({
|
issues.append({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user