Enable `direct_return` rule in the repository
This commit is contained in:
parent
06578e5d91
commit
7ac128c83d
|
@ -15,7 +15,6 @@ disabled_rules:
|
||||||
- closure_body_length
|
- closure_body_length
|
||||||
- conditional_returns_on_newline
|
- conditional_returns_on_newline
|
||||||
- convenience_type
|
- convenience_type
|
||||||
- direct_return
|
|
||||||
- discouraged_optional_collection
|
- discouraged_optional_collection
|
||||||
- explicit_acl
|
- explicit_acl
|
||||||
- explicit_enum_raw_value
|
- explicit_enum_raw_value
|
||||||
|
|
|
@ -137,9 +137,8 @@ public struct SourceKittenDictionary {
|
||||||
/// The fully preserved SourceKitten dictionaries for all the attributes associated with this dictionary.
|
/// The fully preserved SourceKitten dictionaries for all the attributes associated with this dictionary.
|
||||||
var swiftAttributes: [SourceKittenDictionary] {
|
var swiftAttributes: [SourceKittenDictionary] {
|
||||||
let array = value["key.attributes"] as? [SourceKitRepresentable] ?? []
|
let array = value["key.attributes"] as? [SourceKitRepresentable] ?? []
|
||||||
let dictionaries = array.compactMap { $0 as? [String: SourceKitRepresentable] }
|
return array.compactMap { $0 as? [String: SourceKitRepresentable] }
|
||||||
.map(Self.init)
|
.map(Self.init)
|
||||||
return dictionaries
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var elements: [SourceKittenDictionary] {
|
var elements: [SourceKittenDictionary] {
|
||||||
|
|
|
@ -270,13 +270,12 @@ extension SwiftLintFile {
|
||||||
internal func ruleEnabled(violatingRanges: [NSRange], for rule: Rule) -> [NSRange] {
|
internal func ruleEnabled(violatingRanges: [NSRange], for rule: Rule) -> [NSRange] {
|
||||||
let fileRegions = regions()
|
let fileRegions = regions()
|
||||||
if fileRegions.isEmpty { return violatingRanges }
|
if fileRegions.isEmpty { return violatingRanges }
|
||||||
let violatingRanges = violatingRanges.filter { range in
|
return violatingRanges.filter { range in
|
||||||
let region = fileRegions.first {
|
let region = fileRegions.first {
|
||||||
$0.contains(Location(file: self, characterOffset: range.location))
|
$0.contains(Location(file: self, characterOffset: range.location))
|
||||||
}
|
}
|
||||||
return region?.isRuleEnabled(rule) ?? true
|
return region?.isRuleEnabled(rule) ?? true
|
||||||
}
|
}
|
||||||
return violatingRanges
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func ruleEnabled(violatingRange: NSRange, for rule: Rule) -> NSRange? {
|
internal func ruleEnabled(violatingRange: NSRange, for rule: Rule) -> NSRange? {
|
||||||
|
|
|
@ -157,9 +157,7 @@ struct ExtensionAccessModifierRule: ASTRule, ConfigurationProviderRule, OptInRul
|
||||||
// attributeBuiltin (`final` for example) tokens between them
|
// attributeBuiltin (`final` for example) tokens between them
|
||||||
let length = typeOffset - previousInternalByteRange.location
|
let length = typeOffset - previousInternalByteRange.location
|
||||||
let range = ByteRange(location: previousInternalByteRange.location, length: length)
|
let range = ByteRange(location: previousInternalByteRange.location, length: length)
|
||||||
let internalBelongsToType = Set(file.syntaxMap.kinds(inByteRange: range)) == [.attributeBuiltin]
|
return Set(file.syntaxMap.kinds(inByteRange: range)) == [.attributeBuiltin]
|
||||||
|
|
||||||
return internalBelongsToType
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return violationOffsets.map {
|
return violationOffsets.map {
|
||||||
|
|
|
@ -114,12 +114,10 @@ struct NimbleOperatorRule: ConfigurationProviderRule, OptInRule, CorrectableRule
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
let containsCall = file.structureDictionary.structures(forByteOffset: byteRange.upperBound - 1)
|
return file.structureDictionary.structures(forByteOffset: byteRange.upperBound - 1)
|
||||||
.contains(where: { dict -> Bool in
|
.contains(where: { dict -> Bool in
|
||||||
return dict.expressionKind == .call && (dict.name ?? "").starts(with: "expect")
|
return dict.expressionKind == .call && (dict.name ?? "").starts(with: "expect")
|
||||||
})
|
})
|
||||||
|
|
||||||
return containsCall
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ struct RedundantTypeAnnotationRule: OptInRule, SubstitutionCorrectableRule, Conf
|
||||||
}
|
}
|
||||||
|
|
||||||
func violationRanges(in file: SwiftLintFile) -> [NSRange] {
|
func violationRanges(in file: SwiftLintFile) -> [NSRange] {
|
||||||
let violatingRanges = file
|
return file
|
||||||
.match(pattern: expressionPattern)
|
.match(pattern: expressionPattern)
|
||||||
.filter {
|
.filter {
|
||||||
$0.1 == [.keyword, .identifier, .typeidentifier, .identifier] ||
|
$0.1 == [.keyword, .identifier, .typeidentifier, .identifier] ||
|
||||||
|
@ -122,8 +122,6 @@ struct RedundantTypeAnnotationRule: OptInRule, SubstitutionCorrectableRule, Conf
|
||||||
file.match(pattern: typeAnnotationPattern,
|
file.match(pattern: typeAnnotationPattern,
|
||||||
excludingSyntaxKinds: SyntaxKind.commentAndStringKinds, range: $0.0).first
|
excludingSyntaxKinds: SyntaxKind.commentAndStringKinds, range: $0.0).first
|
||||||
}
|
}
|
||||||
|
|
||||||
return violatingRanges
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func isFalsePositive(file: SwiftLintFile, range: NSRange) -> Bool {
|
private func isFalsePositive(file: SwiftLintFile, range: NSRange) -> Bool {
|
||||||
|
|
|
@ -23,10 +23,9 @@ struct FileLengthRule: ConfigurationProviderRule {
|
||||||
func validate(file: SwiftLintFile) -> [StyleViolation] {
|
func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||||
func lineCountWithoutComments() -> Int {
|
func lineCountWithoutComments() -> Int {
|
||||||
let commentKinds = SyntaxKind.commentKinds
|
let commentKinds = SyntaxKind.commentKinds
|
||||||
let lineCount = file.syntaxKindsByLines.filter { kinds in
|
return file.syntaxKindsByLines.filter { kinds in
|
||||||
return !Set(kinds).isSubset(of: commentKinds)
|
return !Set(kinds).isSubset(of: commentKinds)
|
||||||
}.count
|
}.count
|
||||||
return lineCount
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var lineCount = file.lines.count
|
var lineCount = file.lines.count
|
||||||
|
|
|
@ -205,11 +205,9 @@ extension ClosureEndIndentationRule {
|
||||||
closureArguments.removeLast()
|
closureArguments.removeLast()
|
||||||
}
|
}
|
||||||
|
|
||||||
let argumentViolations = closureArguments.compactMap { dictionary in
|
return closureArguments.compactMap { dictionary in
|
||||||
return validateClosureArgument(in: file, dictionary: dictionary)
|
return validateClosureArgument(in: file, dictionary: dictionary)
|
||||||
}
|
}
|
||||||
|
|
||||||
return argumentViolations
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func validateClosureArgument(in file: SwiftLintFile,
|
private func validateClosureArgument(in file: SwiftLintFile,
|
||||||
|
|
|
@ -234,9 +234,8 @@ struct OpeningBraceRule: CorrectableRule, ConfigurationProviderRule {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let indexRange = contents.nsrangeToIndexRange(adjustedRange) {
|
if let indexRange = contents.nsrangeToIndexRange(adjustedRange) {
|
||||||
let correctedContents = contents
|
return contents
|
||||||
.replacingCharacters(in: indexRange, with: correctString)
|
.replacingCharacters(in: indexRange, with: correctString)
|
||||||
return correctedContents
|
|
||||||
} else {
|
} else {
|
||||||
return contents
|
return contents
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,9 +179,7 @@ private extension StatementPositionRule {
|
||||||
let validator = Self.uncuddledMatchValidator(contents: contents)
|
let validator = Self.uncuddledMatchValidator(contents: contents)
|
||||||
let filterMatches = Self.uncuddledMatchFilter(contents: contents, syntaxMap: syntaxMap)
|
let filterMatches = Self.uncuddledMatchFilter(contents: contents, syntaxMap: syntaxMap)
|
||||||
|
|
||||||
let validMatches = matches.compactMap(validator).filter(filterMatches).map({ $0.range })
|
return matches.compactMap(validator).filter(filterMatches).map({ $0.range })
|
||||||
|
|
||||||
return validMatches
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func uncuddledCorrect(file: SwiftLintFile) -> [Correction] {
|
func uncuddledCorrect(file: SwiftLintFile) -> [Correction] {
|
||||||
|
|
|
@ -132,8 +132,7 @@ struct VerticalWhitespaceBetweenCasesRule: ConfigurationProviderRule {
|
||||||
|
|
||||||
let matchFirstRange = matchResult.range(at: 1)
|
let matchFirstRange = matchResult.range(at: 1)
|
||||||
let matchFirstString = substring.substring(from: matchFirstRange.location, length: matchFirstRange.length)
|
let matchFirstString = substring.substring(from: matchFirstRange.location, length: matchFirstRange.length)
|
||||||
let isAllWhitespace = matchFirstString.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
|
return matchFirstString.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
|
||||||
return isAllWhitespace
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue