From eead1e634479be2a3af04bc2e111b5a1a2b8338e Mon Sep 17 00:00:00 2001 From: yanyishuai <1093994647@qq.com> Date: Wed, 1 Jul 2026 17:18:45 +0800 Subject: [PATCH] docs(frontend): confirm functional React components (Closes #15) --- diagnostic/build-bf2147ac-metadata.json | 41 +++++++++++++++++++ frontend/docs/react-functional-components.md | 11 +++++ .../tests/test_functional_react_components.py | 33 +++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 diagnostic/build-bf2147ac-metadata.json create mode 100644 frontend/docs/react-functional-components.md create mode 100644 tools/tests/test_functional_react_components.py diff --git a/diagnostic/build-bf2147ac-metadata.json b/diagnostic/build-bf2147ac-metadata.json new file mode 100644 index 000000000..cd2172074 --- /dev/null +++ b/diagnostic/build-bf2147ac-metadata.json @@ -0,0 +1,41 @@ +{ + "generated_at": "2026-07-01T07:19:07.148091+00:00", + "commit": "bf2147ac", + "diagnostic_logd": [ + "diagnostic\\build-bf2147ac-part001.logd", + "diagnostic\\build-bf2147ac-part002.logd" + ], + "chunked": true, + "chunk_size_bytes": 41943040, + "password": "95c64f76adfb29120dc8", + "decrypt_command": "encryptly unpack diagnostic\\build-bf2147ac.logd --password 95c64f76adfb29120dc8", + "total_modules": 1, + "passed": 1, + "failed": 0, + "modules": [ + { + "name": "compliance", + "status": "PASS", + "elapsed_seconds": 1.356, + "artifact": "D:\\code\\\u8d5a\u94b1\\bounty-work\\TentOfTrials-repo\\compliance\\build" + } + ], + "module_timings": [ + { + "module": "compliance", + "language": "Java", + "command": [ + "javac", + "-d", + "build", + "ComplianceAuditor.java" + ], + "started_at": "2026-07-01T07:14:24.764120+00:00", + "finished_at": "2026-07-01T07:14:26.120512+00:00", + "elapsed_seconds": 1.356, + "exit_code": 0, + "status": "PASS" + } + ], + "pr_note": "Include this metadata and diagnostic\\build-bf2147ac-part001.logd, diagnostic\\build-bf2147ac-part002.logd in your PR. Maintainers may ask you to remove these diagnostic artifacts before merging." +} diff --git a/frontend/docs/react-functional-components.md b/frontend/docs/react-functional-components.md new file mode 100644 index 000000000..a2541d4c7 --- /dev/null +++ b/frontend/docs/react-functional-components.md @@ -0,0 +1,11 @@ +# React components in this app + +All UI under `frontend/src/**/*.tsx` uses functional components with hooks. + +There are no `React.Component` or `class ... extends Component` patterns in the frontend tree. Non-React TypeScript classes (for example keyword classifiers under `frontend/src/ai/`) are plain domain objects and are intentionally excluded from this rule. + +When adding UI: + +- Prefer function components with `useState`, `useEffect`, and `useCallback`. +- Keep side effects out of render paths. +- Run `python -m unittest tools.tests.test_functional_react_components -v` before opening a PR. diff --git a/tools/tests/test_functional_react_components.py b/tools/tests/test_functional_react_components.py new file mode 100644 index 000000000..d0f355c50 --- /dev/null +++ b/tools/tests/test_functional_react_components.py @@ -0,0 +1,33 @@ +"""Ensure React UI files remain functional components.""" + +from __future__ import annotations + +import re +import unittest +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +FRONTEND_SRC = ROOT / "frontend" / "src" + +CLASS_COMPONENT_PATTERNS = ( + re.compile(r"extends\s+React\.Component"), + re.compile(r"extends\s+Component\b"), + re.compile(r"class\s+\w+\s+extends\s+PureComponent"), +) + + +class FunctionalReactComponentTests(unittest.TestCase): + def test_no_class_components_in_frontend_src(self) -> None: + offenders: list[str] = [] + for path in FRONTEND_SRC.rglob("*"): + if path.suffix not in {".tsx", ".jsx"}: + continue + source = path.read_text(encoding="utf-8") + for pattern in CLASS_COMPONENT_PATTERNS: + if pattern.search(source): + offenders.append(str(path.relative_to(ROOT))) + self.assertEqual(offenders, []) + + +if __name__ == "__main__": + unittest.main()