Repository navigation
Warn when a target contains an unrecognized YAML key - #1661
Open
SwastikTripathi wants to merge 1 commit into
Open
SwastikTripathi wants to merge 1 commit into
SwastikTripathi wants to merge 1 commit into
Conversation
`Target.init(jsonDictionary:)` silently ignores any top-level key that it does not recognise. This makes it very easy to misplace valid fields (e.g. writing `resources:` instead of adding a source entry with `buildPhase: resources`) and get a project that generates successfully but is simply missing resources at runtime, with no diagnostic of any kind. Add `Target.validYAMLKeys` — the exhaustive set of top-level keys that Target parsing understands — and extend `validateProjectDictionaryWarnings` to surface any key outside that set as a `SpecValidationError`. The warning is printed by the `generate` command before the project file is written, giving users an early signal that a key will be ignored. Fixes yonaskolb#1645 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
SwastikTripathi
force-pushed
the
warn-unknown-target-keys
branch
from
October 25, 2026 05:39
3191ad0 to
843d967
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
Target.init(jsonDictionary:)silently ignores any top-level key it does not recognise. This creates a particularly nasty failure mode: writingresources:under a target (which is not a valid Target key, resources must be specified as source entries withbuildPhase: resources) causesxcodegen generateto exit 0 with no warning, the project builds, but resource files are simply missing from the app bundle at runtime. The issue is only surfaced as a crash on launch (e.g.Could not locate configuration file: 'GoogleService-Info.plist').Reported in #1645.
Changes
Target.validYAMLKeys, a new staticSet<String>onTargetlisting every top-level YAML key that the parser recognises (fromnamethroughputResourcesBeforeSourcesBuildPhase, plus the template-relatedtemplates/templateAttributeskeys that are consumed beforeTarget.initis called).SpecValidationError.ValidationError.unknownTargetKey, a new error case emitted for each unrecognised key.SpecLoader.validateProjectDictionaryWarnings, extended to iterate over the raw project dictionary'stargetsand emit anunknownTargetKeywarning for any key not inTarget.validYAMLKeys. Thegeneratecommand already calls this and prints each error as a warning before writing the project file.Test,
testSpecWarningValidationgains a new case that creates a target withresources: ["Resources"], callsvalidateProjectDictionaryWarnings, and asserts that the expectedunknownTargetKey(target: "App", key: "resources")error is present.Example output
🤖 Generated with Claude Code