Skip to content

Commit b93b10b

Browse files
justin808claude
andcommitted
Add CODING_AGENTS.md guide for AI contributors
Provides comprehensive guidelines for AI coding agents working with React on Rails, including: - Essential commands and CI compliance checklist - RuboCop patterns and common fixes - Test-driven development workflows - File processing best practices (learned from CSS module fix) - Git/PR workflows with proper commit messages - Debugging patterns and common pitfalls - Communication guidelines with human maintainers This guide supplements CONTRIBUTING.md with AI-specific workflows and will help future coding agents contribute more effectively. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 0e639f7 commit b93b10b

File tree

1 file changed

+284
-0
lines changed

1 file changed

+284
-0
lines changed

CODING_AGENTS.md

Lines changed: 284 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,284 @@
1+
# 🤖 Coding Agents & AI Contributors Guide
2+
3+
This guide provides specific guidelines for AI coding agents (like Claude Code) contributing to React on Rails. It supplements the main [CONTRIBUTING.md](./CONTRIBUTING.md) with AI-specific workflows and patterns.
4+
5+
## Quick Reference Commands
6+
7+
### Essential Commands
8+
```bash
9+
# Install dependencies
10+
bundle && yarn
11+
12+
# Run tests
13+
bundle exec rspec # All tests (from project root)
14+
cd spec/dummy && bundle exec rspec # Dummy app tests only
15+
16+
# Linting & Formatting
17+
bundle exec rubocop # Ruby linting
18+
bundle exec rubocop [file_path] # Lint specific file
19+
# Note: yarn format requires local setup, format manually
20+
21+
# Development
22+
cd spec/dummy && foreman start # Start dummy app with webpack
23+
```
24+
25+
### CI Compliance Checklist
26+
- [ ] `bundle exec rubocop` passes with no offenses
27+
- [ ] All RSpec tests pass
28+
- [ ] No trailing whitespace
29+
- [ ] Line length ≤120 characters
30+
- [ ] Security violations properly scoped with disable comments
31+
32+
## Development Patterns for AI Contributors
33+
34+
### 1. Task Management
35+
Always use TodoWrite tool for multi-step tasks to:
36+
- Track progress transparently
37+
- Show the user what's being worked on
38+
- Ensure no steps are forgotten
39+
- Mark tasks complete as you finish them
40+
41+
```markdown
42+
Example workflow:
43+
1. Analyze the problem
44+
2. Create test cases
45+
3. Implement the fix
46+
4. Run tests
47+
5. Fix linting issues
48+
6. Update documentation
49+
```
50+
51+
### 2. Test-Driven Development
52+
When fixing bugs or adding features:
53+
54+
1. **Create failing tests first** that reproduce the issue
55+
2. **Implement the minimal fix** to make tests pass
56+
3. **Add comprehensive test coverage** for edge cases
57+
4. **Verify all existing tests still pass**
58+
59+
### 3. File Processing Guidelines
60+
When working with file generation or processing:
61+
62+
- **Filter by extension**: Only process relevant files (e.g., `.js/.jsx/.ts/.tsx` for React components)
63+
- **Validate assumptions**: Don't assume all files in a directory are components
64+
- **Handle edge cases**: CSS modules, config files, etc. should be excluded appropriately
65+
66+
Example from CSS module fix:
67+
```ruby
68+
COMPONENT_EXTENSIONS = /\.(jsx?|tsx?)$/
69+
70+
def filter_component_files(paths)
71+
paths.grep(COMPONENT_EXTENSIONS)
72+
end
73+
```
74+
75+
## RuboCop Compliance Patterns
76+
77+
### Common Fixes
78+
79+
1. **Trailing Whitespace**
80+
```ruby
81+
# Bad
82+
let(:value) { "test" }
83+
84+
# Good
85+
let(:value) { "test" }
86+
```
87+
88+
2. **Line Length (120 chars max)**
89+
```ruby
90+
# Bad
91+
expect { eval(pack_content.gsub(/import.*from.*['"];/, "").gsub(/ReactOnRails\.register.*/, "")) }.not_to raise_error
92+
93+
# Good
94+
sanitized_content = pack_content.gsub(/import.*from.*['"];/, "")
95+
.gsub(/ReactOnRails\.register.*/, "")
96+
expect { eval(sanitized_content) }.not_to raise_error
97+
```
98+
99+
3. **Named Subjects (RSpec)**
100+
```ruby
101+
# Bad
102+
describe "#method_name" do
103+
subject { instance.method_name(arg) }
104+
105+
it "does something" do
106+
expect(subject).to eq "result"
107+
end
108+
end
109+
110+
# Good
111+
describe "#method_name" do
112+
subject(:method_result) { instance.method_name(arg) }
113+
114+
it "does something" do
115+
expect(method_result).to eq "result"
116+
end
117+
end
118+
```
119+
120+
4. **Security/Eval Violations**
121+
```ruby
122+
# Bad
123+
expect { eval(dangerous_code) }.not_to raise_error
124+
125+
# Good
126+
# rubocop:disable Security/Eval
127+
sanitized_content = dangerous_code.gsub(/harmful_pattern/, "")
128+
expect { eval(sanitized_content) }.not_to raise_error
129+
# rubocop:enable Security/Eval
130+
```
131+
132+
### RuboCop Workflow
133+
1. Run `bundle exec rubocop [file]` to see violations
134+
2. Fix violations manually or with auto-correct where safe
135+
3. Re-run to verify fixes
136+
4. Use disable comments sparingly and with good reason
137+
138+
## Testing Best Practices
139+
140+
### Test Structure
141+
```ruby
142+
describe "FeatureName" do
143+
context "when condition A" do
144+
let(:setup) { create_test_condition }
145+
146+
before do
147+
# Setup code
148+
end
149+
150+
it "does expected behavior" do
151+
# Arrange, Act, Assert
152+
end
153+
end
154+
end
155+
```
156+
157+
### Test Fixtures
158+
- Create realistic test data that represents edge cases
159+
- Use descriptive names for fixtures and variables
160+
- Clean up after tests (handled by RSpec automatically in most cases)
161+
162+
### CSS Module Testing Example
163+
```ruby
164+
# Create test fixtures
165+
Write.create("ComponentWithCSSModule.module.css", css_content)
166+
Write.create("ComponentWithCSSModule.jsx", jsx_content)
167+
168+
# Test the behavior
169+
it "ignores CSS module files during pack generation" do
170+
generated_packs = PacksGenerator.instance.generate_packs_if_stale
171+
expect(generated_packs).not_to include("ComponentWithCSSModule.module.js")
172+
end
173+
```
174+
175+
## Git & PR Workflow
176+
177+
### Branch Management
178+
```bash
179+
git checkout -b fix/descriptive-name
180+
# Make changes
181+
git add .
182+
git commit -m "Descriptive commit message
183+
184+
- Bullet points for major changes
185+
- Reference issue numbers
186+
- Include 🤖 Generated with Claude Code signature"
187+
188+
git push -u origin fix/descriptive-name
189+
```
190+
191+
### Commit Message Format
192+
```
193+
Brief description of the change
194+
195+
- Detailed bullet points of what changed
196+
- Why the change was needed
197+
- Any breaking changes or considerations
198+
199+
Fixes #issue_number
200+
201+
🤖 Generated with [Claude Code](https://claude.ai/code)
202+
203+
Co-Authored-By: Claude <[email protected]>
204+
```
205+
206+
### PR Creation
207+
Use `gh pr create` with:
208+
- Clear title referencing the issue
209+
- Comprehensive description with summary and test plan
210+
- Link to the issue being fixed
211+
- Include the Claude Code signature
212+
213+
## Common Pitfalls & Solutions
214+
215+
### 1. File Path Issues
216+
- Always use absolute paths in tools
217+
- Check current working directory with `pwd`
218+
- Use proper path joining methods
219+
220+
### 2. Test Environment
221+
- Run tests from correct directory (often project root)
222+
- Understand the difference between gem tests vs dummy app tests
223+
- Clean up test artifacts appropriately
224+
225+
### 3. Dependency Management
226+
- Don't assume packages are installed globally
227+
- Use `bundle exec` for Ruby commands
228+
- Verify setup with `bundle && yarn` when needed
229+
230+
### 4. RuboCop Configuration
231+
- Different rules may apply to different directories
232+
- Use `bundle exec rubocop` (not global rubocop)
233+
- Check `.rubocop.yml` files for project-specific rules
234+
235+
## Debugging Workflow
236+
237+
1. **Understand the Problem**
238+
- Read the issue carefully
239+
- Reproduce the bug if possible
240+
- Identify root cause
241+
242+
2. **Create Minimal Test Case**
243+
- Write failing test that demonstrates issue
244+
- Keep it focused and minimal
245+
246+
3. **Implement Fix**
247+
- Make smallest change possible
248+
- Ensure fix doesn't break existing functionality
249+
- Follow existing code patterns
250+
251+
4. **Verify Solution**
252+
- All new tests pass
253+
- All existing tests still pass
254+
- RuboCop compliance maintained
255+
- Manual testing if applicable
256+
257+
## IDE Configuration for AI Context
258+
259+
When analyzing codebases, ignore these directories to avoid confusion:
260+
- `/coverage`, `/tmp`, `/gen-examples`
261+
- `/node_package/lib`, `/node_modules`
262+
- `/spec/dummy/app/assets/webpack`
263+
- `/spec/dummy/log`, `/spec/dummy/node_modules`, `/spec/dummy/tmp`
264+
- `/spec/react_on_rails/dummy-for-generators`
265+
266+
## Communication with Human Maintainers
267+
268+
- Be transparent about AI-generated changes
269+
- Explain reasoning behind implementation choices
270+
- Ask for clarification when requirements are ambiguous
271+
- Provide comprehensive commit messages and PR descriptions
272+
- Include test plans and verification steps
273+
274+
## Resources
275+
276+
- [Main Contributing Guide](./CONTRIBUTING.md)
277+
- [Pull Request Guidelines](./docs/contributor-info/pull-requests.md)
278+
- [Generator Testing](./docs/contributor-info/generator-testing.md)
279+
- [RuboCop Documentation](https://docs.rubocop.org/)
280+
- [RSpec Best Practices](https://rspec.info/)
281+
282+
---
283+
284+
This guide evolves based on AI contributor experiences. Suggest improvements via issues or PRs!

0 commit comments

Comments
 (0)