-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add Force Unwrapping Rule to SwiftLint #1749
Add Force Unwrapping Rule to SwiftLint #1749
Conversation
As far as I know, this is in a separate repository. Abe has already fixed the issue, but we need to create another release. |
I can do a release and update the version in CE first thing tomorrow morning. |
Looks like there's a ton of new lint errors from force unwrapping. Is it possible to write some custom rules so that we don't have to disable the linter for specific lines? For example in cases like this where we know a value already exists: private var abc = URL("")! |
f14a0f8
There are still some errors regarding linting |
I left the force unwraps in place because I wasn't certain if removing them would break the code. Additionally, I avoided using |
How do we want to proceed here then? Do we merge this and fix it later? I don't think that is a good idea, because then we'd have to check what SwiftLint logs exactly to before we merge (Because it will say the check failed) |
I've added |
As for the CI failures, I'm not sure about those warnings. I can't see them on my local machine. |
@activcoding I'll try to take a look tonight |
Do we have plans to remove these |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO there are to much swiftlint:disable comments, this should be reduced to the bare minimum required.
if let bundlePath = Bundle.main.path(forResource: "Package", ofType: "resolved") { | ||
let jsonData = try String(contentsOfFile: bundlePath).data(using: .utf8) | ||
// swiftlint:disable:next force_unwrapping | ||
let parsedJSON = try JSONDecoder().decode(AcknowledgementObject.self, from: jsonData!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a guard let, or if let.
There is no need to force unwap this.
if let bundlePath = Bundle.main.path(forResource: "Package", ofType: "resolved") { | |
let jsonData = try String(contentsOfFile: bundlePath).data(using: .utf8) | |
// swiftlint:disable:next force_unwrapping | |
let parsedJSON = try JSONDecoder().decode(AcknowledgementObject.self, from: jsonData!) | |
if let bundlePath = Bundle.main.path(forResource: "Package", ofType: "resolved"), | |
let jsonData = try String(contentsOfFile: bundlePath).data(using: .utf8) { | |
let parsedJSON = try JSONDecoder().decode(AcknowledgementObject.self, from: jsonData) |
@@ -131,6 +131,7 @@ class EditorManager: ObservableObject { | |||
if activeEditorHistory.isEmpty { | |||
activeEditor = findSomeEditor(excluding: editor) | |||
} else { | |||
// swiftlint:disable:next force_unwrapping | |||
activeEditor = activeEditorHistory.removeFirst()()! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is ()()
correct?
let window = NSApp.windows.first { $0.identifier?.rawValue == SceneID.settings.rawValue }! | ||
window.titlebarAppearsTransparent = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't something like this work?
let window = NSApp.windows.first { $0.identifier?.rawValue == SceneID.settings.rawValue }! | |
window.titlebarAppearsTransparent = true | |
NSApp.windows.first { $0.identifier?.rawValue == SceneID.settings.rawValue }?.titlebarAppearsTransparent = true |
In my experience, without adding swiftlint:disable to every force unwrap, no one will bother to remove them. For the proposed changes, could you open a PR and fix some instances of force unwrapping? |
Can you fix the merge conflicts? then I can add some fixes to this PR. |
Description
In PR #1673, we agreed on adding a force unwrapping rule to SwiftLint to improve our code quality across the project. Although this addition is not directly related to the original request in #1673, implementing this rule will help us write cleaner and safer code.
In this PR, I have:
If you come across a file you have worked on or will be working on, please take a moment to fix any linter warnings you encounter. This doesn't need to be done immediately, but can be addressed gradually over time.
Related Issues
Checklist
Screenshots