Skip to content

Warn on unrecognized keys in target dictionaries - #1660

Open
FawwazLawal wants to merge 2 commits into
yonaskolb:masterfrom
FawwazLawal:fix/1645-unrecognized-target-key-warning
Open

FawwazLawal wants to merge 2 commits into
yonaskolb:masterfrom
FawwazLawal:fix/1645-unrecognized-target-key-warning

Conversation

@FawwazLawal

@FawwazLawal FawwazLawal commented Oct 23, 2026 •

Copy link
Copy Markdown

Summary

Target.init(name:jsonDictionary:) silently ignores unknown keys, so a typo like resources instead of sources produces no output and no error. This adds a validation warning that names the target and the unrecognized key.

A new Target.recognizedKeys set (32 keys, including platformPrefix and platformSuffix read at Target.swift:217-218) is checked in SpecLoader.validateWarnings(). Unrecognized keys produce a SpecValidationError.unrecognizedTargetKey warning that lists the valid keys inline, so the fix is in the message itself:

Target "MyApp" has unrecognized key "resources". Valid target keys are: attributes, buildRules, buildToolPlugins, configFiles, dependencies, deploymentTarget, directlyEmbedCarthageDependencies, entitlements, info, isMultiPlatformTarget, legacy, name, onlyCopyFilesOnInstall, platform, platformPrefix, platformSuffix, postBuildScripts, postCompileScripts, postbuildScripts, preBuildScripts, prebuildScripts, productName, putResourcesBeforeSourcesBuildPhase, requiresObjCLinking, scheme, settings, sources, supportedDestinations, templateAttributes, templates, transitivelyLinkDependencies, type

Target and key iteration are sorted, so a spec with several typos emits warnings in a stable order across runs.

Reproduction

A target spec that lists files under a top-level resources: key rather than under sources: is accepted silently and leaves the project without those files.

project.yml:

name: Demo
targets:
  Demo:
    type: application
    platform: iOS
    sources:
      - path: Sources/App
      - path: Sources/Models
    resources:
      - path: Resources
xcodegen generate
grep -c config.plist Demo.xcodeproj/project.pbxproj
grep -q PBXResourcesBuildPhase Demo.xcodeproj/project.pbxproj && echo present || echo ABSENT

Against XcodeGen 2.45.3:

0
ABSENT

Moving the Resources directory under sources: on the same files, with nothing else changed, produces 4 and present. The four lines are the file's PBXBuildFile, PBXFileReference, group listing and build-phase listing, not four copies. Both runs are silent, exit 0.

With this change the same spec still generates and names the unrecognized key:

Spec validation error: Target "Demo" has unrecognized key "resources". Valid target keys are: attributes, buildRules, ... type
xcodegen output: Spec validation error warning naming the resources key, then plists/project/write succeed, exit 0, grep returns 0

This PR applied to the broken spec: warning above, generation proceeds, exit 0. Count stays 0; the fix surfaces the discarded key, it does not include the file.

Generation continues and exits 0. validateWarnings() was an existing stub in SpecLoader with a hard-coded empty array, and GenerateCommand already caught any thrown error and routed it to warning(). The change populates that channel; it does not add a new abort path.

Tests cover both the warning case and the clean-spec case. CHANGELOG entry added.

 5 files changed, 85 insertions(+), 1 deletion(-)

Local runs: xcrun swift test on macOS exits 0, 246 tests across 5 xctest bundles, 0 failures; swift test --enable-test-discovery in swift:6.1-noble on Linux exits 0, 82 tests, 6 skipped, 0 failures.

Resolves #1645

Adds a validation warning when a target dictionary contains keys not in
Target.recognizedKeys, helping catch typos like `resources` instead of
`sources`.

Resolves yonaskolb#1645
@barissalihbabacan

Copy link
Copy Markdown

@yonaskolb gentle ping to review this PR addressing #1645 when you get a chance.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unrecognized target keys (e.g. resources:) are silently ignored — should warn

2 participants