Skip to content

Commit

Permalink
Add ability to organize declarations by type over visibility (#1678)
Browse files Browse the repository at this point in the history
  • Loading branch information
oiuhr authored and nicklockwood committed Jun 11, 2024
1 parent 8cffd92 commit 89bfc69
Show file tree
Hide file tree
Showing 8 changed files with 795 additions and 167 deletions.
44 changes: 44 additions & 0 deletions Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -1364,10 +1364,13 @@ Option | Description
`--classthreshold` | Minimum line count to organize class body. Defaults to 0
`--enumthreshold` | Minimum line count to organize enum body. Defaults to 0
`--extensionlength` | Minimum line count to organize extension body. Defaults to 0
`--organizationmode` | Organize declarations by "visibility" (default) or "type"

<details>
<summary>Examples</summary>

`--organizationmode visibility` (default)

```diff
public class Foo {
- public func c() -> String {}
Expand Down Expand Up @@ -1411,6 +1414,47 @@ Option | Description
}
```

`--organizationmode type`

```diff
public class Foo {
- public func c() -> String {}
-
- public let a: Int = 1
- private let g: Int = 2
- let e: Int = 2
- public let b: Int = 3
-
- public func d() {}
- func f() {}
- init() {}
- deinit() {}
}

public class Foo {
+
+ // MARK: Properties
+
+ public let a: Int = 1
+ public let b: Int = 3
+
+ let e: Int = 2
+
+ private let g: Int = 2
+
+ // MARK: Lifecycle
+
+ init() {}
+ deinit() {}
+
+ // MARK: Functions
+
+ public func c() -> String {}
+ public func d() {}
+
}
```

</details>
<br/>

Expand Down
43 changes: 43 additions & 0 deletions Sources/Examples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,8 @@ private struct Examples {
"""

let organizeDeclarations = """
`--organizationmode visibility` (default)
```diff
public class Foo {
- public func c() -> String {}
Expand Down Expand Up @@ -1319,6 +1321,47 @@ private struct Examples {
+
}
```
`--organizationmode type`
```diff
public class Foo {
- public func c() -> String {}
-
- public let a: Int = 1
- private let g: Int = 2
- let e: Int = 2
- public let b: Int = 3
-
- public func d() {}
- func f() {}
- init() {}
- deinit() {}
}
public class Foo {
+
+ // MARK: Properties
+
+ public let a: Int = 1
+ public let b: Int = 3
+
+ let e: Int = 2
+
+ private let g: Int = 2
+
+ // MARK: Lifecycle
+
+ init() {}
+ deinit() {}
+
+ // MARK: Functions
+
+ public func c() -> String {}
+ public func d() {}
+
}
```
"""

let extensionAccessControl = """
Expand Down
Loading

0 comments on commit 89bfc69

Please sign in to comment.