mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
fcf848608e
* Add Example wrapper in order to display test failures inline when running in Xcode. * Stop using Swift 5.1-only features so we can compile on Xcode 10.2. * Wrap strings in Example. * Add Changelog entry. * Wrap all examples in Example struct. * Better and more complete capturing of line numbers. * Fix broken test. * Better test traceability. * Address or disable linting warnings. * Add documentation comments. * Disable linter for a few cases. * Limit mutability and add copy-and-mutate utility functions. * Limit scope of mutability.
230 lines
5.2 KiB
Swift
230 lines
5.2 KiB
Swift
// swiftlint:disable type_body_length
|
|
internal struct ModifierOrderRuleExamples {
|
|
static let nonTriggeringExamples = [
|
|
Example("""
|
|
public class Foo {
|
|
public convenience required init() {}
|
|
}
|
|
"""),
|
|
Example("""
|
|
public class Foo {
|
|
public static let bar = 42
|
|
}
|
|
"""),
|
|
Example("""
|
|
public class Foo {
|
|
public static var bar: Int {
|
|
return
|
|
}
|
|
}
|
|
"""),
|
|
Example("""
|
|
public class Foo {
|
|
public class var bar: Int {
|
|
return 42
|
|
}
|
|
}
|
|
"""),
|
|
Example("""
|
|
public class Bar {
|
|
public class var foo: String {
|
|
return "foo"
|
|
}
|
|
}
|
|
public class Foo: Bar {
|
|
override public final class var foo: String {
|
|
return "bar"
|
|
}
|
|
}
|
|
"""),
|
|
Example("""
|
|
open class Bar {
|
|
public var foo: Int? {
|
|
return 42
|
|
}
|
|
}
|
|
open class Foo: Bar {
|
|
override public var foo: Int? {
|
|
return 43
|
|
}
|
|
}
|
|
"""),
|
|
Example("""
|
|
open class Bar {
|
|
open class func foo() -> Int {
|
|
return 42
|
|
}
|
|
}
|
|
class Foo: Bar {
|
|
override open class func foo() -> Int {
|
|
return 43
|
|
}
|
|
}
|
|
"""),
|
|
Example("""
|
|
protocol Foo: class {}
|
|
class Bar {
|
|
public private(set) weak var foo: Foo?
|
|
}
|
|
"""),
|
|
Example("""
|
|
@objc
|
|
public final class Foo: NSObject {}
|
|
"""),
|
|
Example("""
|
|
@objcMembers
|
|
public final class Foo: NSObject {}
|
|
"""),
|
|
Example("""
|
|
@objc
|
|
override public private(set) weak var foo: Bar?
|
|
"""),
|
|
Example("""
|
|
@objc
|
|
public final class Foo: NSObject {}
|
|
"""),
|
|
Example("""
|
|
@objc
|
|
open final class Foo: NSObject {
|
|
open weak var weakBar: NSString? = nil
|
|
}
|
|
"""),
|
|
Example("""
|
|
public final class Foo {}
|
|
"""),
|
|
Example("""
|
|
class Bar {
|
|
func bar() {}
|
|
}
|
|
"""),
|
|
Example("""
|
|
internal class Foo: Bar {
|
|
override internal func bar() {}
|
|
}
|
|
"""),
|
|
Example("""
|
|
public struct Foo {
|
|
internal weak var weakBar: NSObject? = nil
|
|
}
|
|
"""),
|
|
Example("""
|
|
class Foo {
|
|
internal lazy var bar: String = "foo"
|
|
}
|
|
""")
|
|
]
|
|
|
|
static let triggeringExamples = [
|
|
Example("""
|
|
class Foo {
|
|
convenience required public init() {}
|
|
}
|
|
"""),
|
|
Example("""
|
|
public class Foo {
|
|
static public let bar = 42
|
|
}
|
|
"""),
|
|
Example("""
|
|
public class Foo {
|
|
static public var bar: Int {
|
|
return 42
|
|
}
|
|
}
|
|
"""),
|
|
Example("""
|
|
public class Foo {
|
|
class public var bar: Int {
|
|
return 42
|
|
}
|
|
}
|
|
"""),
|
|
Example("""
|
|
public class RootFoo {
|
|
class public var foo: String {
|
|
return "foo"
|
|
}
|
|
}
|
|
public class Foo: RootFoo {
|
|
override final class public var foo: String
|
|
return "bar"
|
|
}
|
|
}
|
|
"""),
|
|
Example("""
|
|
open class Bar {
|
|
public var foo: Int? {
|
|
return 42
|
|
}
|
|
}
|
|
open class Foo: Bar {
|
|
public override var foo: Int? {
|
|
return 43
|
|
}
|
|
}
|
|
"""),
|
|
Example("""
|
|
protocol Foo: class {}
|
|
class Bar {
|
|
private(set) public weak var foo: Foo?
|
|
}
|
|
"""),
|
|
Example("""
|
|
open class Bar {
|
|
open class func foo() -> Int {
|
|
return 42
|
|
}
|
|
}
|
|
class Foo: Bar {
|
|
class open override func foo() -> Int {
|
|
return 43
|
|
}
|
|
}
|
|
"""),
|
|
Example("""
|
|
open class Bar {
|
|
open class func foo() -> Int {
|
|
return 42
|
|
}
|
|
}
|
|
class Foo: Bar {
|
|
open override class func foo() -> Int {
|
|
return 43
|
|
}
|
|
}
|
|
"""),
|
|
Example("""
|
|
@objc
|
|
final public class Foo: NSObject {}
|
|
"""),
|
|
Example("""
|
|
@objcMembers
|
|
final public class Foo: NSObject {}
|
|
"""),
|
|
Example("""
|
|
@objc
|
|
final open class Foo: NSObject {
|
|
weak open var weakBar: NSString? = nil
|
|
}
|
|
"""),
|
|
Example("""
|
|
final public class Foo {}
|
|
"""),
|
|
Example("""
|
|
internal class Foo: Bar {
|
|
internal override func bar() {}
|
|
}
|
|
"""),
|
|
Example("""
|
|
public struct Foo {
|
|
weak internal var weakBar: NSObjetc? = nil
|
|
}
|
|
"""),
|
|
Example("""
|
|
class Foo {
|
|
lazy internal var bar: String = "foo"
|
|
}
|
|
""")
|
|
]
|
|
}
|