fix: Sanitize class names in ObjC generator to allow dashes (fixes #23) #64
+6
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Title
fix: Sanitize project names in iOS generators to support dashes
Description
This PR fixes Issue #23 where project names containing dashes (e.g.,
my-app) caused build failures in the generated iOS code.The Problem
Objective-C class names cannot contain hyphens. When the Valdi CLI generates a project with a dash in the name, the compiler currently injects the raw string into
@classand@interfacedeclarations (e.g.,test-valdiAppComponent), which causes syntax errors during the Xcode build process.The Fix
I updated the iOS generator files to sanitize class names before they are written to the output files. I added
.replacingOccurrences(of: "-", with: "_")in the following files to ensure valid Objective-C syntax:compiler/compiler/Compiler/Sources/Generation/ObjC/ObjCCodeGenerator.swiftcompiler/compiler/Compiler/Sources/Template/ObjCViewClassGenerator.swiftcompiler/compiler/Compiler/Sources/ViewModels/ObjCModelGenerator.swiftWith these changes, a project named
my-appwill correctly generate class names using underscores (e.g.,my_appAppComponent) instead of dashes.Related Issue
Fixes #23
Type of Change
Test Plan
Note on Environment: I am contributing from a Linux (WSL) environment and do not have access to Xcode to run the full
valdi install iosbuild.I verified the fix in the following ways:
replacingOccurrences) via a standalone Swift script to confirm it correctly converts kebab-case strings to snake_case.swift testlocally, but I encountered unrelated dependency issues on Linux (specifically inside theZiplibrary, which seems to have strict typing issues on WSL). Since my changes are strictly limited to string sanitization in the iOS generators, I am relying on the CI (GitHub Actions) to verify that the full test suite passes on macOS.Checklist