Lint: Enforce no-new-public-enums policy via SwiftLint custom rule#6778
Merged
Conversation
Per company policy, no new `enum` types may be added to consumer-facing APIs (fully public + `@_spi(Experimental)`). This adds CI-level enforcement so the policy stops being just a guideline. Adds a `check_public_enums` Fastlane lane that consumes the `.private.swiftinterface` files emitted alongside the public ones, extracts every consumer-facing `enum` declaration, and diffs against an allowlist baseline file per scheme. Internal SPI is intentionally excluded. Wired into both `check-api-changes-revenuecat` and `check-api-changes-revenuecatui` CI jobs. Allowlists seeded from the currently-committed swiftinterface files (45 entries for RevenueCat, 3 for RevenueCatUI). To intentionally add a new consumer-facing enum (with API-council approval), regenerate the allowlist: bundle exec fastlane ios check_public_enums scheme:RevenueCat regenerate:true Co-authored-by: Cursor <cursoragent@cursor.com>
This reverts commit d671999.
Adds the `no_new_public_enums` custom SwiftLint rule that flags any new `public enum` declared in the SDK's consumer-facing surface, including `@_spi(Experimental)` APIs. Enums marked `@_spi(Internal)` on the same line as the declaration are exempt because they are not part of the consumer-facing surface. Existing public enums are grandfathered via `swiftlint-baseline.json`, which SwiftLint reads automatically through the `baseline:` key in `.swiftlint.yml`. Refactors that remove a baselined entry continue to pass; only NEW violations fail the build. New entries can be added by regenerating the baseline with `swiftlint lint --write-baseline swiftlint-baseline.json`, which requires an explicit, reviewable JSON change. This mirrors the approach taken on Android in RevenueCat/purchases-android#3503, which adds a custom detekt rule `ForbiddenPublicSealedClass` with the equivalent semantics for sealed classes/interfaces. Why: adding a case to an existing `public enum` is source-breaking for any consumer with an exhaustive `switch`. The policy avoids new public enums entirely; structs of static constants are the recommended alternative. `AGENTS.md` and the `Important Files` list are updated to document the new policy and the baseline file. Co-authored-by: Cursor <cursoragent@cursor.com>
Drops the `@_spi(Internal)` suggestion (not a real alternative when a public API is needed) and the baseline mention from the user-facing message. Regenerates `swiftlint-baseline.json` since SwiftLint baselines key off the violation message. Co-authored-by: Cursor <cursoragent@cursor.com>
Replaces the previous "lint everything except Tests/" approach with an explicit `included:` list of the actual SDK source roots: Sources/, RevenueCatUI/, and AdapterSDKs/RevenueCatAdMob/Sources/. Sample apps, backend integration tests, dev tooling, and similar non-SDK Swift files are no longer in scope for this rule. Coverage of the existing 56 grandfathered violations is unchanged. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
…o-new-public-enums
This was referenced Jun 3, 2026
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.
Checklist
purchases-androidand hybridsMotivation
Internal policy forbids new
public enumdeclarations in the SDK's consumer-facing surface (incl.@_spi(Experimental)): adding a case is source-breaking for any consumer with an exhaustiveswitch. Parallels purchases-android#3503.Description
New SwiftLint custom rule
no_new_public_enumsflags new public enums except those marked@_spi(Internal)on the same line. Pre-existing types are grandfathered inswiftlint-baseline.json.To intentionally accept a new violation, regenerate the baseline:
Note
Low Risk
Tooling and documentation only; no runtime SDK behavior changes.
Overview
Adds CI enforcement for the existing “no new
public enumon consumer-facing API” policy via a new SwiftLint custom ruleno_new_public_enums, scoped toSources/,RevenueCatUI/, and AdMob adapter sources. The rule errors onpublic enumdeclarations unless the declaration is immediately preceded by@_spi(Internal)on the same line.Wires
swiftlint-baseline.jsoninto.swiftlint.ymlso all current violations are grandfathered; new matches fail lint until someone intentionally regenerates the baseline withswiftlint lint --write-baseline swiftlint-baseline.json.AGENTS.mdis updated to document the rule, baseline workflow, and the@_spi(Internal)exemption alongside the existing API guidance.Reviewed by Cursor Bugbot for commit 02f835e. Bugbot is set up for automated code reviews on this repo. Configure here.