realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.67k stars 2.22k forks source link

Make type_contents_order to enable placement init() in SwiftUI views above computed properties #3548

Open michzio opened 3 years ago

michzio commented 3 years ago

I think for SwiftUI views such order should be supported by default Or there should be possibility to exclude some content types from ordering like only initializers to enable random placing.

struct MainTabView: View {

    @StateObject var tabState: TabState

    init(state: TabState) {
        _tabState = StateObject(wrappedValue: state)
    }

    var body: some View {
        TabView(selection: $tabState.selection) {
            DashboardView()
            ProfileView()
        }
    }
}
richellis commented 3 years ago

Perhaps a special case for var body: some View where import SwiftUI is present? Similar to how ibOutlet can be configured separately from instanceProperties.

For example, at my company we'd want something like this:

type_contents_order:
  order: [
    ["case"],
    ["type_alias", "associated_type", "subtype", "type_property", "instance_property"],
    ["ib_outlet"],
    ["ib_inspectable"],
    ["initializer", "deinitializer"],
    ["swiftui_body"],   # <-------- NEW
    ["type_method"],
    ["subscript"],
    ["view_life_cycle_method"],
    ["ib_action"],
    ["other_method"]
  ]
edorphy commented 3 years ago

Agreed, with SwiftUI taking off, and a natural evolution/upgrade to SwiftUI coming in WWDC around the corner, this would be a very timely update!

jonduenas commented 1 year ago

Any updates on this? This is a particularly annoying issue for my team. We like the rule and don’t want to disable it entirely, but having to mark our Views with disable comments every time is a bit annoying, especially since we have our scans set strict.

wellington-hirsch-zoop commented 2 months ago

Still no update?