Enable `direct_return` rule in the repository

This commit is contained in:
Danny Mösch 2023-03-12 14:02:43 +01:00
parent 06578e5d91
commit 7ac128c83d
11 changed files with 10 additions and 26 deletions

View File

@ -15,7 +15,6 @@ disabled_rules:
- closure_body_length
- conditional_returns_on_newline
- convenience_type
- direct_return
- discouraged_optional_collection
- explicit_acl
- explicit_enum_raw_value

View File

@ -137,9 +137,8 @@ public struct SourceKittenDictionary {
/// The fully preserved SourceKitten dictionaries for all the attributes associated with this dictionary.
var swiftAttributes: [SourceKittenDictionary] {
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)
return dictionaries
}
var elements: [SourceKittenDictionary] {

View File

@ -270,13 +270,12 @@ extension SwiftLintFile {
internal func ruleEnabled(violatingRanges: [NSRange], for rule: Rule) -> [NSRange] {
let fileRegions = regions()
if fileRegions.isEmpty { return violatingRanges }
let violatingRanges = violatingRanges.filter { range in
return violatingRanges.filter { range in
let region = fileRegions.first {
$0.contains(Location(file: self, characterOffset: range.location))
}
return region?.isRuleEnabled(rule) ?? true
}
return violatingRanges
}
internal func ruleEnabled(violatingRange: NSRange, for rule: Rule) -> NSRange? {

View File

@ -157,9 +157,7 @@ struct ExtensionAccessModifierRule: ASTRule, ConfigurationProviderRule, OptInRul
// attributeBuiltin (`final` for example) tokens between them
let length = typeOffset - previousInternalByteRange.location
let range = ByteRange(location: previousInternalByteRange.location, length: length)
let internalBelongsToType = Set(file.syntaxMap.kinds(inByteRange: range)) == [.attributeBuiltin]
return internalBelongsToType
return Set(file.syntaxMap.kinds(inByteRange: range)) == [.attributeBuiltin]
}
return violationOffsets.map {

View File

@ -114,12 +114,10 @@ struct NimbleOperatorRule: ConfigurationProviderRule, OptInRule, CorrectableRule
return false
}
let containsCall = file.structureDictionary.structures(forByteOffset: byteRange.upperBound - 1)
return file.structureDictionary.structures(forByteOffset: byteRange.upperBound - 1)
.contains(where: { dict -> Bool in
return dict.expressionKind == .call && (dict.name ?? "").starts(with: "expect")
})
return containsCall
}
}

View File

@ -110,7 +110,7 @@ struct RedundantTypeAnnotationRule: OptInRule, SubstitutionCorrectableRule, Conf
}
func violationRanges(in file: SwiftLintFile) -> [NSRange] {
let violatingRanges = file
return file
.match(pattern: expressionPattern)
.filter {
$0.1 == [.keyword, .identifier, .typeidentifier, .identifier] ||
@ -122,8 +122,6 @@ struct RedundantTypeAnnotationRule: OptInRule, SubstitutionCorrectableRule, Conf
file.match(pattern: typeAnnotationPattern,
excludingSyntaxKinds: SyntaxKind.commentAndStringKinds, range: $0.0).first
}
return violatingRanges
}
private func isFalsePositive(file: SwiftLintFile, range: NSRange) -> Bool {

View File

@ -23,10 +23,9 @@ struct FileLengthRule: ConfigurationProviderRule {
func validate(file: SwiftLintFile) -> [StyleViolation] {
func lineCountWithoutComments() -> Int {
let commentKinds = SyntaxKind.commentKinds
let lineCount = file.syntaxKindsByLines.filter { kinds in
return file.syntaxKindsByLines.filter { kinds in
return !Set(kinds).isSubset(of: commentKinds)
}.count
return lineCount
}
var lineCount = file.lines.count

View File

@ -205,11 +205,9 @@ extension ClosureEndIndentationRule {
closureArguments.removeLast()
}
let argumentViolations = closureArguments.compactMap { dictionary in
return closureArguments.compactMap { dictionary in
return validateClosureArgument(in: file, dictionary: dictionary)
}
return argumentViolations
}
private func validateClosureArgument(in file: SwiftLintFile,

View File

@ -234,9 +234,8 @@ struct OpeningBraceRule: CorrectableRule, ConfigurationProviderRule {
}
if let indexRange = contents.nsrangeToIndexRange(adjustedRange) {
let correctedContents = contents
return contents
.replacingCharacters(in: indexRange, with: correctString)
return correctedContents
} else {
return contents
}

View File

@ -179,9 +179,7 @@ private extension StatementPositionRule {
let validator = Self.uncuddledMatchValidator(contents: contents)
let filterMatches = Self.uncuddledMatchFilter(contents: contents, syntaxMap: syntaxMap)
let validMatches = matches.compactMap(validator).filter(filterMatches).map({ $0.range })
return validMatches
return matches.compactMap(validator).filter(filterMatches).map({ $0.range })
}
func uncuddledCorrect(file: SwiftLintFile) -> [Correction] {

View File

@ -132,8 +132,7 @@ struct VerticalWhitespaceBetweenCasesRule: ConfigurationProviderRule {
let matchFirstRange = matchResult.range(at: 1)
let matchFirstString = substring.substring(from: matchFirstRange.location, length: matchFirstRange.length)
let isAllWhitespace = matchFirstString.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
return isAllWhitespace
return matchFirstString.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
}
}