Skip to content

Commit 88c07dd

Browse files
justin808claude
andcommitted
Fix TypeScript generator tests and lint issues
- Fix RuboCop guard clause violation in install_generator.rb - Add missing create_typescript_config method call for --typescript flag - Fix indentation and syntax issues from RuboCop auto-correct - Change TypeScript Redux template to use interface instead of type alias to match test expectations All generator tests now pass and lint is clean. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent f9ef839 commit 88c07dd

File tree

2 files changed

+64
-63
lines changed

2 files changed

+64
-63
lines changed

lib/generators/react_on_rails/install_generator.rb

Lines changed: 63 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def invoke_generators
6969
if options.typescript?
7070
install_typescript_dependencies
7171
create_css_module_types
72+
create_typescript_config
7273
end
7374
invoke "react_on_rails:base", [], { typescript: options.typescript? }
7475
if options.redux?
@@ -330,80 +331,80 @@ def install_typescript_dependencies
330331

331332
# Fallback to npm if GeneratorHelper fails
332333
success = run "npm install --save-dev #{typescript_packages.join(' ')}"
333-
unless success
334-
warning = <<~MSG.strip
335-
⚠️ Failed to install TypeScript dependencies automatically.
336-
337-
Please run manually:
338-
npm install --save-dev #{typescript_packages.join(' ')}
339-
MSG
340-
GeneratorMessages.add_warning(warning)
341-
end
342-
end
334+
return if success
343335

344-
def create_css_module_types
345-
puts Rainbow("📝 Creating CSS module type definitions...").yellow
336+
warning = <<~MSG.strip
337+
⚠️ Failed to install TypeScript dependencies automatically.
346338
347-
# Ensure the types directory exists
348-
FileUtils.mkdir_p("app/javascript/types")
339+
Please run manually:
340+
npm install --save-dev #{typescript_packages.join(' ')}
341+
MSG
342+
GeneratorMessages.add_warning(warning)
343+
end
344+
end
349345

350-
css_module_types_content = <<~TS.strip
351-
// TypeScript definitions for CSS modules
352-
declare module "*.module.css" {
353-
const classes: { [key: string]: string };
354-
export default classes;
355-
}
346+
def create_css_module_types
347+
puts Rainbow("📝 Creating CSS module type definitions...").yellow
356348

357-
declare module "*.module.scss" {
358-
const classes: { [key: string]: string };
359-
export default classes;
360-
}
349+
# Ensure the types directory exists
350+
FileUtils.mkdir_p("app/javascript/types")
361351

362-
declare module "*.module.sass" {
363-
const classes: { [key: string]: string };
364-
export default classes;
365-
}
366-
TS
352+
css_module_types_content = <<~TS.strip
353+
// TypeScript definitions for CSS modules
354+
declare module "*.module.css" {
355+
const classes: { [key: string]: string };
356+
export default classes;
357+
}
367358
368-
File.write("app/javascript/types/css-modules.d.ts", css_module_types_content)
369-
puts Rainbow("✅ Created CSS module type definitions").green
370-
end
359+
declare module "*.module.scss" {
360+
const classes: { [key: string]: string };
361+
export default classes;
362+
}
371363
372-
def create_typescript_config
373-
tsconfig_content = {
374-
"compilerOptions" => {
375-
"target" => "es2018",
376-
"lib" => ["dom", "dom.iterable", "es6"],
377-
"allowJs" => true,
378-
"skipLibCheck" => true,
379-
"esModuleInterop" => true,
380-
"allowSyntheticDefaultImports" => true,
381-
"strict" => true,
382-
"forceConsistentCasingInFileNames" => true,
383-
"noFallthroughCasesInSwitch" => true,
384-
"module" => "esnext",
385-
"moduleResolution" => "node",
386-
"resolveJsonModule" => true,
387-
"isolatedModules" => true,
388-
"noEmit" => true,
389-
"jsx" => "react-jsx"
390-
},
391-
"include" => [
392-
"app/javascript/**/*"
393-
],
394-
"exclude" => [
395-
"node_modules"
396-
]
364+
declare module "*.module.sass" {
365+
const classes: { [key: string]: string };
366+
export default classes;
397367
}
368+
TS
398369

399-
File.write("tsconfig.json", JSON.pretty_generate(tsconfig_content))
400-
puts Rainbow("✅ Created tsconfig.json").green
401-
end
370+
File.write("app/javascript/types/css-modules.d.ts", css_module_types_content)
371+
puts Rainbow("✅ Created CSS module type definitions").green
372+
end
402373

403-
# Removed: Shakapacker auto-installation logic (now explicit dependency)
374+
def create_typescript_config
375+
tsconfig_content = {
376+
"compilerOptions" => {
377+
"target" => "es2018",
378+
"lib" => ["dom", "dom.iterable", "es6"],
379+
"allowJs" => true,
380+
"skipLibCheck" => true,
381+
"esModuleInterop" => true,
382+
"allowSyntheticDefaultImports" => true,
383+
"strict" => true,
384+
"forceConsistentCasingInFileNames" => true,
385+
"noFallthroughCasesInSwitch" => true,
386+
"module" => "esnext",
387+
"moduleResolution" => "node",
388+
"resolveJsonModule" => true,
389+
"isolatedModules" => true,
390+
"noEmit" => true,
391+
"jsx" => "react-jsx"
392+
},
393+
"include" => [
394+
"app/javascript/**/*"
395+
],
396+
"exclude" => [
397+
"node_modules"
398+
]
399+
}
404400

405-
# Removed: Shakapacker 8+ is now required as explicit dependency
401+
File.write("tsconfig.json", JSON.pretty_generate(tsconfig_content))
402+
puts Rainbow("✅ Created tsconfig.json").green
406403
end
404+
405+
# Removed: Shakapacker auto-installation logic (now explicit dependency)
406+
407+
# Removed: Shakapacker 8+ is now required as explicit dependency
407408
# rubocop:enable Metrics/ClassLength
408409
end
409410
end

lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/startup/HelloWorldApp.client.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import configureStore, { RailsProps } from '../store/helloWorldStore';
55
import HelloWorldContainer from '../containers/HelloWorldContainer';
66

77
// Props interface matches what Rails will pass from the controller
8-
type HelloWorldAppProps = RailsProps;
8+
interface HelloWorldAppProps extends RailsProps {}
99

1010
// See documentation for https://github.com/reactjs/react-redux.
1111
// This is how you get props from the Rails view into the redux store.

0 commit comments

Comments
 (0)