Skip to content

Fix/july #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions .cursor/rules/sonar.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
alwaysApply: true
---
# Cursor Rules for Dispute Resolver Project

## SonarCloud Quality Assurance

### Always Check SonarCloud Issues Before Code Changes

When asked about SonarCloud issues or code quality, use this recipe:

1. **Primary Method - IDE Diagnostics (Real-time)**:
```
mcp__ide__getDiagnostics() # Get all current issues
```

2. **Verify SonarLint Extension**:
```bash
code --list-extensions | grep -i sonar
```
Expected: `sonarsource.sonarlint-vscode`

3. **Check Specific Files** (for modified files from git status):
```
mcp__ide__getDiagnostics(uri="file:///absolute/path/to/file.js")
```

4. **Fallback - Read Existing Reports**:
```
Read("sonarcloud-issues-report.md")
Read("sonarcloud-remaining-issues.md")
```

### Interpretation Guidelines

- **Empty diagnostics = Clean code** - No SonarCloud violations
- **Focus on real-time data** - IDE diagnostics over static reports
- **Check modified files first** - Use git status to identify changed files
- **Verify extension status** - Ensure SonarLint is active for accurate results

### Code Quality Standards

- **Before making changes**: Check existing SonarCloud issues in target files
- **During development**: Follow established patterns and avoid introducing new issues
- **After changes**: Verify no new SonarCloud violations appear
- **Critical/Blocker issues**: Must be fixed immediately
- **Major issues**: Fix when touching the code
- **Minor issues**: Fix opportunistically

### Project-Specific Commands

```bash
# Development
npm start

# Testing
npm test

# Build
npm run build

# Linting (if available)
npm run lint
```

### Technology Stack Context

- React 17 with Create React App
- Web3/Ethereum integration with ethers.js
- SCSS styling with Bootstrap
- SonarCloud for code quality analysis

### Quality Gates

- Maintain or improve SonarCloud quality rating
- Keep code coverage stable or increasing
- Ensure no security issues are introduced
- Follow established code style and patterns

## General Development Rules

- **File Creation**: Only create new files when absolutely necessary
- **Prefer Editing**: Always prefer editing existing files over creating new ones
- **No Unsolicited Documentation**: Never create README or .md files unless explicitly requested
- **Follow Patterns**: Mimic existing code style and conventions
- **Security First**: Never expose secrets, keys, or sensitive information
- **Test After Changes**: Run tests to ensure no regressions

This ensures consistent SonarCloud quality checking across all AI interactions with the project.
85 changes: 85 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Claude AI Agent Guidelines for Dispute Resolver

## Code Quality Standards

This project uses SonarCloud for code quality analysis. The SonarQube extension is already configured and connected to our SonarCloud project.

### Before Making Any Code Changes

1. **Check Current Diagnostics**: Review any existing SonarCloud issues in files you plan to modify
2. **Understand Context**: Read the existing code patterns and follow established conventions
3. **Plan Changes**: Ensure changes align with SonarCloud quality profile

### During Code Development

1. **Follow SonarCloud Rules**: Never introduce code that would trigger SonarCloud warnings
2. **Fix Existing Issues**: When modifying a file, fix any existing SonarCloud issues if possible
3. **Maintain Quality**: Ensure all new code meets or exceeds current quality standards

### After Code Changes

1. **Verify No New Issues**: Check that no new SonarCloud diagnostics appear
2. **Test Functionality**: Ensure changes work correctly
3. **Document Changes**: Update comments and documentation as needed

## SonarCloud Quality Gates

- **Critical/Blocker Issues**: Must be fixed immediately
- **Major Issues**: Should be fixed when touching the code
- **Minor Issues**: Fix opportunistically

## Project-Specific Patterns

### Web3/Ethereum Code
- Always handle async operations properly
- Use proper error handling for contract calls
- Follow BigNumber handling patterns established in the codebase

### React Components
- Use hooks appropriately and follow React best practices
- Maintain consistent prop types and state management
- Follow established component structure patterns

### Testing
- Run existing tests after changes: `npm test`
- Ensure no regressions in functionality
- Add tests for new features when appropriate

## Commands to Run

```bash
# Start development server
npm start

# Run tests
npm test

# Build for production
npm run build

# Check for issues (if available)
npm run lint
```

## Quality Metrics

- Maintain or improve SonarCloud quality rating
- Keep code coverage stable or increasing
- Ensure no security issues are introduced
- Follow established code style and patterns

## Kleros Arbitration Standards (ERC-792 & ERC-1497)

[... previous content remains unchanged ...]

## Memories and Learning Notes

### Interface Compatibility and Dispute Handling
- Some arbitrables we load only implement IEvidence and IArbitrable, some implement IDisputeResolver in addition.
- Crowdfunded appeal and evidence submission functionalities are only guaranteed to work if the arbitrable implements IDisputeResolver.
- Other view functionality should work just fine.
- There might be bad disputes, such as those that are badly configured and do not follow the standard.
- We don't have to figure out how to display them perfectly, but we must make sure they don't crash the application altogether.
- When a bad dispute is encountered, the application should fail gracefully.

[... rest of the previous content remains unchanged ...]
220 changes: 220 additions & 0 deletions docs/ai-agent-sonarcloud-workflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
# AI Agent SonarCloud Workflow

## Overview

This document outlines the workflow for AI agents working with this codebase to ensure compliance with SonarCloud quality standards using the existing SonarQube extension.

## Prerequisites

- SonarQube extension is installed and configured in your IDE
- Extension is connected to the SonarCloud project
- Real-time analysis is enabled

## Workflow Steps

### 1. Before Making Any Changes

#### Check Current State
```bash
# Run quality check
./scripts/check-quality.sh

# Check specific file
./scripts/pre-change-check.sh src/path/to/file.js
```

#### Review IDE Diagnostics
- Open the file in your IDE
- Check the Problems panel for SonarCloud issues
- Look for SonarLint annotations in the code
- Note any existing issues that should be fixed

### 2. During Development

#### Follow SonarCloud Patterns
- **Code Style**: Match existing code patterns
- **Error Handling**: Use try/catch for async operations
- **Security**: Avoid eval(), innerHTML, document.write
- **Complexity**: Keep functions small and focused
- **Performance**: Avoid unnecessary computations

#### Common SonarCloud Rules to Follow

**JavaScript/React Specific:**
- Use `const` and `let` instead of `var`
- Prefer arrow functions for callbacks
- Use proper error handling for async operations
- Avoid console.log in production code
- Use meaningful variable names
- Keep functions under 50 lines when possible

**React Component Patterns:**
- Use hooks appropriately
- Avoid direct state mutations
- Use proper prop types
- Handle component lifecycle correctly

**Web3/Ethereum Patterns:**
- Handle BigNumber operations carefully
- Use proper error handling for contract calls
- Validate addresses and parameters
- Use safe arithmetic operations

### 3. After Making Changes

#### Verify Quality
```bash
# Quick check for common issues
./scripts/check-quality.sh

# Check modified file specifically
./scripts/pre-change-check.sh src/path/to/modified/file.js
```

#### IDE Verification
- Check Problems panel for new issues
- Ensure no new SonarCloud warnings appear
- Verify existing issues are fixed (if touched)

### 4. Quality Gates

#### Must Fix (Blocker/Critical)
- Security vulnerabilities
- Major bugs or logic errors
- Critical performance issues

#### Should Fix (Major)
- Code smells in modified files
- Maintainability issues
- Performance improvements

#### Can Fix (Minor)
- Style inconsistencies
- Documentation improvements
- Minor optimizations

## Common SonarCloud Issues and Solutions

### 1. Complexity Issues
```javascript
// ❌ Too complex
function processData(data) {
if (data && data.length > 0) {
for (let i = 0; i < data.length; i++) {
if (data[i].status === 'active') {
// lots of nested logic...
}
}
}
}

// ✅ Simplified
function processData(data) {
if (!data?.length) return;

const activeItems = data.filter(item => item.status === 'active');
return activeItems.map(processActiveItem);
}

function processActiveItem(item) {
// focused logic
}
```

### 2. Async/Await Error Handling
```javascript
// ❌ No error handling
async function fetchData() {
const response = await fetch('/api/data');
return response.json();
}

// ✅ Proper error handling
async function fetchData() {
try {
const response = await fetch('/api/data');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
} catch (error) {
console.error('Error fetching data:', error);
throw error;
}
}
```

### 3. React Component Issues
```javascript
// ❌ Direct state mutation
this.state.items.push(newItem);

// ✅ Proper state update
this.setState(prevState => ({
items: [...prevState.items, newItem]
}));
```

### 4. Web3 Patterns
```javascript
// ❌ No validation
function transfer(address, amount) {
contract.transfer(address, amount);
}

// ✅ Proper validation
function transfer(address, amount) {
if (!ethers.utils.isAddress(address)) {
throw new Error('Invalid address');
}
if (amount <= 0) {
throw new Error('Amount must be positive');
}
return contract.transfer(address, amount);
}
```

## AI Agent Best Practices

### 1. Proactive Quality Checking
- Always check file quality before modifications
- Use IDE diagnostics as primary source of truth
- Run scripts to understand current state

### 2. Incremental Improvements
- Fix existing issues when touching files
- Don't introduce new quality issues
- Maintain or improve overall quality score

### 3. Documentation
- Update comments when changing logic
- Document complex business rules
- Explain Web3/blockchain specific patterns

### 4. Testing
- Run existing tests after changes
- Ensure no regressions
- Add tests for new functionality

## Troubleshooting

### SonarQube Extension Issues
- Restart VS Code if analysis stops working
- Check extension status in VS Code
- Verify connection to SonarCloud project

### Common Problems
- **No diagnostics appearing**: Check extension configuration
- **Too many false positives**: Review SonarCloud project settings
- **Performance issues**: Consider excluding large files from analysis

## Resources

- [SonarCloud Documentation](https://docs.sonarcloud.io/)
- [SonarLint VS Code Extension](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarlint-vscode)
- [Project CLAUDE.md](../CLAUDE.md) - AI agent guidelines
- [Quality Check Script](../scripts/check-quality.sh)

## Summary

This workflow ensures that AI agents can effectively use the existing SonarQube extension to maintain code quality without requiring additional tools. The key is to leverage the real-time feedback from the IDE and follow established patterns in the codebase.
Loading
Loading