Skip to content

Commit 7d3128e

Browse files
authored
Update black format in css_check.py
1 parent b99ba8e commit 7d3128e

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

.github/workflows/css_check.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
from collections import namedtuple
99

1010
# Define namedtuples for storing results
11-
Violation = namedtuple('Violation', ['file_path', 'css_file', 'reason'])
12-
CorrectImport = namedtuple('CorrectImport', ['file_path', 'css_file'])
13-
EmbeddedViolation = namedtuple('EmbeddedViolation', ['file_path', 'css_codes'])
14-
CSSCheckResult = namedtuple('CSSCheckResult', ['violations', 'correct_imports', 'embedded_violations'])
11+
Violation = namedtuple("Violation", ["file_path", "css_file", "reason"])
12+
CorrectImport = namedtuple("CorrectImport", ["file_path", "css_file"])
13+
EmbeddedViolation = namedtuple("EmbeddedViolation", ["file_path", "css_codes"])
14+
CSSCheckResult = namedtuple(
15+
"CSSCheckResult", ["violations", "correct_imports", "embedded_violations"]
16+
)
17+
1518

1619
def check_embedded_css(content: str) -> list:
1720
"""
@@ -26,8 +29,12 @@ def check_embedded_css(content: str) -> list:
2629
embedded_css_pattern = r"#([0-9a-fA-F]{3}){1,2}" # Matches CSS color codes
2730
return re.findall(embedded_css_pattern, content)
2831

32+
2933
def check_files(
30-
directory: str, exclude_files: list, exclude_directories: list, allowed_css_patterns: list
34+
directory: str,
35+
exclude_files: list,
36+
exclude_directories: list,
37+
allowed_css_patterns: list,
3138
) -> CSSCheckResult:
3239
"""
3340
Check TypeScript files for CSS violations and correct CSS imports.
@@ -83,20 +90,29 @@ def check_files(
8390

8491
# Check if the CSS file exists
8592
if not os.path.exists(css_file_path):
86-
violations.append(Violation(file_path, css_file, "File not found"))
93+
violations.append(
94+
Violation(file_path, css_file, "File not found")
95+
)
8796
# Check if the CSS import matches the allowed patterns
88-
elif any(css_file.endswith(pattern) for pattern in allowed_css_patterns):
97+
elif any(
98+
css_file.endswith(pattern) for pattern in allowed_css_patterns
99+
):
89100
correct_css_imports.append(CorrectImport(file_path, css_file))
90101
else:
91-
violations.append(Violation(file_path, css_file, "Invalid import"))
102+
violations.append(
103+
Violation(file_path, css_file, "Invalid import")
104+
)
92105

93106
# Check for embedded CSS
94107
embedded_css = check_embedded_css(content)
95108
if embedded_css:
96-
embedded_css_violations.append(EmbeddedViolation(file_path, embedded_css))
109+
embedded_css_violations.append(
110+
EmbeddedViolation(file_path, embedded_css)
111+
)
97112

98113
return CSSCheckResult(violations, correct_css_imports, embedded_css_violations)
99114

115+
100116
def main():
101117
"""Run the CSS check script."""
102118
parser = argparse.ArgumentParser(
@@ -140,31 +156,35 @@ def main():
140156
if result.violations:
141157
output.append("CSS Import Violations:")
142158
for violation in result.violations:
143-
output.append(f"- {violation.file_path}: {violation.css_file} ({violation.reason})")
159+
output.append(
160+
f"- {violation.file_path}: {violation.css_file} ({violation.reason})"
161+
)
144162
exit_code = 1
145163

146164
if result.embedded_violations:
147165
output.append("\nEmbedded CSS Violations:")
148166
for violation in result.embedded_violations:
149167
output.append(f"- {violation.file_path}: {', '.join(violation.css_codes)}")
150-
exit_code = 1
168+
exit_code = 1
151169

152170
if output:
153171
print("\n".join(output))
154-
print("""
172+
print(
173+
"""
155174
Please address the above CSS violations:
156175
1. For invalid CSS imports, ensure you're using the correct import syntax and file paths.
157176
2. For embedded CSS, move the CSS to appropriate stylesheet files and import them correctly.
158177
3. Make sure to use only the allowed CSS patterns as specified in the script arguments.
159178
4. Check that all imported CSS files exist in the specified locations.
160-
""")
179+
"""
180+
)
161181
if args.show_success and result.correct_imports:
162182
print("\nCorrect CSS Imports:")
163183
for import_ in result.correct_imports:
164184
print(f"- {import_.file_path}: {import_.css_file}")
165185

166186
sys.exit(exit_code)
167187

188+
168189
if __name__ == "__main__":
169190
main()
170-

0 commit comments

Comments
 (0)