Change violation position for static/class decls
This commit is contained in:
parent
cf7b3e03ad
commit
805e761bee
|
@ -103,6 +103,8 @@ private extension IdentifierNameRule {
|
|||
return nil
|
||||
}
|
||||
|
||||
let violationPosition = modifiers.staticOrClassPosition ?? violationPosition
|
||||
|
||||
if kind != .function {
|
||||
let allowedSymbols = configuration.allowedSymbols.union(.alphanumerics)
|
||||
if !allowedSymbols.isSuperset(of: CharacterSet(charactersIn: name)) {
|
||||
|
@ -182,3 +184,11 @@ private extension String {
|
|||
return operators.contains(where: hasPrefix)
|
||||
}
|
||||
}
|
||||
|
||||
private extension ModifierListSyntax? {
|
||||
var staticOrClassPosition: AbsolutePosition? {
|
||||
self?.first { modifier in
|
||||
modifier.name.tokenKind == .staticKeyword || modifier.name.tokenKind == .classKeyword
|
||||
}?.positionAfterSkippingLeadingTrivia
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,16 @@ internal struct IdentifierNameRuleExamples {
|
|||
Example("func something(↓x: Int) -> Bool"),
|
||||
Example("enum Foo { case ↓MyEnum }"),
|
||||
Example("list.first { ↓l in l == 1 }"),
|
||||
Example("for ↓i in 0..<10 {}")
|
||||
Example("for ↓i in 0..<10 {}"),
|
||||
Example("""
|
||||
class MyClass {
|
||||
↓static var x: Int
|
||||
}
|
||||
"""),
|
||||
Example("""
|
||||
class MyClass {
|
||||
↓class let i = 0
|
||||
}
|
||||
""")
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue