Rule Request: Disallow `NSApp.activate(ignoringOtherApps: true)` in `applicationDidFinishLaunching`
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
New rule request
Most macOS apps abuse this method. The problem is the ignoringOtherApps: true part. It means if you launch the app and then switch to a different app while it's launching, it will steal focus when it has finished launching. This is something that is hard to catch in development, but users gets annoyed by this behavior.
I propose reporting when NSApp.activate(ignoringOtherApps: true) is used inside applicationDidFinishLaunching. It's ok to use ignoringOtherApps: true in other situations. It's also ok to use NSApp.activate(ignoringOtherApps: false) inside applicationDidFinishLaunching.
Having this rule will hopefully make devs aware they're using the API incorrectly and fix their apps.
- Why should this rule be added? Share links to existing discussion about what
the community thinks about this.
Because it's a widespread problem that affects real users: https://twitter.com/sindresorhus/status/1085002325511426051
- Provide several examples of what would and wouldn't trigger violations.
Would trigger:
@NSApplicationMain
final class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
NSApp.activate(ignoringOtherApps: true)
}
}
Would not trigger:
@NSApplicationMain
final class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
NSApp.activate(ignoringOtherApps: false)
}
}
@NSApplicationMain
final class AppDelegate: NSObject, NSApplicationDelegate {
func foo() {
NSApp.activate(ignoringOtherApps: true)
}
}
- Should the rule be configurable, if so what parameters should be configurable?
No.
- Should the rule be opt-in or enabled by default? Why?
See README.md for guidelines on when to mark a rule as opt-in.
Enabled by default.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with README.md's opt-in-rules guidance and review SwiftLint's existing rule and test conventions, since this issue does not name implementation files or tests. Done means reporting only true activation inside applicationDidFinishLaunching, while allowing false activation there and true activation elsewhere, with coverage for the supplied examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100