mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
Ignore function, initializer and subscript declarations alike (#6242)
This commit is contained in:
+4
-1
@@ -16,7 +16,10 @@
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* None.
|
||||
* Ignore function, initializer and subscript declarations alike when the
|
||||
`ignores_function_declarations` option is enabled in the `line_length` rule.
|
||||
[SimplyDanny](https://github.com/SimplyDanny)
|
||||
[#6241](https://github.com/realm/SwiftLint/issues/6241)
|
||||
|
||||
## 0.61.0: Even Fresher Breeze
|
||||
|
||||
|
||||
@@ -147,6 +147,18 @@ private final class FunctionLineVisitor: SyntaxVisitor {
|
||||
}
|
||||
|
||||
override func visitPost(_ node: FunctionDeclSyntax) {
|
||||
collectLines(from: node)
|
||||
}
|
||||
|
||||
override func visitPost(_ node: InitializerDeclSyntax) {
|
||||
collectLines(from: node)
|
||||
}
|
||||
|
||||
override func visitPost(_ node: SubscriptDeclSyntax) {
|
||||
collectLines(from: node)
|
||||
}
|
||||
|
||||
private func collectLines(from node: any SyntaxProtocol) {
|
||||
let startLocation = locationConverter.location(for: node.positionAfterSkippingLeadingTrivia)
|
||||
let endLocation = locationConverter.location(for: node.endPositionBeforeTrailingTrivia)
|
||||
for line in startLocation.line...endLocation.line {
|
||||
|
||||
@@ -7,12 +7,35 @@ final class LineLengthRuleTests: SwiftLintTestCase {
|
||||
"c: String, d: String, e: String, f: String, g: String, h: String, i: String, " +
|
||||
"j: String, k: String, l: String, m: String, n: String, o: String, p: String, " +
|
||||
"q: String, r: String, s: String, t: String, u: String, v: String, w: String, " +
|
||||
"x: String, y: String, z: String) {\n"),
|
||||
"x: String, y: String, z: String) {}\n"),
|
||||
Example("func superDuperLongFunctionDeclaration(a: String, b: String, " +
|
||||
"c: String, d: String, e: String, f: String, g: String, h: String, i: String, " +
|
||||
"j: String, k: String, l: String, m: String, n: String, o: String, p: String, " +
|
||||
"q: String, r: String, s: String, t: String, u: String, v: String, w: String, " +
|
||||
"x: String, y: String, z: String) {\n"),
|
||||
"x: String, y: String, z: String) {}\n"),
|
||||
Example("""
|
||||
struct S {
|
||||
public init(a: String, b: String, c: String, d: String, e: String, f: String, \
|
||||
g: String, h: String, i: String, j: String, k: String, l: String, \
|
||||
m: String, n: String, o: String, p: String, q: String, r: String, \
|
||||
s: String, t: String, u: String, v: String, w: String, x: String, \
|
||||
y: String, z: String) throws {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
"""),
|
||||
Example("""
|
||||
struct S {
|
||||
subscript(a: String, b: String, c: String, d: String, e: String, f: String, \
|
||||
g: String, h: String, i: String, j: String, k: String, l: String, \
|
||||
m: String, n: String, o: String, p: String, q: String, r: String, \
|
||||
s: String, t: String, u: String, v: String, w: String, x: String, \
|
||||
y: String, z: String) -> Int {
|
||||
// ...
|
||||
return 0
|
||||
}
|
||||
}
|
||||
"""),
|
||||
]
|
||||
|
||||
private let longComment = Example(String(repeating: "/", count: 121) + "\n")
|
||||
@@ -50,8 +73,12 @@ final class LineLengthRuleTests: SwiftLintTestCase {
|
||||
let nonTriggeringExamples = baseDescription.nonTriggeringExamples + longFunctionDeclarations
|
||||
let description = baseDescription.with(nonTriggeringExamples: nonTriggeringExamples)
|
||||
|
||||
verifyRule(description, ruleConfiguration: ["ignores_function_declarations": true],
|
||||
commentDoesntViolate: false, stringDoesntViolate: false)
|
||||
verifyRule(
|
||||
description,
|
||||
ruleConfiguration: ["ignores_function_declarations": true],
|
||||
commentDoesntViolate: false,
|
||||
stringDoesntViolate: false
|
||||
)
|
||||
}
|
||||
|
||||
func testLineLengthWithIgnoreCommentsEnabled() {
|
||||
|
||||
Reference in New Issue
Block a user