This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 29ea4d0fbd1 Enhance code compliance and add AI Common Pitfalls guide 
(#37055)
29ea4d0fbd1 is described below

commit 29ea4d0fbd1703cea1db50b79e204c460cbe2bc7
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Nov 9 20:11:17 2025 +0800

    Enhance code compliance and add AI Common Pitfalls guide (#37055)
    
    - Add AI Common Pitfalls section to CLAUDE.md documenting common errors
    - Fix test variable naming violations in HintValueContextTest.java (result 
-> actual)
    - Refactor GlobalRulesBuilder to use functional style for stream collection
    - Update CODE_OF_CONDUCT.md references with proper links in CLAUDE.md
    
    🤖 Generated with [Claude Code](https://claude.com/claude-code)
    
    Co-authored-by: Claude <[email protected]>
---
 CLAUDE.md                                          | 33 +++++++++++++++++-----
 .../rule/builder/global/GlobalRulesBuilder.java    |  7 ++---
 .../infra/hint/HintValueContextTest.java           | 24 ++++++++--------
 3 files changed, 40 insertions(+), 24 deletions(-)

diff --git a/CLAUDE.md b/CLAUDE.md
index c559b3022a7..c6d75f55c6a 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -2,9 +2,9 @@
 
 ## Mandatory Pre-Development Checklist
 
-**CRITICAL: Claude must treat CODE_OF_CONDUCT.md as ABSOLUTE LAW with ZERO 
tolerance for violations.**
+**CRITICAL: Claude must treat [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) as 
ABSOLUTE LAW with ZERO tolerance for violations.**
 
-Before writing any code, AI must:
+Before writing any code, Claude must:
 
 1. **Re-read CLAUDE.md in full** - Memory reliance is forbidden
 2. **Identify and confirm relevant standards** - Find corresponding sections 
based on task type
@@ -43,12 +43,31 @@ Before writing any code, AI must:
 - New testing patterns are discovered
 
 ### Violation Consequences:
-- Any CODE_OF_CONDUCT.md violation = COMPLETE code failure
+- Any [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) violation = COMPLETE code 
failure
 - Any inline comment or non-self-documenting code = IMMEDIATE rewrite required
 - Must immediately stop and rewrite according to standards
 - No excuses, no exceptions, no workarounds
 
-**This checklist overrides all other instructions. CODE_OF_CONDUCT.md 
compliance is NON-NEGOTIABLE.**
+**This checklist overrides all other instructions. 
[CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) compliance is NON-NEGOTIABLE.**
+
+## AI Common Pitfalls
+*Record AI common errors during development and preventive measures*
+
+### Method Internal Blank Lines
+**Error**: Adding meaningless blank lines within methods to separate logic 
blocks
+**Correct**: Keep method internals continuous, manage complexity by extracting 
private methods
+**Rule basis**: [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) line 29 explicitly 
states no meaningless blank lines should exist
+**Preventive measures**:
+- Check for internal blank lines immediately after writing methods
+- Extract private methods for complex logic instead of using blank lines for 
separation
+
+### Test Variable Naming Confusion
+**Error**: Using `result` as assertion variable name in test code
+**Correct**: Use `actual` in test code, use `result` in production code
+**Rule basis**: [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) line 103 explicitly 
states actual values in test cases should be named `actual XXX`
+**Preventive measures**:
+- Check variable naming immediately when generating test code
+- Build conditioned reflex: use `actual` for test assertions, use `result` for 
production return values
 
 ---
 
@@ -107,7 +126,7 @@ Key areas covered by code standards documents:
 - **Element addition strategy**: Add new elements to existing test data 
collections to trigger new branches
 - **Coverage-driven iteration**: Continue adding tests until 100% instruction 
coverage is achieved
 
-*For detailed testing standards, see CODE_OF_CONDUCT.md reference in code 
standards section*
+*For detailed testing standards, see 
[CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) reference in code standards section*
 
 ## AI Testing Case Development Standards
 *Effective testing case development standards and workflows for all new test 
code*
@@ -277,7 +296,7 @@ Key areas covered by code standards documents:
 - **Framework Dependency Reduction**: Minimize test framework extensions and 
annotations when not necessary
 - **Logic Extraction**: Extract repetitive mock setup and assertion logic into 
private methods
 
-*For detailed test organization standards, see CODE_OF_CONDUCT.md reference in 
code standards section*
+*For detailed test organization standards, see 
[CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) reference in code standards section*
 
 ### Testing Case Development Standards
 For comprehensive testing case development requirements, see [AI Testing Case 
Development Standards](#ai-testing-case-development-standards) above.
@@ -368,7 +387,7 @@ For comprehensive testing case development requirements, 
see [AI Testing Case De
 - **Intelligence**: Apply pattern recognition capabilities from AI Code 
Understanding Guidelines above
 
 ### Formatting Standards
-*For formatting guidance, see CODE_OF_CONDUCT.md reference in elegant code 
standards section*
+*For formatting guidance, see C[CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) 
reference in elegant code standards section*
 
 ## Unified Guidelines
 *Operating scope, permissions, and decision framework*
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java
index b1529ce53f2..0a28e081dc4 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java
@@ -67,13 +67,10 @@ public final class GlobalRulesBuilder {
     
     @SuppressWarnings("rawtypes")
     private static Map<RuleConfiguration, GlobalRuleBuilder> 
getMissedDefaultRuleBuilderMap(final Map<RuleConfiguration, GlobalRuleBuilder> 
builders) {
-        Map<RuleConfiguration, GlobalRuleBuilder> result = new 
LinkedHashMap<>();
         Map<GlobalRuleBuilder, DefaultGlobalRuleConfigurationBuilder> 
defaultBuilders = OrderedSPILoader.getServices(
                 DefaultGlobalRuleConfigurationBuilder.class, 
getMissedDefaultRuleBuilders(builders.values()));
-        for (Entry<GlobalRuleBuilder, DefaultGlobalRuleConfigurationBuilder> 
entry : defaultBuilders.entrySet()) {
-            result.put(entry.getValue().build(), entry.getKey());
-        }
-        return result;
+        return defaultBuilders.entrySet().stream().collect(
+                Collectors.toMap(entry -> entry.getValue().build(), 
Entry::getKey, (oldValue, currentValue) -> currentValue, LinkedHashMap::new));
     }
     
     @SuppressWarnings({"unchecked", "rawtypes"})
diff --git 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/hint/HintValueContextTest.java
 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/hint/HintValueContextTest.java
index 83748c38efa..8ac144b1be6 100644
--- 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/hint/HintValueContextTest.java
+++ 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/hint/HintValueContextTest.java
@@ -75,35 +75,35 @@ class HintValueContextTest {
     void assertGetHintShardingTableValueWithTableName() {
         HintValueContext hintValueContext = new HintValueContext();
         
hintValueContext.getShardingTableValues().put("TABLE.SHARDING_TABLE_VALUE", 
"1");
-        Collection<Comparable<?>> result = 
hintValueContext.getHintShardingTableValue("table");
-        assertThat(result.size(), is(1));
-        assertThat(result.iterator().next(), is("1"));
+        Collection<Comparable<?>> actual = 
hintValueContext.getHintShardingTableValue("table");
+        assertThat(actual.size(), is(1));
+        assertThat(actual.iterator().next(), is("1"));
     }
     
     @Test
     void assertSetHintShardingTableValueWithoutTableName() {
         HintValueContext hintValueContext = new HintValueContext();
         hintValueContext.getShardingTableValues().put("SHARDING_TABLE_VALUE", 
"2");
-        Collection<Comparable<?>> result = 
hintValueContext.getHintShardingTableValue("other_table");
-        assertThat(result.size(), is(1));
-        assertThat(result.iterator().next(), is("2"));
+        Collection<Comparable<?>> actual = 
hintValueContext.getHintShardingTableValue("other_table");
+        assertThat(actual.size(), is(1));
+        assertThat(actual.iterator().next(), is("2"));
     }
     
     @Test
     void assertGetHintShardingDatabaseValueWithTableName() {
         HintValueContext hintValueContext = new HintValueContext();
         
hintValueContext.getShardingDatabaseValues().put("TABLE.SHARDING_DATABASE_VALUE",
 "1");
-        Collection<Comparable<?>> result = 
hintValueContext.getHintShardingDatabaseValue("table");
-        assertThat(result.size(), is(1));
-        assertThat(result.iterator().next(), is("1"));
+        Collection<Comparable<?>> actual = 
hintValueContext.getHintShardingDatabaseValue("table");
+        assertThat(actual.size(), is(1));
+        assertThat(actual.iterator().next(), is("1"));
     }
     
     @Test
     void assertGetHintShardingDatabaseValueWithoutTableName() {
         HintValueContext hintValueContext = new HintValueContext();
         
hintValueContext.getShardingDatabaseValues().put("SHARDING_DATABASE_VALUE", 
"2");
-        Collection<Comparable<?>> result = 
hintValueContext.getHintShardingDatabaseValue("other_table");
-        assertThat(result.size(), is(1));
-        assertThat(result.iterator().next(), is("2"));
+        Collection<Comparable<?>> actual = 
hintValueContext.getHintShardingDatabaseValue("other_table");
+        assertThat(actual.size(), is(1));
+        assertThat(actual.iterator().next(), is("2"));
     }
 }

Reply via email to