mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +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.
71 lines
2.1 KiB
Swift
71 lines
2.1 KiB
Swift
import Foundation
|
|
import SourceKittenFramework
|
|
|
|
public struct StrictFilePrivateRule: OptInRule, ConfigurationProviderRule, AutomaticTestableRule {
|
|
public var configuration = SeverityConfiguration(.warning)
|
|
|
|
public init() {}
|
|
|
|
public static let description = RuleDescription(
|
|
identifier: "strict_fileprivate",
|
|
name: "Strict fileprivate",
|
|
description: "`fileprivate` should be avoided.",
|
|
kind: .idiomatic,
|
|
nonTriggeringExamples: [
|
|
Example("extension String {}"),
|
|
Example("private extension String {}"),
|
|
Example("""
|
|
public
|
|
extension String {}
|
|
"""),
|
|
Example("""
|
|
open extension
|
|
String {}
|
|
"""),
|
|
Example("internal extension String {}")
|
|
],
|
|
triggeringExamples: [
|
|
Example("↓fileprivate extension String {}"),
|
|
Example("""
|
|
↓fileprivate
|
|
extension String {}
|
|
"""),
|
|
Example("""
|
|
↓fileprivate extension
|
|
String {}
|
|
"""),
|
|
Example("""
|
|
extension String {
|
|
↓fileprivate func Something(){}
|
|
}
|
|
"""),
|
|
Example("""
|
|
class MyClass {
|
|
↓fileprivate let myInt = 4
|
|
}
|
|
"""),
|
|
Example("""
|
|
class MyClass {
|
|
↓fileprivate(set) var myInt = 4
|
|
}
|
|
"""),
|
|
Example("""
|
|
struct Outter {
|
|
struct Inter {
|
|
↓fileprivate struct Inner {}
|
|
}
|
|
}
|
|
""")
|
|
]
|
|
)
|
|
|
|
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
|
// Mark all fileprivate occurences as a violation
|
|
return file.match(pattern: "fileprivate", with: [.attributeBuiltin]).map {
|
|
StyleViolation(ruleDescription: type(of: self).description,
|
|
severity: configuration.severity,
|
|
location: Location(file: file, characterOffset: $0.location))
|
|
}
|
|
}
|
|
}
|