Skip to content

Add acronym visibility controls - #2724

Merged
nicklockwood merged 1 commit into
developfrom
acronym-visibiity
Oct 3, 2026
Merged

nicklockwood merged 1 commit into
developfrom
acronym-visibiity

Conversation

@nicklockwood

Copy link
Copy Markdown
Owner

This PR extends the acronyms rule with an --acronym-visibility option to control the visibility level of symbols to be renamed. This was inspired by the similar --typo-visibility option in the commonTypos rule.

@calda I defaulted this to internal to match the existing behavior of the rule, but do you think it would be better to make it fileprivate, then the rule could safely be enabled by default?

@nicklockwood
nicklockwood requested a review from calda October 2, 2026 22:35
@calda

calda commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

I don't think we should enable the rule by default, having a mixture of acronym capitalizations in a single file isn't a great situation

@calda calda left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

/// Whether renaming this declaration cannot affect a public or serialized API contract.
func declarationCanBeRenamed(
_ declaration: Declaration,
upTo maximumVisibility: Visibility?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a single --rename-visbility option across all rules instead of one each?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be problematic if we are planning to give them different defaults

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially we could add a context-dependent "default" case to the enum, then each rule could interpret that as it chooses, but I think that might be more confusing than what we have now

@codecov

codecov Bot commented Oct 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.58%. Comparing base (57e69e1) to head (0132e1b).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2724      +/-   ##
===========================================
+ Coverage    95.56%   95.58%   +0.02%     
===========================================
  Files          185      185              
  Lines        28810    28882      +72     
===========================================
+ Hits         27532    27608      +76     
+ Misses        1278     1274       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rgoldberg

Copy link
Copy Markdown

Should the options be made self documenting by being renamed to --acronym-max-visibility & --typo-max-visibility?

That also allows for possible future --*-min-visibility.

@nicklockwood

Copy link
Copy Markdown
Owner Author

@rgoldberg how would min-visibility be applied?

@nicklockwood
nicklockwood merged commit d7a2591 into develop Oct 3, 2026
16 checks passed
@nicklockwood
nicklockwood deleted the acronym-visibiity branch October 3, 2026 07:49
@rgoldberg

rgoldberg commented Oct 3, 2026 •

Copy link
Copy Markdown

@nicklockwood I haven't looked through the implementation, but it would seem to me that keeping acronym naming consistent and/or avoiding typos is more important the more visible something is, because more people will look at public symbols than private symbols.

I could understand limiting symbol renaming only at a public level because you want to ensure a public API is clean, but maybe you deal with third-party APIs that don't follow your naming conventions at internal or lower visibility, and you want to align your symbols with the third-party symbols without exposing them to the public.

I thus wasn't sure which end the options limited until I checked their documentation.

The primary purpose is self-documentation, but it also allows the easy adoption of min values in the future, too. Maybe in some circumstances min or max won't make sense, but standardizing across all options makes all
Self-documenting & allows for future expansion everywhere while maintaining consistency.

@nicklockwood

Copy link
Copy Markdown
Owner Author

@rgoldberg I'm inclined to leave it as-is for now, but it's not a big problem to rename it and deprecate the old name in future if the need arises

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.

3 participants