Skip to content

Add Danger check for @UserDefaultsWrapper additions#18

Merged
ayoy merged 5 commits intomainfrom
dominik/user-defaults-wrapper
Jan 26, 2026
Merged

Add Danger check for @UserDefaultsWrapper additions#18
ayoy merged 5 commits intomainfrom
dominik/user-defaults-wrapper

Conversation

@ayoy
Copy link
Copy Markdown
Contributor

@ayoy ayoy commented May 19, 2025

Task URL: https://app.asana.com/1/137249556945/project/1201037661562251/task/1210321655252710?focus=true


Note

Introduces a CI check to prevent new @UserDefaultsWrapper definitions in Swift diffs.

  • New userDefaultsWrapper rule scans added lines in .swift files and fails on @UserDefaultsWrapper annotations (handles parameterized, multiline, and no-parameter forms; ignores comments and non-definition usage)
  • Integrated the rule into the default Danger run in allPRs.ts
  • Added tests covering pass/fail scenarios for various annotation patterns
  • Minor cleanup: removed redundant early-return in singletons()

Written by Cursor Bugbot for commit fd7fdc7. This will update automatically on new commits. Configure here.

@samsymons samsymons self-requested a review May 20, 2025 01:01
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Comment thread org/allPRs.ts
for (const file of changedFiles) {
let diff = await danger.git.diffForFile(file);
let addedLines = diff?.added.split(/\n/);
const foundOccurrence = addedLines?.find(value => /^\+(?!\s*\/\/)\s*@UserDefaultsWrapper(?:\((?:.*\))?)?$/.test(value));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Regex misses single-line property wrapper declarations

Medium Severity

The regex /^\+(?!\s*\/\/)\s*@UserDefaultsWrapper(?:\((?:.*\))?)?$/ requires @UserDefaultsWrapper to be at the end of the line due to the $ anchor. This means valid Swift declarations where the wrapper and property are on the same line (e.g., @UserDefaultsWrapper var myProperty: Bool or @UserDefaultsWrapper(key: .foo) var myProperty: Bool) won't be detected. Developers could bypass the check by using single-line syntax instead of placing the attribute on its own line.


Please tell me if this was useful or not with a 👍 or 👎.

Fix in Cursor Fix in Web

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is enough for now, we only use UserDefaultsWrapper on a separate line.

@ayoy ayoy merged commit b6f233c into main Jan 26, 2026
2 checks passed
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.

2 participants