Skip to content

Commit

Permalink
Enable more rules in SwiftLint's own .swiftlint.yml (realm#5532)
Browse files Browse the repository at this point in the history
  • Loading branch information
mildm8nnered authored Apr 27, 2024
1 parent 5bbdf7f commit 7623f1e
Show file tree
Hide file tree
Showing 98 changed files with 348 additions and 354 deletions.
2 changes: 1 addition & 1 deletion .sourcery/GeneratedTests.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import SwiftLintTestHelpers

{% for rule in types.structs %}
{% if rule.name|hasSuffix:"Rule" %}
class {{ rule.name }}GeneratedTests: SwiftLintTestCase {
final class {{ rule.name }}GeneratedTests: SwiftLintTestCase {
func testWithDefaultConfiguration() {
verifyRule({{ rule.name }}.description)
}
Expand Down
7 changes: 1 addition & 6 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ disabled_rules:
- explicit_top_level_acl
- explicit_type_interface
- file_types_order
- final_test_case
- force_unwrapping
- function_default_parameter_at_end
- implicit_return
- implicitly_unwrapped_optional
- indentation_width
- inert_defer
- missing_docs
Expand All @@ -43,11 +41,8 @@ disabled_rules:
- prefer_nimble
- prefer_self_in_static_references
- prefixed_toplevel_constant
- redundant_self_in_closure
- required_deinit
- self_binding
- static_over_final_class
- shorthand_argument
- sorted_enum_cases
- strict_fileprivate
- switch_case_on_newline
Expand Down Expand Up @@ -84,7 +79,7 @@ balanced_xctest_lifecycle: &unit_test_configuration
- XCTestCase
empty_xctest_method: *unit_test_configuration
single_test_class: *unit_test_configuration

final_test_case: *unit_test_configuration
function_body_length: 60
type_body_length: 400

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ struct ExpiringTodoRule: OptInRule {
syntaxKinds.allSatisfy({ $0.isCommentLike }),
checkingResult.numberOfRanges > 1,
case let range = checkingResult.range(at: 1),
let violationLevel = self.violationLevel(for: expiryDate(file: file, range: range)),
let severity = self.severity(for: violationLevel) else {
let violationLevel = violationLevel(for: expiryDate(file: file, range: range)),
let severity = severity(for: violationLevel) else {
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct TypeContentsOrderRule: OptInRule {

private func typeContentOffsets(in typeStructure: SourceKittenDictionary) -> [TypeContentOffset] {
return typeStructure.substructure.compactMap { typeContentStructure in
guard let typeContent = self.typeContent(for: typeContentStructure) else { return nil }
guard let typeContent = typeContent(for: typeContentStructure) else { return nil }
return (typeContent, typeContentStructure.offset!)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ internal extension Configuration.FileGraph {

// MARK: - Edge
struct Edge: Hashable {
// swiftlint:disable implicitly_unwrapped_optional
var parent: Vertex!
var child: Vertex!
// swiftlint:enable implicitly_unwrapped_optional
}

// MARK: - EdgeType
Expand Down
8 changes: 4 additions & 4 deletions Source/SwiftLintCore/Models/Linter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ public struct CollectedLinter {
$0 is SuperfluousDisableCommandRule
}) as? SuperfluousDisableCommandRule
let validationResults = rules.parallelCompactMap {
$0.lint(file: self.file, regions: regions, benchmark: benchmark,
$0.lint(file: file, regions: regions, benchmark: benchmark,
storage: storage,
configuration: self.configuration,
configuration: configuration,
superfluousDisableCommandRule: superfluousDisableCommandRule,
compilerArguments: self.compilerArguments)
compilerArguments: compilerArguments)
}
let undefinedSuperfluousCommandViolations = self.undefinedSuperfluousCommandViolations(
regions: regions, configuration: configuration,
Expand Down Expand Up @@ -265,7 +265,7 @@ public struct CollectedLinter {
}

private func cachedStyleViolations(benchmark: Bool = false) -> ([StyleViolation], [(id: String, time: Double)])? {
let start: Date! = benchmark ? Date() : nil
let start = Date()
guard let cache, let file = file.path,
let cachedViolations = cache.violations(forFile: file, configuration: configuration) else {
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,7 @@ extension ConfigurationElement: AnyConfigurationElement {

extension Optional: AcceptableByConfigurationElement where Wrapped: AcceptableByConfigurationElement {
public func asOption() -> OptionType {
if let value = self {
return value.asOption()
}
return .empty
self?.asOption() ?? .empty
}

public init(fromAny value: Any, context ruleID: String) throws {
Expand Down
10 changes: 5 additions & 5 deletions Source/SwiftLintCore/Reporters/SummaryReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ private extension TextTable {
self.init(columns: columns)

let ruleIdentifiersToViolationsMap = violations.group { $0.ruleIdentifier }
let sortedRuleIdentifiers = ruleIdentifiersToViolationsMap.keys.sorted {
let count1 = ruleIdentifiersToViolationsMap[$0]?.count ?? 0
let count2 = ruleIdentifiersToViolationsMap[$1]?.count ?? 0
let sortedRuleIdentifiers = ruleIdentifiersToViolationsMap.sorted { lhs, rhs in
let count1 = lhs.value.count
let count2 = rhs.value.count
if count1 > count2 {
return true
}
if count1 == count2 {
return $0 < $1
return lhs.key < rhs.key
}
return false
}
}.map(\.key)

var totalNumberOfWarnings = 0
var totalNumberOfErrors = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public struct RegexConfiguration<Parent: Rule>: SeverityBasedRuleConfiguration,
public var message = "Regex matched"
/// The regular expression to apply to trigger violations for this custom rule.
@ConfigurationElement(key: "regex")
var regex: RegularExpression!
var regex: RegularExpression! // swiftlint:disable:this implicitly_unwrapped_optional
/// Regular expressions to include when matching the file path.
public var included: [NSRegularExpression] = []
/// Regular expressions to exclude when matching the file path.
Expand Down
12 changes: 6 additions & 6 deletions Source/swiftlint/Helpers/CompilerArgumentsExtractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,22 @@ extension Array where Element == String {
(args, shouldContinueToFilterArguments) = partiallyFilter(arguments: args)
}

return args.filter {
return args.filter { arg in
![
"-parseable-output",
"-incremental",
"-serialize-diagnostics",
"-emit-dependencies",
"-use-frontend-parseable-output"
].contains($0)
}.map {
if $0 == "-O" {
].contains(arg)
}.map { arg in
if arg == "-O" {
return "-Onone"
}
if $0 == "-DNDEBUG=1" {
if arg == "-DNDEBUG=1" {
return "-DDEBUG=1"
}
return $0
return arg
}
}
}
Loading

0 comments on commit 7623f1e

Please sign in to comment.