@kamaal111/kamaal-quality-config 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/package.json +1 -1
- package/swift/SwiftLintChecks/Sources/SwiftLintChecks/LintViolation.swift +3 -0
- package/swift/SwiftLintChecks/Sources/SwiftLintChecks/PrivateSetterAccessVisitor.swift +14 -0
- package/swift/SwiftLintChecks/Sources/SwiftLintChecks/SwiftLint.swift +7 -1
- package/swift/SwiftLintChecks/Tests/SwiftLintChecksTests/PrivateSetterAccessTests.swift +33 -0
package/README.md
CHANGED
|
@@ -210,12 +210,15 @@ Without paths, the command checks the current directory recursively. Explicit fi
|
|
|
210
210
|
paths are relative to your working directory. Recursive scanning skips hidden paths (including
|
|
211
211
|
`.build`), `node_modules`, symlinks, and non-Swift files. Use `--` before paths starting with a dash.
|
|
212
212
|
|
|
213
|
-
All
|
|
213
|
+
All six checks run whenever you invoke `kqc swift-lint`:
|
|
214
214
|
|
|
215
215
|
- `member_spacing`: separate methods and initializers from adjacent members with a blank line.
|
|
216
216
|
- `multiline_chain_spacing`: put each chained call on its own line in multiline expressions.
|
|
217
217
|
- `view_body_declarations`: move local `let` and `var` declarations out of SwiftUI
|
|
218
218
|
`var body: some View`, including nested builder closures. Conditional bindings remain allowed.
|
|
219
|
+
- `private_setter_access`: require `private(set)` wherever a setter has explicit access control.
|
|
220
|
+
For example, `public internal(set) var value` reports `internal`. Both `public var value` and
|
|
221
|
+
`public private(set) var value` pass the check.
|
|
219
222
|
- `no_nested_do_catch`: reject a `do/catch` nested anywhere in another `do/catch`,
|
|
220
223
|
including its catch clauses. Plain `do` blocks do not count, but do not hide nesting.
|
|
221
224
|
Functions, closures, initializers, accessors, and nested types start independent scopes;
|
package/package.json
CHANGED
|
@@ -9,6 +9,7 @@ enum LintRule: String {
|
|
|
9
9
|
case memberSpacing = "member_spacing"
|
|
10
10
|
case multilineChainSpacing = "multiline_chain_spacing"
|
|
11
11
|
case noNestedDoCatch = "no_nested_do_catch"
|
|
12
|
+
case privateSetterAccess = "private_setter_access"
|
|
12
13
|
case singleTryPerDoCatch = "single_try_per_do_catch"
|
|
13
14
|
case viewBodyDeclarations = "view_body_declarations"
|
|
14
15
|
|
|
@@ -20,6 +21,8 @@ enum LintRule: String {
|
|
|
20
21
|
"Place each chained call on its own line in a multiline expression."
|
|
21
22
|
case .noNestedDoCatch:
|
|
22
23
|
"Avoid nested do/catch statements. Extract error handling into a helper or use sequential do/catch blocks."
|
|
24
|
+
case .privateSetterAccess:
|
|
25
|
+
"Use private(set) for explicit setter access."
|
|
23
26
|
case .singleTryPerDoCatch:
|
|
24
27
|
"""
|
|
25
28
|
Keep at most one plain try expression in each do/catch body. \
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import SwiftSyntax
|
|
2
|
+
|
|
3
|
+
final class PrivateSetterAccessVisitor: SyntaxVisitor {
|
|
4
|
+
private(set) var violations: [LintViolation] = []
|
|
5
|
+
|
|
6
|
+
override func visit(_ node: DeclModifierSyntax) -> SyntaxVisitorContinueKind {
|
|
7
|
+
if node.detail?.detail.text == "set", node.name.tokenKind != .keyword(.private) {
|
|
8
|
+
violations.append(
|
|
9
|
+
LintViolation(position: node.name.positionAfterSkippingLeadingTrivia, rule: .privateSetterAccess)
|
|
10
|
+
)
|
|
11
|
+
}
|
|
12
|
+
return .visitChildren
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -18,7 +18,13 @@ enum SwiftLint {
|
|
|
18
18
|
tries.walk(tree)
|
|
19
19
|
let handlers = NoNestedDoCatchVisitor(viewMode: .sourceAccurate)
|
|
20
20
|
handlers.walk(tree)
|
|
21
|
-
|
|
21
|
+
let setters = PrivateSetterAccessVisitor(viewMode: .sourceAccurate)
|
|
22
|
+
setters.walk(tree)
|
|
23
|
+
let violations =
|
|
24
|
+
visitor.violations + chains.violations + bodies.violations + tries.violations
|
|
25
|
+
+ handlers.violations + setters.violations
|
|
26
|
+
return
|
|
27
|
+
violations
|
|
22
28
|
.sorted { $0.position < $1.position }
|
|
23
29
|
.map { violation in
|
|
24
30
|
let location = converter.location(for: violation.position)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import Testing
|
|
2
|
+
|
|
3
|
+
@testable import SwiftLintChecks
|
|
4
|
+
|
|
5
|
+
struct PrivateSetterAccessTests {
|
|
6
|
+
@Test(arguments: ["fileprivate", "internal", "package"])
|
|
7
|
+
func `Reports the explicit setter modifier`(access: String) {
|
|
8
|
+
let source = """
|
|
9
|
+
public struct Example {
|
|
10
|
+
public \(access)(set) var value = 1
|
|
11
|
+
}
|
|
12
|
+
"""
|
|
13
|
+
let diagnostics = SwiftLint.diagnostics(source: source, path: "Example.swift")
|
|
14
|
+
#expect(
|
|
15
|
+
diagnostics == [
|
|
16
|
+
"Example.swift:2:12: error: Use private(set) for explicit setter access. [private_setter_access]"
|
|
17
|
+
]
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Test
|
|
22
|
+
func `Allows private setters and declarations without setter modifiers`() {
|
|
23
|
+
let source = """
|
|
24
|
+
public struct Example {
|
|
25
|
+
public private(set) var restricted = 1
|
|
26
|
+
public var unrestricted = 2
|
|
27
|
+
private var hidden = 3
|
|
28
|
+
}
|
|
29
|
+
"""
|
|
30
|
+
let diagnostics = SwiftLint.diagnostics(source: source, path: "Example.swift")
|
|
31
|
+
#expect(diagnostics.isEmpty)
|
|
32
|
+
}
|
|
33
|
+
}
|