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

redundant_optional_initialization removes opening bracket before property observer #3718

Closed
2 tasks done
maikasshoff opened this issue Sep 13, 2021 · 6 comments · Fixed by #3717
Closed
2 tasks done

Comments

@maikasshoff
Copy link

New Issue Checklist

Describe the bug

The redundant_optional_initialization rule removes the opening bracket before a property observer which causes a syntax issue. For example

var foo: String? = nil {
  didSet {
    print("foo")
  }
}

is changed to

var foo: String?
  didSet {
    print("foo")
  }
}
Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint       

Linting Swift files in current working directory
Linting 'Foo.swift' (1/1)
/Foo.swift:3:21: warning: Redundant Optional Initialization Violation: Initializing an optional variable with nil is redundant. (redundant_optional_initialization)
Done linting! Found 1 violation, 0 serious in 1 file.

Environment

$ swiftlint version
swiftlint version
0.44.0

@iressler

@iressler
Copy link
Contributor

Interesting, I assume you are actually running swiftlint lint --fix (or equivalent)?

I'll take a look at this when I get a chance, however I'm not familiar with how the autocorrect works. This may be a quick fix for someone familiar with it so if someone else wants to take a stab at it please do.

@naru-jpn
Copy link
Contributor

naru-jpn commented Sep 14, 2021

Hi, I found same problem and created PR to fix this issue :) #3717

@morluna
Copy link

morluna commented Sep 16, 2021

This is breaking our workflow since our development team uses the Homebrew installation of swiftlint for analysis 😔 Our workaround is to disable the rule for now, but a fix would be appreciated. Thanks @naru-jpn for the fix.

@BrunoVillanova-SaudeID
Copy link

Awaiting PR merge and release.

@maartenbusstra
Copy link

We ran into this issue as well. For good measure, we're turning off automatically fixing issues in CI, as the underlying project shouldn't change when publishing builds.

@ansonj
Copy link

ansonj commented Oct 19, 2021

In case anyone is watching this issue for updates, the 0.45.0 release includes the fix for this issue. Tested it, and looks good for me:
https://github.com/realm/SwiftLint/releases/tag/0.45.0

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 a pull request may close this issue.

7 participants