mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
Fix line count calculation for multiline string literals (#4587)
Fixes https://github.com/realm/SwiftLint/issues/4585 Update body length rule thresholds for SwiftLint
This commit is contained in:
@@ -88,6 +88,9 @@ file_name:
|
||||
- GeneratedTests.swift
|
||||
- TestHelpers.swift
|
||||
|
||||
function_body_length: 60
|
||||
type_body_length: 400
|
||||
|
||||
custom_rules:
|
||||
rule_id:
|
||||
included: Source/SwiftLintFramework/Rules/.+/\w+\.swift
|
||||
|
||||
@@ -35,6 +35,10 @@
|
||||
[JP Simard](https://github.com/jpsim)
|
||||
[#4582](https://github.com/realm/SwiftLint/issues/4582)
|
||||
|
||||
* Fix line count calculation for multiline string literals.
|
||||
[JP Simard](https://github.com/jpsim)
|
||||
[#4585](https://github.com/realm/SwiftLint/issues/4585)
|
||||
|
||||
## 0.50.0: Artisanal Clothes Pegs
|
||||
|
||||
#### Breaking
|
||||
|
||||
@@ -43,7 +43,12 @@ extension SwiftLintFile {
|
||||
return syntaxTree
|
||||
.tokens(viewMode: .sourceAccurate)
|
||||
.reduce(into: []) { linesWithTokens, token in
|
||||
if let line = locationConverter.location(for: token.positionAfterSkippingLeadingTrivia).line {
|
||||
if case .stringSegment = token.tokenKind {
|
||||
let sourceRange = token.withoutTrivia().sourceRange(converter: locationConverter)
|
||||
let startLine = sourceRange.start.line!
|
||||
let endLine = sourceRange.end.line!
|
||||
linesWithTokens.formUnion(startLine...endLine)
|
||||
} else if let line = locationConverter.location(for: token.positionAfterSkippingLeadingTrivia).line {
|
||||
linesWithTokens.insert(line)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ struct FileTypesOrderRule: ConfigurationProviderRule, OptInRule {
|
||||
triggeringExamples: FileTypesOrderRuleExamples.triggeringExamples
|
||||
)
|
||||
|
||||
// swiftlint:disable:next function_body_length
|
||||
func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||
guard let mainTypeSubstructure = mainTypeSubstructure(in: file),
|
||||
let mainTypeSubstuctureOffset = mainTypeSubstructure.offset else { return [] }
|
||||
|
||||
@@ -24,7 +24,6 @@ struct IdentifierNameRule: ASTRule, ConfigurationProviderRule {
|
||||
deprecatedAliases: ["variable_name"]
|
||||
)
|
||||
|
||||
// swiftlint:disable:next function_body_length
|
||||
func validate(
|
||||
file: SwiftLintFile,
|
||||
kind: SwiftDeclarationKind,
|
||||
|
||||
@@ -76,7 +76,7 @@ struct TypeContentsOrderRule: ConfigurationProviderRule, OptInRule {
|
||||
}
|
||||
}
|
||||
|
||||
// swiftlint:disable:next cyclomatic_complexity function_body_length
|
||||
// swiftlint:disable:next cyclomatic_complexity
|
||||
private func typeContent(for typeContentStructure: SourceKittenDictionary) -> TypeContent? {
|
||||
guard let typeContentKind = typeContentStructure.declarationKind else { return nil }
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
import XCTest
|
||||
|
||||
class ColonRuleTests: XCTestCase {
|
||||
// swiftlint:disable:next function_body_length
|
||||
func testColonWithFlexibleRightSpace() {
|
||||
// Verify Colon rule with test values for when flexible_right_spacing
|
||||
// is true.
|
||||
@@ -69,7 +68,6 @@ class ColonRuleTests: XCTestCase {
|
||||
verifyRule(description, ruleConfiguration: ["flexible_right_spacing": true])
|
||||
}
|
||||
|
||||
// swiftlint:disable:next function_body_length
|
||||
func testColonWithoutApplyToDictionaries() {
|
||||
let nonTriggeringExamples = ColonRule.description.nonTriggeringExamples + [
|
||||
Example("let abc = [Void:Void]()\n"),
|
||||
|
||||
@@ -3,8 +3,6 @@ import SourceKittenFramework
|
||||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
// swiftlint:disable type_body_length - Disable the rule and self-test commenting a command
|
||||
|
||||
private extension Command {
|
||||
init?(string: String) {
|
||||
let nsString = string.bridge()
|
||||
|
||||
@@ -3,7 +3,7 @@ import SourceKittenFramework
|
||||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
// swiftlint:disable file_length type_body_length
|
||||
// swiftlint:disable file_length
|
||||
|
||||
private let optInRules = primaryRuleList.list.filter({ $0.1.init() is OptInRule }).map({ $0.0 })
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import XCTest
|
||||
|
||||
class FileTypesOrderRuleTests: XCTestCase {
|
||||
// swiftlint:disable:next function_body_length
|
||||
func testFileTypesOrderReversedOrder() {
|
||||
// Test with reversed `order` entries
|
||||
let nonTriggeringExamples = [
|
||||
|
||||
@@ -66,6 +66,7 @@ class ModifierOrderTests: XCTestCase {
|
||||
"override"]])
|
||||
}
|
||||
|
||||
// swiftlint:disable:next function_body_length
|
||||
func testAtPrefixedGroup() {
|
||||
let descriptionOverride = ModifierOrderRule.description
|
||||
.with(nonTriggeringExamples: [
|
||||
@@ -215,6 +216,7 @@ class ModifierOrderTests: XCTestCase {
|
||||
ruleConfiguration: ["preferred_modifier_order": ["final", "override", "acl"]])
|
||||
}
|
||||
|
||||
// swiftlint:disable:next function_body_length
|
||||
func testCorrectionsAreAppliedCorrectly() {
|
||||
let descriptionOverride = ModifierOrderRule.description
|
||||
.with(nonTriggeringExamples: [], triggeringExamples: [])
|
||||
@@ -281,6 +283,7 @@ class ModifierOrderTests: XCTestCase {
|
||||
ruleConfiguration: ["preferred_modifier_order": ["final", "override", "acl", "typeMethods"]])
|
||||
}
|
||||
|
||||
// swiftlint:disable:next function_body_length
|
||||
func testCorrectionsAreNotAppliedToIrrelevantModifier() {
|
||||
let descriptionOverride = ModifierOrderRule.description
|
||||
.with(nonTriggeringExamples: [], triggeringExamples: [])
|
||||
|
||||
@@ -2,8 +2,6 @@ import SourceKittenFramework
|
||||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
// swiftlint:disable type_body_length
|
||||
|
||||
class RuleConfigurationTests: XCTestCase {
|
||||
func testNameConfigurationSetsCorrectly() {
|
||||
let config = [ "min_length": ["warning": 17, "error": 7],
|
||||
|
||||
@@ -451,7 +451,6 @@ public extension XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
// swiftlint:disable:next function_body_length
|
||||
private func verifyExamples(triggers: [Example], nonTriggers: [Example],
|
||||
configuration config: Configuration, requiresFileOnDisk: Bool,
|
||||
file callSiteFile: StaticString = #file,
|
||||
|
||||
Reference in New Issue
Block a user