Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ disabled_rules:
- no_grouping_extension
- no_magic_numbers
- one_declaration_per_file
- prefer_condition_list
- prefer_key_path # Re-enable once we are on Swift 6.
- prefer_nimble
- prefixed_toplevel_constant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ private extension DiscouragedObjectLiteralRule {
return
}

if !configuration.imageLiteral && identifierText == "imageLiteral" {
if !configuration.imageLiteral, identifierText == "imageLiteral" {
return
}

if !configuration.colorLiteral && identifierText == "colorLiteral" {
if !configuration.colorLiteral, identifierText == "colorLiteral" {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct RedundantVoidReturnRule: Rule {
private extension RedundantVoidReturnRule {
final class Visitor: ViolationsSyntaxVisitor<ConfigurationType> {
override func visitPost(_ node: ReturnClauseSyntax) {
if !configuration.includeClosures && node.parent?.is(ClosureSignatureSyntax.self) == true {
if !configuration.includeClosures, node.parent?.is(ClosureSignatureSyntax.self) == true {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private extension FunctionCallExprSyntax {
}

// Check container views with accessibility modifiers
if funcCall.isContainerView() && funcCall.hasAccessibilityModifiersInChain() {
if funcCall.isContainerView(), funcCall.hasAccessibilityModifiersInChain() {
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private extension EmptyXCTestMethodRule {
}

override func visitPost(_ node: FunctionDeclSyntax) {
if (node.modifiers.contains(keyword: .override) || node.isTestMethod) && node.hasEmptyBody {
if node.modifiers.contains(keyword: .override) || node.isTestMethod, node.hasEmptyBody {
violations.append(node.funcKeyword.positionAfterSkippingLeadingTrivia)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private extension OrphanedDocCommentRule {
switch piece {
case .docLineComment(let comment), .docBlockComment(let comment):
// These patterns are often used for "file header" style comments
if !comment.hasPrefix("////") && !comment.hasPrefix("/***") {
if !comment.hasPrefix("////"), !comment.hasPrefix("/***") {
if isOrphanedDocComment(with: &iterator) {
let utf8Length = pieces[..<index].reduce(0) { $0 + $1.sourceLength.utf8Length }
violations.append(node.position.advanced(by: utf8Length))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private extension PrivateOutletRule {
return
}

if configuration.allowPrivateSet && decl.modifiers.containsPrivateOrFileprivate(setOnly: true) {
if configuration.allowPrivateSet, decl.modifiers.containsPrivateOrFileprivate(setOnly: true) {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private extension UnneededOverrideRule {
}

override func visitPost(_ node: InitializerDeclSyntax) {
if configuration.affectInits && node.isUnneededOverride {
if configuration.affectInits, node.isUnneededOverride {
self.violations.append(node.positionAfterSkippingLeadingTrivia)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private extension SwiftLintFile {
// with "related names", which appears to be similarly named declarations (i.e. overloads) that are
// programmatically unrelated to the current cursor-info declaration. Those similarly named declarations
// aren't in `key.related` so confirm that that one is also populated.
if cursorInfo?.value["key.related_decls"] != nil && indexEntity.value["key.related"] != nil {
if cursorInfo?.value["key.related_decls"] != nil, indexEntity.value["key.related"] != nil {
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private extension SwiftLintFile {

var unusedImports = imports.subtracting(usrFragments).subtracting(configuration.alwaysKeepImports)
// Certain Swift attributes requires importing Foundation.
if unusedImports.contains("Foundation") && containsAttributesRequiringFoundation() {
if unusedImports.contains("Foundation"), containsAttributesRequiringFoundation() {
unusedImports.remove("Foundation")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private extension FileLengthRule {
) {
var currentPosition = startPosition
for piece in trivia {
if !piece.isComment && !piece.isWhitespace {
if !piece.isComment, !piece.isWhitespace {
let startLocation = locationConverter.location(for: currentPosition)
let endLocation = locationConverter.location(for: currentPosition + piece.sourceLength)
addLinesInRange(from: startLocation.line, to: endLocation.line, to: &lines)
Expand All @@ -93,7 +93,7 @@ private extension FileLengthRule {
}

private func addLinesInRange(from startLine: Int, to endLine: Int, to lines: inout Set<Int>) {
guard startLine > 0 && startLine <= endLine else { return }
guard startLine > 0, startLine <= endLine else { return }
for line in startLine...endLine {
lines.insert(line)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ private extension LineLengthRule {
}

// Apply ignore configurations
if configuration.ignoresFunctionDeclarations && functionDeclarationLines.contains(line.index) {
if configuration.ignoresFunctionDeclarations, functionDeclarationLines.contains(line.index) {
continue
}
if configuration.ignoresComments && commentOnlyLines.contains(line.index) {
if configuration.ignoresComments, commentOnlyLines.contains(line.index) {
continue
}
if configuration.ignoresInterpolatedStrings && interpolatedStringLines.contains(line.index) {
if configuration.ignoresInterpolatedStrings, interpolatedStringLines.contains(line.index) {
continue
}
if configuration.ignoresMultilineStrings && multilineStringLines.contains(line.index) {
if configuration.ignoresMultilineStrings, multilineStringLines.contains(line.index) {
continue
}
if configuration.excludedLinesPatterns.contains(where: {
Expand Down
4 changes: 2 additions & 2 deletions Source/SwiftLintBuiltInRules/Rules/Metrics/NestingRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private extension NestingRule {
override func visit(_ node: EnumDeclSyntax) -> SyntaxVisitorContinueKind {
// if current defines coding keys and we're ignoring coding keys, then skip nesting rule
// push another level on and proceed to visit children
if configuration.ignoreCodingKeys && node.definesCodingKeys {
if configuration.ignoreCodingKeys, node.definesCodingKeys {
levels.push(levels.lastIsFunction)
} else {
validate(forFunction: false, triggeringToken: node.enumKeyword)
Expand Down Expand Up @@ -156,7 +156,7 @@ private extension NestingRule {
let targetLevel = forFunction ? configuration.functionLevel : configuration.typeLevel

// if parent is function and current is not function types, then skip nesting rule.
if configuration.alwaysAllowOneTypeInFunctions && inFunction && !forFunction {
if configuration.alwaysAllowOneTypeInFunctions, inFunction, !forFunction {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private extension EmptyCountRule {
private extension ExprSyntax {
func countCallPosition(onlyAfterDot: Bool) -> AbsolutePosition? {
if let expr = self.as(MemberAccessExprSyntax.self) {
if expr.declName.argumentNames == nil && expr.declName.baseName.tokenKind == .identifier("count") {
if expr.declName.argumentNames == nil, expr.declName.baseName.tokenKind == .identifier("count") {
return expr.declName.baseName.positionAfterSkippingLeadingTrivia
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct OverriddenSuperCallConfiguration: SeverityBasedRuleConfiguration {

var resolvedMethodNames: [String] {
var names: [String] = []
if included.contains("*") && !excluded.contains("*") {
if included.contains("*"), !excluded.contains("*") {
names += Self.defaultIncluded
}
names += included.filter { $0 != "*" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct ProhibitedSuperConfiguration: SeverityBasedRuleConfiguration {

var resolvedMethodNames: [String] {
var names = [String]()
if included.contains("*") && !excluded.contains("*") {
if included.contains("*"), !excluded.contains("*") {
names += Self.methodNames
}
names += included.filter { $0 != "*" }
Expand Down
4 changes: 2 additions & 2 deletions Source/SwiftLintBuiltInRules/Rules/Style/AttributesRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private extension AttributesRule {
}

let hasMultipleNewlines = node.children(viewMode: .sourceAccurate).enumerated().contains { index, element in
if index > 0 && element.leadingTrivia.hasMultipleNewlines == true {
if index > 0, element.leadingTrivia.hasMultipleNewlines == true {
return true
}
return element.trailingTrivia.hasMultipleNewlines == true
Expand Down Expand Up @@ -162,7 +162,7 @@ private struct RuleHelper {
linesWithAttributes.contains(attributeStartLine)
linesWithAttributes.insert(attributeStartLine)
if hasViolation {
if attributesWithArgumentsAlwaysOnNewLine && shouldBeOnSameLine {
if attributesWithArgumentsAlwaysOnNewLine, shouldBeOnSameLine {
return .argumentsAlwaysOnNewLineViolation
}
return .violation
Expand Down
6 changes: 3 additions & 3 deletions Source/SwiftLintBuiltInRules/Rules/Style/ColonRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ struct ColonRule: SubstitutionCorrectableRule, SourceKitFreeRule {
return nil
}

if previous.trailingTrivia.isNotEmpty && !previous.trailingTrivia.containsBlockComments() {
if previous.trailingTrivia.isNotEmpty, !previous.trailingTrivia.containsBlockComments() {
let start = ByteCount(previous.endPositionBeforeTrailingTrivia)
let end = ByteCount(current.endPosition)
return ByteRange(location: start, length: end - start)
}
if current.trailingTrivia != [.spaces(1)] && !next.leadingTrivia.containsNewlines() {
if current.trailingTrivia != [.spaces(1)], !next.leadingTrivia.containsNewlines() {
if case .spaces(1) = current.trailingTrivia.first {
return nil
}

let flexibleRightSpacing = configuration.flexibleRightSpacing ||
caseStatementPositions.contains(current.position)
if flexibleRightSpacing && current.trailingTrivia.isNotEmpty {
if flexibleRightSpacing, current.trailingTrivia.isNotEmpty {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintBuiltInRules/Rules/Style/CommaRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct CommaRule: CorrectableRule, SourceKitFreeRule {
if current.tokenKind != .comma {
return nil
}
if !previous.trailingTrivia.isEmpty && !previous.trailingTrivia.containsBlockComments() {
if !previous.trailingTrivia.isEmpty, !previous.trailingTrivia.containsBlockComments() {
let start = ByteCount(previous.endPositionBeforeTrailingTrivia)
let end = ByteCount(current.endPosition)
let nextIsNewline = next.leadingTrivia.containsNewlines()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private extension FileHeaderRule {
continue
}

if piece.isComment && !piece.isDocComment {
if piece.isComment, !piece.isDocComment {
if firstStart == nil {
firstStart = pieceStart
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct IndentationWidthRule: OptInRule {

// Determine indentation
let indentation: Indentation
if tabCount != 0 && spaceCount != 0 {
if tabCount != 0, spaceCount != 0 {
// Catch mixed indentation
violations.append(
StyleViolation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ struct MultilineParametersBracketsRule: OptInRule {
let declarationNewlineCount = functionName.countOccurrences(of: "\n")
let isMultiline = declarationNewlineCount > parametersNewlineCount

if isMultiline && parameters.isNotEmpty {
if isMultiline, parameters.isNotEmpty {
if let openingBracketViolation = openingBracketViolation(parameters: parameters, file: file) {
violations.append(openingBracketViolation)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private extension NumberSeparatorValidator {
defer { correctComponents.append(String(char)) }
guard char.unicodeScalars.allSatisfy(CharacterSet.decimalDigits.contains) else { continue }

if numerals.isMultiple(of: 3) && numerals > 0 && shouldAddSeparators {
if numerals.isMultiple(of: 3), numerals > 0, shouldAddSeparators {
correctComponents.append("_")
}
numerals += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private class OperatorUsageWhitespaceVisitor: SyntaxVisitor {
let noSpacing = noSpacingBefore || noSpacingAfter

let operatorText = operatorToken.text
if noSpacing && allowedNoSpaceOperators.contains(operatorText) {
if noSpacing, allowedNoSpaceOperators.contains(operatorText) {
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private extension TokenSyntax {
var end: AbsolutePosition?
var correction = " -> "

if previousToken.trailingTrivia != .space && !leadingTrivia.containsNewlines() {
if previousToken.trailingTrivia != .space, !leadingTrivia.containsNewlines() {
start = previousToken.endPositionBeforeTrailingTrivia
end = endPosition

Expand All @@ -96,7 +96,7 @@ private extension TokenSyntax {
}
}

if trailingTrivia != .space && !nextToken.leadingTrivia.containsNewlines() {
if trailingTrivia != .space, !nextToken.leadingTrivia.containsNewlines() {
if leadingTrivia.containsNewlines() {
start = positionAfterSkippingLeadingTrivia
correction = "-> "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private extension StatementPositionRule {
} else {
newLines = ""
}
if !whitespace.hasPrefix("\n") && newLines != "\n" {
if !whitespace.hasPrefix("\n"), newLines != "\n" {
whitespace.insert("\n", at: whitespace.startIndex)
}
contents = contents.bridge().replacingCharacters(in: range2, with: whitespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extension SwitchCaseAlignmentRule {
let switchKeywordPosition = node.switchKeyword.positionAfterSkippingLeadingTrivia
let switchKeywordLocation = locationConverter.location(for: switchKeywordPosition)

if configuration.ignoreOneLiners && switchKeywordLocation.line == closingBraceLocation.line {
if configuration.ignoreOneLiners, switchKeywordLocation.line == closingBraceLocation.line {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ private extension TrailingWhitespaceRule {
}

// Apply `ignoresEmptyLines` configuration
if configuration.ignoresEmptyLines &&
line.trimmingCharacters(in: .whitespaces).isEmpty {
if configuration.ignoresEmptyLines, line.trimmingCharacters(in: .whitespaces).isEmpty {
continue
}

Expand Down Expand Up @@ -102,7 +101,7 @@ private extension TrailingWhitespaceRule {
let pieceStart = currentPos
currentPos += piece.sourceLength

if piece.isComment && !piece.isBlockComment {
if piece.isComment, !piece.isBlockComment {
let pieceStartLine = locationConverter.location(for: pieceStart).line
lineCommentRanges[pieceStartLine, default: []].append(pieceStart..<currentPos)
}
Expand All @@ -114,7 +113,7 @@ private extension TrailingWhitespaceRule {
let pieceStart = currentPos
currentPos += piece.sourceLength

if piece.isComment && !piece.isBlockComment {
if piece.isComment, !piece.isBlockComment {
let pieceStartLine = locationConverter.location(for: pieceStart).line
lineCommentRanges[pieceStartLine, default: []].append(pieceStart..<currentPos)
}
Expand Down Expand Up @@ -153,7 +152,7 @@ private extension TrailingWhitespaceRule {
from line: String,
removing trailingWhitespaceInfo: TrailingWhitespaceInfo
) -> String {
if trailingWhitespaceInfo.characterCount > 0 && line.count >= trailingWhitespaceInfo.characterCount {
if trailingWhitespaceInfo.characterCount > 0, line.count >= trailingWhitespaceInfo.characterCount {
return String(line.prefix(line.count - trailingWhitespaceInfo.characterCount))
}
return ""
Expand All @@ -179,7 +178,7 @@ private extension TrailingWhitespaceRule {
// Check if this position falls within any comment range on this line
if let ranges = lineCommentRanges[lineNumber] {
for range in ranges {
if range.lowerBound <= lastNonWhitespacePos && lastNonWhitespacePos < range.upperBound {
if range.lowerBound <= lastNonWhitespacePos, lastNonWhitespacePos < range.upperBound {
return true
}
}
Expand Down Expand Up @@ -236,7 +235,7 @@ private extension TrailingWhitespaceRule {
var endLine = endLocation.line

// If comment ends at column 1, it actually ended on the previous line
if endLocation.column == 1 && endLine > startLine {
if endLocation.column == 1, endLine > startLine {
endLine -= 1
}

Expand All @@ -261,13 +260,13 @@ private extension TrailingWhitespaceRule {
let lastNonWhitespacePos = lineStartPos.advanced(by: byteOffsetToLastNonWS)

// Check if both first and last non-whitespace positions are within the comment
if firstNonWhitespacePos >= blockCommentStart && lastNonWhitespacePos < blockCommentEnd {
if firstNonWhitespacePos >= blockCommentStart, lastNonWhitespacePos < blockCommentEnd {
linesFullyCoveredByBlockComments.insert(lineNum)
}
} else {
// Line is all whitespace - check if it's within the comment bounds
let lineEndPos = lineStartPos.advanced(by: lineContent.utf8.count)
if lineStartPos >= blockCommentStart && lineEndPos <= blockCommentEnd {
if lineStartPos >= blockCommentStart, lineEndPos <= blockCommentEnd {
linesFullyCoveredByBlockComments.insert(lineNum)
}
}
Expand All @@ -294,7 +293,7 @@ private extension String {
var charCount = 0
var byteLen = 0
for char in self.reversed() {
if char.isWhitespace && (char == " " || char == "\t") { // Only count spaces and tabs
if char.isWhitespace, char == " " || char == "\t" { // Only count spaces and tabs
charCount += 1
byteLen += char.utf8.count
} else {
Expand Down
Loading