Răsfoiți Sursa

refactor: 修改ai审查的问题

RyanCW 2 săptămâni în urmă
părinte
comite
002739343b

+ 33 - 131
.clang-format

@@ -1,77 +1,46 @@
-# SPDX-License-Identifier: Apache-2.0
-#
-# Note: The list of ForEachMacros can be obtained using:
-#
-#    git grep -h '^#define [^[:space:]]*FOR_EACH[^[:space:]]*(' include/ \
-#    | sed "s,^#define \([^[:space:]]*FOR_EACH[^[:space:]]*\)(.*$,  - '\1'," \
-#    | sort | uniq
-#
-# References:
-#   - https://clang.llvm.org/docs/ClangFormatStyleOptions.html
-
 ---
-# 基于 LLVM 的代码风格作为起点,随后覆盖指定字段
 BasedOnStyle: LLVM
 
-# 连续宏定义的对齐方式
-# Enabled: true         -> 启用对齐连续宏定义
-# AcrossComments: true  -> 跨注释也会对齐,适合一组宏中间穿插注释的情况
+# --- 对齐策略 ---
+# 对齐连续宏定义,不跨空行
 AlignConsecutiveMacros:
   Enabled: true
   AcrossComments: true
+  AcrossEmptyLines: false
 
-# 是否允许短代码块(如 { ... })出现在单行
-# true  -> 允许短块单行(例如 `{}` 或 `{ a(); }`)
-# 你的原值 true:保持允许(便于简短动作写在一行)
-AllowShortBlocksOnASingleLine: true
+# 对齐位字段和连续赋值(嵌入式配置常用)
+AlignConsecutiveAssignments:
+  Enabled: true
+  AcrossEmptyLines: false
+AlignConsecutiveBitFields:
+  Enabled: true
 
-# 是否允许短 case 标签单行
-# true  -> 允许 `case X: doSomething();`
+# --- 单行短代码压缩策略 ---
+AllowShortBlocksOnASingleLine: true
 AllowShortCaseLabelsOnASingleLine: true
-
-# 是否允许短枚举在一行
-# true  -> 允许短枚举如 `enum { A, B };`
 AllowShortEnumsOnASingleLine: false
-
-# 是否允许短函数在单行
-# None 表示对所有函数都应用此规则(即不限制单行函数)
-# 通常我们不希望把所有函数压成一行,所以保留 None(更严格)
-AllowShortFunctionsOnASingleLine: true
-
-AllowShortCaseExpressionOnASingleLine: true
-
-# 短 if 语句单行显示策略
-# Always  -> 允许并尽可能保留短 if 语句为单行(包括带 else 的情况)
-# 你希望单行 + 大括号时使用这个选项
-AllowShortIfStatementsOnASingleLine: true
-
-# 是否允许短循环(for/while)单行显示
+AllowShortFunctionsOnASingleLine: All # 建议显式设为 All
+AllowShortIfStatementsOnASingleLine: AllIfAndElse # 允许 if/else 都在单行
 AllowShortLoopsOnASingleLine: true
 
-# 属性宏列表,列出在格式化时应视为属性的宏(影响对齐、换行等)
-# 如果代码库使用自定义属性宏,把它们列在这里可以提升格式化准确性
-AttributeMacros:
-  - __aligned
-  - __deprecated
-  - __packed
-  - __printf_like
-  - __syscall
-  - __syscall_always_inline
-  - __subsystem
-
-# 位字段冒号后的空格:After 表示 `int x : 3;` 中冒号后带一个空格(风格选择)
-BitFieldColonSpacing: After
+# --- 缩进与制表符 ---
+IndentWidth: 8
+TabWidth: 8  # 必须与 IndentWidth 一致
+UseTab: ForContinuationAndIndentation
+ContinuationIndentWidth: 8
+ConstructorInitializerIndentWidth: 8
 
-# 大括号换行策略:使用 Custom 配合 BraceWrapping 指定细节
-# 你用了 Custom,这意味着下面的 BraceWrapping 字段决定具体行为
+# --- 大括号换行 (重点修正) ---
 BreakBeforeBraces: Custom
 BraceWrapping:
-  AfterCaseLabel: false           # case 标签后不另起行放 {,通常 case: 仍和语句对齐
-  AfterClass: true                # class 后大括号另起行
-  AfterControlStatement: Always   # 控制语句(if/for/while)后通常将 { 放在新行(可被覆盖)
-  AfterEnum: true                 # enum 后另起行
+  AfterCaseLabel: false
+  AfterClass: true
+  # 改为 MultiLine: 只有当 if 内容本身跨行时,大括号才换行
+  # 这样可以配合 AllowShortIfStatements 保持真正的单行短语句
+  AfterControlStatement: MultiLine 
+  AfterEnum: true
   AfterExternBlock: false
-  AfterFunction: true             # 函数体大括号另起行
+  AfterFunction: true
   AfterNamespace: true
   AfterObjCDeclaration: true
   AfterStruct: true
@@ -80,88 +49,21 @@ BraceWrapping:
   BeforeElse: true
   BeforeLambdaBody: false
   BeforeWhile: false
-  IndentBraces: false             # 不单独缩进大括号行
+  IndentBraces: false
   SplitEmptyFunction: true
   SplitEmptyRecord: true
   SplitEmptyNamespace: true
 
-# 单行代码的最大列数(换行阈值)
+# --- 细节修正 ---
 ColumnLimit: 140
-
-# 构造函数初始化列表的缩进宽度(可针对长列表调整可读性)
-ConstructorInitializerIndentWidth: 8
-
-# 折行缩进宽度(续行缩进)
-ContinuationIndentWidth: 8
-
-# ForEach 宏列表:告诉 clang-format 哪些宏应当当作循环处理(便于格式化块体)
-ForEachMacros:
-  - "ARRAY_FOR_EACH"
-  - "ARRAY_FOR_EACH_PTR"
-  - "FOR_EACH"
-
-# If 宏列表:把 CHECKIF 等宏视为 if 语句(影响括号和后续块处理)
-IfMacros:
-  - "CHECKIF"
-
-# include 文件的分类和排序优先级
-# Regex: 正则匹配,Priority: 数字越小优先级越高(越先放)
-IncludeCategories:
-  - Regex: '^".*\.h"$'
-    Priority: 0
-  - Regex: '^<(assert|complex|ctype|errno|fenv|float|inttypes|limits|locale|math|setjmp|signal|stdarg|stdbool|stddef|stdint|stdio|stdlib|string|tgmath|time|wchar|wctype)\.h>$'
-    Priority: 1
-  - Regex: '^\<Ryan/.*\.h\>$'
-    Priority: 2
-  - Regex: ".*"
-    Priority: 3
-
-# case 标签是否缩进(true 会将 case 缩进到 switch 中)
-# false -> case 与 switch 对齐(你原先设置 false)
 IndentCaseLabels: false
-
-# goto 标签是否缩进(false 表示标签在行首)
 IndentGotoLabels: false
-
-# 缩进宽度(通常与制表符策略配合使用)
-IndentWidth: 8
-
-# 自动插入大括号(即使单语句也插入 { })
-# 这可以避免单行语句因为后续添加语句而引入 bug
 InsertBraces: true
-
-# 文件末尾自动插入换行
 InsertNewlineAtEOF: true
+SortIncludes: Never # 既然你不排序,IncludeCategories 的优先级其实失效了
 
-# 继承冒号前是否加空格(False 表示不加空格:"class A: public B")
-SpaceBeforeInheritanceColon: False
+# 强制在指针符号左侧对齐 (int* p),如果你喜欢嵌入式风格 (int *p),改为 Right
+PointerAlignment: Right 
 
-# 控制语句后是否加空格(这个值控制 if/for/while 等的格式)
-# ControlStatementsExceptControlMacros -> 控制语句(非宏)前加空格:`if (cond)` 而非 `if(cond)`
+# 控制语句空格
 SpaceBeforeParens: ControlStatementsExceptControlMacros
-
-# 包含文件是否自动排序(Never 表示不排序)
-SortIncludes: Never
-
-# 缩进与续行使用制表符策略
-# ForContinuationAndIndentation -> 续行与缩进使用制表符,其他空格仍按规则
-UseTab: ForContinuationAndIndentation
-
-# 对空白敏感的宏列表(多用于预处理器宏展开格式保持)
-WhitespaceSensitiveMacros:
-  - COND_CODE_0
-  - COND_CODE_1
-  - IF_DISABLED
-  - IF_ENABLED
-  - LISTIFY
-  - STRINGIFY
-  - Z_STRINGIFY
-  - DT_FOREACH_PROP_ELEM_SEP
-
-# --------------------------
-# 可选:降低 clang-format 拆行惩罚,使其更倾向于保留短 if/else 单行
-# 下面两个值可以帮助把格式化后的多行 if/else 更可能压缩成单行(仅在 AllowShortIfStatementsOnASingleLine: Always 有效时可用)
-# PenaltyBreakIfElse: 0
-# PenaltyBreakStatement: 0
-
-# 注:上面的 Penalty 设置是可选的,如果你发现 clang-format 依旧不把某些 if/else 压成单行,可以取消注释并试验效果。

+ 1 - 1
README.md

@@ -246,7 +246,7 @@ json原始文本长度为 100, 序列化后RyanJson内存占用: 300, cJSON内
 
 
 
-RFC 8295 标准测试,大部分嵌入式场景不会出现极为特殊的Unicode字符集
+RFC 8259 标准测试,大部分嵌入式场景不会出现极为特殊的Unicode字符集
 
 ***如果项目需要完全兼容Unicode字符集,可以考虑yyjson / json-c***
 

+ 2 - 2
RyanJson/RyanJsonUtils.c

@@ -22,7 +22,7 @@ RyanJson_t RyanJsonGetObjectByKeys(RyanJson_t pJson, const char *key, ...)
 	while (nextItem && NULL != nextKey)
 	{
 		nextItem = RyanJsonGetObjectByKey(nextItem, nextKey);
-		nextKey = va_arg(args, char *);
+		nextKey = va_arg(args, const char *);
 	}
 	va_end(args);
 
@@ -34,7 +34,7 @@ RyanJson_t RyanJsonGetObjectByKeys(RyanJson_t pJson, const char *key, ...)
  *
  * @param pJson
  * @param index
- * @param ... 可变参,连续输入索引,直到INT_MIN结束
+ * @param ... 可变参,连续输入索引,直到UINT32_MAX结束
  * @return RyanJson_t
  */
 RyanJson_t RyanJsonGetObjectByIndexs(RyanJson_t pJson, uint32_t index, ...)

+ 2 - 1
run_coverage.sh

@@ -41,4 +41,5 @@ llvm-cov show ./build/linux/x86/release/RyanJson \
   -show-expansions \
   -show-regions \
   -show-line-counts-or-regions \
-  -sources ./test/fuzzer ./RyanJson
+  -sources ./RyanJson
+#   -sources ./test/fuzzer ./RyanJson

+ 1 - 1
test/RyanJsonRFC8259JsonTest.c

@@ -66,8 +66,8 @@ static int testFile(const char *path, jsonParseData jsonParseDataHandle)
 		{
 			int area = 0, use = 0;
 			v_mcheck(&area, &use);
-			free(data);
 			printf("内存泄漏 %s len: %ld\r\n", data, len);
+            free(data);
 			// printf("内存泄漏 %x len: %ld\r\n", (unsigned int)data, len);
 			// printf("内存泄漏 %c len: %ld\r\n", (int)data, len);
 			printf("|||----------->>> area = %d, size = %d\r\n", area, use);

+ 9 - 9
test/baseTest/RyanJsonBaseTest.h

@@ -32,15 +32,15 @@ extern RyanJsonBool_e arrayNodeCheckTest(RyanJson_t json);
 extern RyanJsonBool_e arrayItemNodeCheckTest(RyanJson_t json);
 extern RyanJsonBool_e RyanJsonBaseTestCheckRoot(RyanJson_t pJson);
 
-extern RyanJsonBool_e RyanJsonBaseTestChangeJson();
-extern RyanJsonBool_e RyanJsonBaseTestCompareJson();
-extern RyanJsonBool_e RyanJsonBaseTestCreateJson();
-extern RyanJsonBool_e RyanJsonBaseTestDeleteJson();
-extern RyanJsonBool_e RyanJsonBaseTestDetachJson();
-extern RyanJsonBool_e RyanJsonBaseTestDuplicateJson();
-extern RyanJsonBool_e RyanJsonBaseTestForEachJson();
-extern RyanJsonBool_e RyanJsonBaseTestLoadJson();
-extern RyanJsonBool_e RyanJsonBaseTestReplaceJson();
+extern RyanJsonBool_e RyanJsonBaseTestChangeJson(void);
+extern RyanJsonBool_e RyanJsonBaseTestCompareJson(void);
+extern RyanJsonBool_e RyanJsonBaseTestCreateJson(void);
+extern RyanJsonBool_e RyanJsonBaseTestDeleteJson(void);
+extern RyanJsonBool_e RyanJsonBaseTestDetachJson(void);
+extern RyanJsonBool_e RyanJsonBaseTestDuplicateJson(void);
+extern RyanJsonBool_e RyanJsonBaseTestForEachJson(void);
+extern RyanJsonBool_e RyanJsonBaseTestLoadJson(void);
+extern RyanJsonBool_e RyanJsonBaseTestReplaceJson(void);
 
 #ifdef __cplusplus
 }

+ 4 - 4
test/baseTest/RyanJsonBaseTestChangeJson.c

@@ -2,7 +2,7 @@
 
 /* --------------------------------------------------------------------- */
 
-RyanJsonBool_e RyanJsonBaseTestChangeJson()
+RyanJsonBool_e RyanJsonBaseTestChangeJson(void)
 {
 	char jsonstr[] =
 		"{\"inter\":16,\"double\":16.89,\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null,"
@@ -84,11 +84,11 @@ RyanJsonBool_e RyanJsonBaseTestChangeJson()
 	/**
 	 * @brief 修改数组对象中的字段 (arrayItem[0].inter -> 123)
 	 */
-	RyanJsonChangeIntValue(RyanJsonGetObjectToKey(RyanJsonGetObjectToIndex(RyanJsonGetObjectByKey(json, "arrayItem"), 0), "inter"),
+	RyanJsonChangeIntValue(RyanJsonGetObjectToKey(RyanJsonGetObjectToIndex(RyanJsonGetObjectToKey(json, "arrayItem"), 0), "inter"),
 			       123);
 	RyanJsonCheckCode(
-		RyanJsonIsInt(RyanJsonGetObjectToKey(RyanJsonGetObjectToIndex(RyanJsonGetObjectByKey(json, "arrayItem"), 0), "inter")) &&
-			RyanJsonGetIntValue(RyanJsonGetObjectToKey(RyanJsonGetObjectToIndex(RyanJsonGetObjectByKey(json, "arrayItem"), 0),
+		RyanJsonIsInt(RyanJsonGetObjectToKey(RyanJsonGetObjectToIndex(RyanJsonGetObjectToKey(json, "arrayItem"), 0), "inter")) &&
+			RyanJsonGetIntValue(RyanJsonGetObjectToKey(RyanJsonGetObjectToIndex(RyanJsonGetObjectToKey(json, "arrayItem"), 0),
 								   "inter")) == 123,
 		{ goto err; });
 

+ 1 - 1
test/baseTest/RyanJsonBaseTestCompareJson.c

@@ -1,7 +1,7 @@
 #include "RyanJsonBaseTest.h"
 /* --------------------------------------------------------------------- */
 
-RyanJsonBool_e RyanJsonBaseTestCompareJson()
+RyanJsonBool_e RyanJsonBaseTestCompareJson(void)
 {
 	char jsonstr[] = "{\"inter\":16,\"double\":16.89,\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null,\"item\":"
 			 "{\"inter\":16,\"double\":16."

+ 1 - 1
test/baseTest/RyanJsonBaseTestCreateJson.c

@@ -1,7 +1,7 @@
 
 #include "RyanJsonBaseTest.h"
 
-RyanJsonBool_e RyanJsonBaseTestCreateJson()
+RyanJsonBool_e RyanJsonBaseTestCreateJson(void)
 {
 	RyanJson_t jsonRoot, item;
 

+ 1 - 1
test/baseTest/RyanJsonBaseTestDeleteJson.c

@@ -2,7 +2,7 @@
 
 /* --------------------------------------------------------------------- */
 
-RyanJsonBool_e RyanJsonBaseTestDeleteJson()
+RyanJsonBool_e RyanJsonBaseTestDeleteJson(void)
 {
 	// 保持原始 jsonStr,不做修改
 	char jsonstr[] =

+ 5 - 3
test/baseTest/RyanJsonBaseTestDetachJson.c

@@ -2,7 +2,7 @@
 
 /* --------------------------------------------------------------------- */
 
-RyanJsonBool_e RyanJsonBaseTestDetachJson()
+RyanJsonBool_e RyanJsonBaseTestDetachJson(void)
 {
 	char jsonstr[] =
 		"{\"inter\":16,\"double\":16.89,\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null,\"item\":"
@@ -58,16 +58,18 @@ RyanJsonBool_e RyanJsonBaseTestDetachJson()
 		RyanJson_t arr = RyanJsonGetObjectByKey(json, "arrayInt");
 		RyanJson_t json2 = RyanJsonParse(jsonstr);
 
+        uint32_t jsonSize =  RyanJsonGetSize(arr);
 		// 头部
 		RyanJsonDelete(RyanJsonDetachByIndex(arr, 0));
-		if (RyanJsonGetObjectToIndex(arr, 0) == NULL)
+		if (jsonSize == RyanJsonGetSize(arr))
 		{
 			RyanJsonCheckCode(NULL, { goto err; });
 		}
 
 		// 中间
+         jsonSize =  RyanJsonGetSize(arr);
 		RyanJsonDelete(RyanJsonDetachByIndex(arr, 2));
-		if (RyanJsonGetObjectToIndex(arr, 2) == NULL)
+		if (jsonSize == RyanJsonGetSize(arr))
 		{
 			RyanJsonCheckCode(NULL, { goto err; });
 		}

+ 1 - 1
test/baseTest/RyanJsonBaseTestDuplicateJson.c

@@ -1,7 +1,7 @@
 
 #include "RyanJsonBaseTest.h"
 
-RyanJsonBool_e RyanJsonBaseTestDuplicateJson()
+RyanJsonBool_e RyanJsonBaseTestDuplicateJson(void)
 {
 	RyanJson_t json, dupItem, jsonRoot = NULL;
 	char jsonstr[] = "{\"inter\":16,\"double\":16.89,\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null,\"item\":"

+ 1 - 1
test/baseTest/RyanJsonBaseTestForEachJson.c

@@ -1,7 +1,7 @@
 
 #include "RyanJsonBaseTest.h"
 
-RyanJsonBool_e RyanJsonBaseTestForEachJson()
+RyanJsonBool_e RyanJsonBaseTestForEachJson(void)
 {
 	char *str = NULL;
 	char jsonstr[] = "{\"inter\":16,\"double\":16.89,\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null,\"item\":"

+ 1 - 1
test/baseTest/RyanJsonBaseTestLoadJson.c

@@ -3,7 +3,7 @@
 
 /* --------------------------------------------------------------------- */
 
-RyanJsonBool_e RyanJsonBaseTestLoadJson()
+RyanJsonBool_e RyanJsonBaseTestLoadJson(void)
 {
 	char *str = NULL;
 	RyanJson_t json;

+ 1 - 2
test/baseTest/RyanJsonBaseTestReplaceJson.c

@@ -2,7 +2,7 @@
 
 /* --------------------------------------------------------------------- */
 
-RyanJsonBool_e RyanJsonBaseTestReplaceJson()
+RyanJsonBool_e RyanJsonBaseTestReplaceJson(void)
 {
 	char jsonstr[] =
 		"{\"inter\":16,\"double\":16.89,\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null,\"item\":"
@@ -96,7 +96,6 @@ RyanJsonBool_e RyanJsonBaseTestReplaceJson()
 	RyanJsonReplaceByIndex(RyanJsonGetObjectToKey(json, "arrayString"), 1, RyanJsonCreateString(NULL, "headString"));
 	{
 		RyanJson_t v = RyanJsonGetObjectToIndex(RyanJsonGetObjectToKey(json, "arrayString"), 1);
-		printJsonDebug(v);
 		RyanJsonCheckCode(RyanJsonIsString(v), { goto err; });
 		RyanJsonCheckCode(strcmp(RyanJsonGetStringValue(v), "headString") == 0, { goto err; });
 	}