Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive in unneeded_synthesized_initializer #5075

Closed
2 tasks done
ZevEisenberg opened this issue Jun 22, 2023 · 2 comments · Fixed by #5076
Closed
2 tasks done

False positive in unneeded_synthesized_initializer #5075

ZevEisenberg opened this issue Jun 22, 2023 · 2 comments · Fixed by #5076
Assignees
Labels
bug Unexpected and reproducible misbehavior.

Comments

@ZevEisenberg
Copy link
Contributor

New Issue Checklist

Describe the bug

unneeded_synthesized_initializer reports a false positive when the init has side effects. In the attached sample, the init prints something, and removing it would remove the print. In the example where I encountered it in a real app, a SwiftUI view modifier's init contained a call to UIScrollView.appearance().bounces = false, which we definitely don't want to lose by deleting the init!

Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint
Linting Swift files in current working directory
Linting 'InitTest.swift' (1/1)
/Users/igeek/Downloads/InitTest/InitTest.swift:2:5: warning: Unneeded Synthesized Initializer Violation: This default initializer would be synthesized automatically - you do not need to define it (unneeded_synthesized_initializer)
Done linting! Found 1 violation, 0 serious in 1 file.

Environment

  • SwiftLint version: 0.52.3
  • Installation method used: homebrew
  • Paste your configuration file: n/a (default configuration)
  • Are you using nested configurations? No
  • Which Xcode version are you using? Xcode 14.3.1 (14E300c) on macOS 13.4.1 (22F82)
  • Do you have a sample that shows the issue? Run echo "[string here]" | swiftlint lint --no-cache --use-stdin --enable-all-rules
    to quickly test if your example is really demonstrating the issue. If your example is more
    complex, you can use swiftlint lint --path [file here] --no-cache --enable-all-rules.
struct MyStruct {
    init() {
        print("perform side effect")
    }
}
@mildm8nnered
Copy link
Collaborator

interesting - taking a look shortly

mildm8nnered added a commit to mildm8nnered/SwiftLint that referenced this issue Jun 22, 2023
@SimplyDanny SimplyDanny added the bug Unexpected and reproducible misbehavior. label Jun 23, 2023
@ZevEisenberg
Copy link
Contributor Author

Quick work! Thank you @mildm8nnered!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected and reproducible misbehavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants