Skip to content

Commit a9a7732

Browse files
justin808claude
andcommitted
Fix CI failures: RuboCop violations and add AI coding agent best practices
- Add RuboCop disable/enable for ABC complexity in colorized help methods - Auto-fix ESLint/Prettier formatting in generator template files - Add comprehensive "Best Practices for AI Coding Agents" section to CONTRIBUTING.md - Include mandatory linting workflow to prevent CI failures - Document common AI agent mistakes and auto-fix commands All linters now pass locally before commit. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f36e40d commit a9a7732

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed

CONTRIBUTING.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,67 @@ rake lint
502502

503503
**Tip**: Set up your IDE to run these automatically on save to catch issues early.
504504

505+
## 🤖 Best Practices for AI Coding Agents
506+
507+
**CRITICAL WORKFLOW** to prevent CI failures:
508+
509+
### 1. **ALWAYS Lint Before Any Code Changes**
510+
```bash
511+
# First, check current state
512+
rake lint
513+
514+
# If violations exist, auto-fix them first
515+
yarn run eslint . --fix # Auto-fix JS/TS formatting
516+
bundle exec rubocop -A # Auto-fix Ruby violations
517+
```
518+
519+
### 2. **After Making Code Changes**
520+
```bash
521+
# MANDATORY: Run linters again
522+
rake lint
523+
524+
# If any violations, auto-fix immediately
525+
yarn run eslint . --fix
526+
bundle exec rubocop -A
527+
528+
# Verify everything passes
529+
rake lint
530+
```
531+
532+
### 3. **Common AI Agent Mistakes**
533+
534+
**DON'T:**
535+
- Make code changes without running linters first
536+
- Commit code that hasn't been linted locally
537+
- Ignore formatting rules when creating new files
538+
- Add manual formatting that conflicts with Prettier/RuboCop
539+
540+
**DO:**
541+
- Run `rake lint` before AND after any code changes
542+
- Use auto-fix options (`--fix`, `-A`) to resolve violations
543+
- Create new files that follow existing patterns
544+
- Test locally before committing
545+
546+
### 4. **Template File Best Practices**
547+
548+
When creating new template files (`.jsx`, `.rb`, etc.):
549+
1. Copy existing template structure and patterns
550+
2. Run `yarn run eslint . --fix` immediately after creation
551+
3. Verify with `rake lint` before committing
552+
553+
### 5. **RuboCop Complexity Issues**
554+
555+
For methods with high ABC complexity (usually formatting/display methods):
556+
```ruby
557+
# rubocop:disable Metrics/AbcSize
558+
def complex_formatting_method
559+
# ... method with lots of string interpolation/formatting
560+
end
561+
# rubocop:enable Metrics/AbcSize
562+
```
563+
564+
**Remember**: Failing CI wastes time and resources. Always lint locally first!
565+
505566
### Linting
506567

507568
All linting is performed from the docker container for CI. You will need docker and docker-compose installed locally to lint code changes via the lint container. You can lint locally by running `npm run lint && npm run flow`

lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.client.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ const HelloWorld = (props) => {
1818
);
1919
};
2020

21-
export default HelloWorld;
21+
export default HelloWorld;

lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.server.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import HelloWorld from './HelloWorld.client';
22
// This could be specialized for server rendering
33
// For example, if using React Router, we'd have the SSR setup here.
44

5-
export default HelloWorld;
5+
export default HelloWorld;

lib/react_on_rails/dev/server_manager.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def help_usage
122122
Rainbow("📋 Usage: bin/dev [command] [options]").bold
123123
end
124124

125+
# rubocop:disable Metrics/AbcSize
125126
def help_commands
126127
<<~COMMANDS
127128
#{Rainbow('🚀 COMMANDS:').cyan.bold}
@@ -139,6 +140,7 @@ def help_commands
139140
#{Rainbow('help').blue.bold} #{Rainbow('Show this help message').white}
140141
COMMANDS
141142
end
143+
# rubocop:enable Metrics/AbcSize
142144

143145
def help_options
144146
<<~OPTIONS
@@ -160,6 +162,7 @@ def help_customization
160162
CUSTOMIZATION
161163
end
162164

165+
# rubocop:disable Metrics/AbcSize
163166
def help_mode_details
164167
<<~MODES
165168
#{Rainbow('🔥 HMR Development mode (default)').cyan.bold} - #{Rainbow('Procfile.dev').green}:
@@ -190,6 +193,7 @@ def help_mode_details
190193
#{Rainbow('•').yellow} #{Rainbow('Access at:').white} #{Rainbow('http://localhost:3001/hello_world').cyan.underline}
191194
MODES
192195
end
196+
# rubocop:enable Metrics/AbcSize
193197

194198
def run_production_like(_verbose: false)
195199
procfile = "Procfile.dev-prod-assets"
@@ -296,6 +300,7 @@ def format_box_line(content, box_width)
296300
line + "#{' ' * padding}│"
297301
end
298302

303+
# rubocop:disable Metrics/AbcSize
299304
def help_troubleshooting
300305
<<~TROUBLESHOOTING
301306
#{Rainbow('🔧 TROUBLESHOOTING:').cyan.bold}
@@ -318,6 +323,7 @@ def help_troubleshooting
318323
#{Rainbow('📚 Need help? Visit:').blue.bold} #{Rainbow('https://www.shakacode.com/react-on-rails/docs/').cyan.underline}
319324
TROUBLESHOOTING
320325
end
326+
# rubocop:enable Metrics/AbcSize
321327
end
322328
end
323329
end

0 commit comments

Comments
 (0)