Skip to content

Commit b276cb6

Browse files
justin808claude
andauthored
Fix RuboCop violations in demo apps (#66)
* Fix linting configuration for demo apps ## Changes **1. Fixed Broken Symlinks** - now points to (was pointing to wrong directory) - now points to (was broken) **2. Created Shared Config Files** - - Rails Omakase style - - React/TypeScript linting **3. Added ESLint Dependencies** Installed ESLint 8 and plugins in both demos (required for npm run lint): - eslint, eslint-plugin-react, eslint-plugin-react-hooks - eslint-plugin-jsx-a11y, eslint-plugin-import - @typescript-eslint/eslint-plugin, @typescript-eslint/parser - eslint-config-prettier **4. Fixed ESLint Violations** - Prefixed unused variables with underscore (_devServer, _inliningCss, _merge) - Added blank lines between import groups - Reordered imports (builtin before external) - Changed console.log to console.warn ## Verification Both demos now pass all linting: - ✅ bundle exec rubocop (0 offenses) - ✅ npm run lint (0 violations) - ✅ npm run format:check (all files formatted) ## Note on bin/ Files bin/ files are intentionally excluded from Rails Omakase StringLiterals enforcement and were not modified. Only app/, config/, lib/, test/, and Gemfile are enforced to use double quotes per Rails conventions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Simplify RuboCop config - inherit directly from rubocop-rails-omakase Instead of duplicating Rails Omakase config, each demo now inherits directly from the rubocop-rails-omakase gem using inherit_gem. Changes: - Removed shared rubocop.yml from shakacode_demo_common - Changed .rubocop.yml from symlink to actual file in each demo - Each demo now uses: inherit_gem: { rubocop-rails-omakase: rubocop.yml } - Fixed array bracket spacing per Rails Omakase conventions - Added rubocop disables for bin/switch-bundler complexity Benefits: - No config duplication - Always uses latest Rails Omakase rules from the gem - Cleaner, more maintainable setup 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Fix Playwright test formatting Fix formatting artifact where closing brace was on the same line. Before: await page.goto('/'); }); After: await page.goto('/'); }); 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Add ESLint and Prettier to pre-commit hooks Updated lefthook.yml to run ESLint and Prettier on staged files in demo apps during pre-commit. This prevents linting violations from being committed. Pre-commit hooks now run: - trailing-newline: Ensures all files end with newline - rubocop: Checks Ruby files - eslint: Checks and fixes JavaScript/TypeScript files in demos - prettier: Formats JavaScript/TypeScript/JSON/CSS/Markdown in demos Each tool runs only on staged files for fast commits. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent 0e76ec6 commit b276cb6

File tree

23 files changed

+8429
-560
lines changed

23 files changed

+8429
-560
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../packages/shakacode_demo_common/config/.eslintrc.js
1+
../../packages/shakacode_demo_common/configs/.eslintrc.js

demos/basic-v16-rspack/.rubocop.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Inherit from Rails Omakase style
2+
inherit_gem:
3+
rubocop-rails-omakase: rubocop.yml
4+
5+
# Demo-specific adjustments
6+
AllCops:
7+
NewCops: enable
8+
SuggestExtensions: false
9+
Exclude:
10+
- 'node_modules/**/*'
11+
- 'tmp/**/*'
12+
- 'vendor/**/*'

demos/basic-v16-rspack/app/javascript/src/HelloWorld/ror_components/HelloWorld.client.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useState } from 'react';
2+
23
import * as style from './HelloWorld.module.css';
34

45
const HelloWorld = (props) => {

demos/basic-v16-rspack/bin/switch-bundler

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ def load_dependencies
4545
dev: custom.dig("webpack", "devDependencies") || DEFAULT_WEBPACK_DEPS[:dev],
4646
prod: custom.dig("webpack", "dependencies") || DEFAULT_WEBPACK_DEPS[:prod]
4747
}
48-
[rspack_deps, webpack_deps]
48+
[ rspack_deps, webpack_deps ]
4949
else
50-
[DEFAULT_RSPACK_DEPS, DEFAULT_WEBPACK_DEPS]
50+
[ DEFAULT_RSPACK_DEPS, DEFAULT_WEBPACK_DEPS ]
5151
end
5252
end
5353
# rubocop:enable Metrics/MethodLength
5454

55+
# rubocop:disable Metrics/MethodLength
5556
def create_config_file
5657
if File.exist?(CUSTOM_DEPS_CONFIG)
5758
puts "⚠️ #{CUSTOM_DEPS_CONFIG} already exists"
@@ -76,6 +77,7 @@ def create_config_file
7677
puts "The script will automatically use these custom dependencies when switching bundlers."
7778
exit 0
7879
end
80+
# rubocop:enable Metrics/MethodLength
7981

8082
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity, Style/OptionalBooleanParameter, Metrics/BlockNesting
8183
def install_dependencies(bundler, install_deps, switching_bundlers = true)
@@ -158,7 +160,7 @@ def install_dependencies(bundler, install_deps, switching_bundlers = true)
158160
end
159161
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity, Style/OptionalBooleanParameter, Metrics/BlockNesting
160162

161-
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
163+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
162164
def switch_to(bundler, install_deps)
163165
unless %w[webpack rspack].include?(bundler)
164166
puts "❌ Invalid bundler: #{bundler}"
@@ -206,8 +208,9 @@ def switch_to(bundler, install_deps)
206208
puts "💡 Tip: Both webpack and rspack can coexist in package.json during migration"
207209
puts " Use --install-deps to automatically manage dependencies, or manage manually"
208210
end
209-
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength
211+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
210212

213+
# rubocop:disable Metrics/MethodLength
211214
def show_usage
212215
current = current_bundler
213216
puts "Current bundler: #{current}"

demos/basic-v16-rspack/config/environments/production.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } }
3434

3535
# Log to STDOUT with the current request id as a default log tag.
36-
config.log_tags = [:request_id]
36+
config.log_tags = [ :request_id ]
3737
config.logger = ActiveSupport::TaggedLogging.logger($stdout)
3838

3939
# Change to "debug" to log everything (including potentially personally-identifiable information!)
@@ -75,7 +75,7 @@
7575
config.active_record.dump_schema_after_migration = false
7676

7777
# Only use :id for inspections in production.
78-
config.active_record.attributes_for_inspect = [:id]
78+
config.active_record.attributes_for_inspect = [ :id ]
7979

8080
# Enable DNS rebinding protection and other `Host` header attacks.
8181
# config.hosts = [

demos/basic-v16-rspack/config/webpack/development.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// The source code including full typescript support is available at:
22
// https://github.com/shakacode/react_on_rails_demo_ssr_hmr/blob/master/config/webpack/development.js
33

4-
const { devServer, inliningCss, config } = require('shakapacker');
4+
const { devServer: _devServer, inliningCss: _inliningCss, config } = require('shakapacker');
55

66
const generateWebpackConfigs = require('./generateWebpackConfigs');
77

demos/basic-v16-rspack/config/webpack/serverWebpackConfig.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// The source code including full typescript support is available at:
22
// https://github.com/shakacode/react_on_rails_demo_ssr_hmr/blob/master/config/webpack/serverWebpackConfig.js
33

4-
const { merge, config } = require('shakapacker');
4+
const { merge: _merge, config } = require('shakapacker');
5+
56
const commonWebpackConfig = require('./commonWebpackConfig');
67

78
// Auto-detect bundler from shakapacker config and load the appropriate library

demos/basic-v16-rspack/config/webpack/webpack.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
const { env } = require('shakapacker')
21
const { existsSync } = require('fs')
32
const { resolve } = require('path')
43

4+
const { env } = require('shakapacker')
5+
56
const envSpecificConfig = () => {
67
const path = resolve(__dirname, `${env.nodeEnv}.js`)
78
if (existsSync(path)) {
8-
console.log(`Loading ENV specific webpack configuration file ${path}`)
9+
console.warn(`Loading ENV specific webpack configuration file ${path}`)
910
return require(path)
1011
} else {
1112
throw new Error(`Could not find file to load ${path}, based on NODE_ENV`)

0 commit comments

Comments
 (0)