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
|
||||
- conditional_returns_on_newline
|
||||
- convenience_type
|
||||
- direct_return
|
||||
- discouraged_optional_collection
|
||||
- explicit_acl
|
||||
- explicit_enum_raw_value
|
||||
|
|
|
@ -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] {
|
||||
|
|
|
@ -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? {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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] {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue