|
|
@@ -1,39 +1,39 @@
|
|
|
-# Coding Standards
|
|
|
+# 编码规范
|
|
|
|
|
|
-## 1. Meaningful variable names, file names, folder names. Use abbreviations for words over ten characters. Abbreviations must be over three characters.
|
|
|
+## 1. 变量名、文件名、文件夹名要有意义。超过十个字符的单词使用缩写。缩写必须超过三个字符。
|
|
|
|
|
|
-- ✅ `update-btn` (refresh button), `device-list`, `user-profile-settings` (profile = abbreviation)
|
|
|
-- ❌ `btn` (too vague), `d1` (meaningless), `temp` (unclear), `us` (abbreviation too short)
|
|
|
+- ✅ `update-btn` (刷新按钮), `device-list`, `user-profile-settings` (profile = 缩写)
|
|
|
+- ❌ `btn` (太模糊), `d1` (无意义), `temp` (不清楚), `us` (缩写太短)
|
|
|
|
|
|
-## 2. Use hyphens (`-`) for multi-word names.
|
|
|
+## 2. 多词名称使用连字符 (`-`)。
|
|
|
|
|
|
-## 3. Comments: One Function, One Comment, English Only
|
|
|
+## 3. 注释:一个函数,一个注释
|
|
|
|
|
|
-## 4. Use functions to separate different logic. Avoid writing too much logic in a single function.
|
|
|
+## 4. 使用函数来分离不同的逻辑。避免在单个函数中编写过多逻辑。
|
|
|
|
|
|
-## 5. Never use try-catch. Let errors crash.
|
|
|
+## 5. 永远不要使用 try-catch。让错误崩溃。
|
|
|
|
|
|
-## 6. GUI components must split into three files:
|
|
|
+## 6. GUI 组件必须拆分为三个文件:
|
|
|
|
|
|
-- `.jsx`: Layout only (no logic, no styles)
|
|
|
-- `.js`: Logic only (functions, state, business logic)
|
|
|
-- `.scss`: Styles only (no logic, no JSX)
|
|
|
+- `.jsx`: 仅布局(无逻辑,无样式)
|
|
|
+- `.js`: 仅逻辑(函数、状态、业务逻辑)
|
|
|
+- `.scss`: 仅样式(无逻辑,无 JSX)
|
|
|
|
|
|
-**Never write logic or inline styles in `.jsx` files.**
|
|
|
+**永远不要在 `.jsx` 文件中编写逻辑或内联样式。**
|
|
|
|
|
|
-## 7. Use the least code to implement functionality.
|
|
|
+## 7. 使用最少的代码来实现功能。
|
|
|
|
|
|
-## 8. Do not add any `console.log` statements in production code.
|
|
|
+## 8. 不要在生产代码中添加任何 `console.log` 语句。
|
|
|
|
|
|
-## 9. Do not create script files unnecessarily. If you can call PowerShell directly, use PowerShell instead of creating a separate script file.
|
|
|
+## 9. 不要不必要地创建脚本文件。如果可以直接调用 PowerShell,使用 PowerShell 而不是创建单独的脚本文件。
|
|
|
|
|
|
-## 10. If you need to create any new files, you must ask first.
|
|
|
+## 10. 如果需要创建任何新文件,必须先询问。
|
|
|
|
|
|
-## 11. Use `switch` statements instead of multiple `if-else` chains when checking the same variable against multiple values.
|
|
|
+## 11. 当检查同一变量与多个值进行比较时,使用 `switch` 语句而不是多个 `if-else` 链。
|
|
|
|
|
|
-## 12. Prefer Early Return Over Else Blocks
|
|
|
+## 12. 优先使用提前返回而不是 else 块
|
|
|
|
|
|
-Prefer early return pattern:
|
|
|
+优先使用提前返回模式:
|
|
|
```javascript
|
|
|
if (condition) {
|
|
|
...
|
|
|
@@ -41,7 +41,7 @@ if (condition) {
|
|
|
}
|
|
|
```
|
|
|
|
|
|
-Instead of:
|
|
|
+而不是:
|
|
|
```javascript
|
|
|
if (condition) {
|
|
|
...
|
|
|
@@ -50,6 +50,6 @@ if (condition) {
|
|
|
}
|
|
|
```
|
|
|
|
|
|
-## 13. No Existence Checks
|
|
|
+## 13. 不进行存在性检查
|
|
|
|
|
|
-Do not add if statements to check if directories exist, files exist, or if parsing succeeded. Let errors crash.
|
|
|
+不要添加 if 语句来检查目录是否存在、文件是否存在或解析是否成功。让错误崩溃。
|