-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TestCaseAccessibilityRule #3376
Changes from 1 commit
dc6e09d
d789185
16ee926
82c057f
87dbfa2
9c0da88
33e8b93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,14 @@ | ||
import SourceKittenFramework | ||
|
||
private let testFunctionNames: Set = [ | ||
"setUp()", | ||
"setUpWithError()", | ||
"tearDown()", | ||
"tearDownWithError()" | ||
] | ||
|
||
private let testVariableNames: Set = [ | ||
"allTests" | ||
] | ||
|
||
enum XCTestHelpers { | ||
static func isXCTestMember(kind: SwiftDeclarationKind, name: String) -> Bool { | ||
if SwiftDeclarationKind.functionKinds.contains(kind) { | ||
return name.hasPrefix("test") || testFunctionNames.contains(name) | ||
} else if SwiftDeclarationKind.variableKinds.contains(kind) { | ||
return testVariableNames.contains(name) | ||
} | ||
|
||
return false | ||
static func isXCTestMember(kind: SwiftDeclarationKind, name: String, | ||
attributes: [SwiftDeclarationAttributeKind]) -> Bool { | ||
return attributes.contains(.override) | ||
|| (kind == .functionMethodInstance && name.hasPrefix("test")) | ||
|| ([.varStatic, .varClass].contains(kind) && testVariableNames.contains(name)) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,10 +1,10 @@ | ||||||||||||||||||||||||
public struct TestCaseAccessibilityConfiguration: RuleConfiguration, Equatable { | ||||||||||||||||||||||||
public private(set) var severityConfiguration = SeverityConfiguration(.warning) | ||||||||||||||||||||||||
public private(set) var methodPrefixes: Set<String> = [] | ||||||||||||||||||||||||
public private(set) var allowedPrefixes: Set<String> = [] | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
public var consoleDescription: String { | ||||||||||||||||||||||||
return severityConfiguration.consoleDescription + | ||||||||||||||||||||||||
", method_prefixes: [\(methodPrefixes)]" | ||||||||||||||||||||||||
", allowed_prefixes: [\(allowedPrefixes)]" | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Examples can now specify configurations, so it'd be nice to test something like SwiftLint/Source/SwiftLintFramework/Models/Example.swift Lines 6 to 16 in da408b5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there an example of that working? I tried that and I don't believe it's passed all the way through the tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAICT it only is for analyze tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I think you're right. Let's hold off for now, but it should be easy to make normal lint tests apply this configuration value. |
||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
public mutating func apply(configuration: Any) throws { | ||||||||||||||||||||||||
|
@@ -16,8 +16,8 @@ public struct TestCaseAccessibilityConfiguration: RuleConfiguration, Equatable { | |||||||||||||||||||||||
try severityConfiguration.apply(configuration: severityString) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
if let methodPrefixes = configuration["method_prefixes"] as? [String] { | ||||||||||||||||||||||||
self.methodPrefixes = Set(methodPrefixes) | ||||||||||||||||||||||||
if let allowedPrefixes = configuration["allowed_prefixes"] as? [String] { | ||||||||||||||||||||||||
self.allowedPrefixes = Set(allowedPrefixes) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.