Compare commits
8 Commits
main
...
release-0.
Author | SHA1 | Date |
---|---|---|
![]() |
e8ef21fef6 | |
![]() |
169542a3e2 | |
![]() |
2eca7783b3 | |
![]() |
e8dc313d8b | |
![]() |
9445e676d2 | |
![]() |
8023f36485 | |
![]() |
052708b82c | |
![]() |
17026c12b1 |
22
CHANGELOG.md
22
CHANGELOG.md
|
@ -1,4 +1,4 @@
|
|||
## Master
|
||||
## 0.46.5: Laundry Studio
|
||||
|
||||
#### Breaking
|
||||
|
||||
|
@ -14,7 +14,25 @@
|
|||
|
||||
#### Bug Fixes
|
||||
|
||||
* None.
|
||||
* Fix `empty_parentheses_with_trailing_closure` rule when using Swift 5.6.
|
||||
[Marcelo Fabri](https://github.com/marcelofabri)
|
||||
[#3846](https://github.com/realm/SwiftLint/issues/3846)
|
||||
|
||||
* Fix false negatives in `closure_parameter_position` rule with Swift 5.6.
|
||||
[Marcelo Fabri](https://github.com/marcelofabri)
|
||||
[#3845](https://github.com/realm/SwiftLint/issues/3845)
|
||||
|
||||
* Fix regression in `last_where` rule when using Swift 5.6.
|
||||
[Marcelo Fabri](https://github.com/marcelofabri)
|
||||
[#3847](https://github.com/realm/SwiftLint/issues/3847)
|
||||
|
||||
* Fix regression in `unused_import` rule when using Swift 5.6.
|
||||
[JP Simard](https://github.com/jpsim)
|
||||
[#3849](https://github.com/realm/SwiftLint/issues/3849)
|
||||
|
||||
* Fix regression in `trailing_closure` rule when using Swift 5.6.
|
||||
[Marcelo Fabri](https://github.com/marcelofabri)
|
||||
[#3848](https://github.com/realm/SwiftLint/issues/3848)
|
||||
|
||||
## 0.46.4: Detergent Tray
|
||||
|
||||
|
|
2
Makefile
2
Makefile
|
@ -158,7 +158,7 @@ endif
|
|||
@sed 's/__VERSION__/$(NEW_VERSION)/g' script/Version.swift.template > Source/SwiftLintFramework/Models/Version.swift
|
||||
git commit -a -m "release $(NEW_VERSION)"
|
||||
git tag -a $(NEW_VERSION) -m "$(NEW_VERSION_AND_NAME)"
|
||||
git push origin master
|
||||
git push origin HEAD
|
||||
git push origin $(NEW_VERSION)
|
||||
|
||||
%:
|
||||
|
|
|
@ -4,5 +4,5 @@ public struct Version {
|
|||
public let value: String
|
||||
|
||||
/// The current SwiftLint version.
|
||||
public static let current = Version(value: "0.46.4")
|
||||
public static let current = Version(value: "0.46.5")
|
||||
}
|
||||
|
|
|
@ -105,6 +105,10 @@ private extension SwiftLintFile {
|
|||
// Always disallow 'Swift' and 'SwiftShims' because they're always available without importing.
|
||||
usrFragments.remove("Swift")
|
||||
usrFragments.remove("SwiftShims")
|
||||
if SwiftVersion.current >= .fiveDotSix {
|
||||
usrFragments.remove("main")
|
||||
}
|
||||
|
||||
var unusedImports = imports.subtracting(usrFragments).subtracting(configuration.alwaysKeepImports)
|
||||
// Certain Swift attributes requires importing Foundation.
|
||||
if unusedImports.contains("Foundation") && containsAttributesRequiringFoundation() {
|
||||
|
|
|
@ -35,7 +35,19 @@ public struct LastWhereRule: CallPairRule, OptInRule, ConfigurationProviderRule,
|
|||
patternSyntaxKinds: [.identifier],
|
||||
callNameSuffix: ".filter",
|
||||
severity: configuration.severity) { dictionary in
|
||||
if dictionary.substructure.isNotEmpty {
|
||||
let substructure: [SourceKittenDictionary] = {
|
||||
if SwiftVersion.current >= .fiveDotSix {
|
||||
return dictionary.substructure.flatMap { dict -> [SourceKittenDictionary] in
|
||||
if dict.expressionKind == .argument {
|
||||
return dict.substructure
|
||||
}
|
||||
return [dict]
|
||||
}
|
||||
}
|
||||
|
||||
return dictionary.substructure
|
||||
}()
|
||||
if substructure.isNotEmpty {
|
||||
return true // has a substructure, like a closure
|
||||
}
|
||||
|
||||
|
|
|
@ -112,16 +112,23 @@ public struct ClosureParameterPositionRule: ASTRule, ConfigurationProviderRule,
|
|||
return []
|
||||
}
|
||||
|
||||
guard let nameOffset = dictionary.nameOffset,
|
||||
let nameLength = dictionary.nameLength,
|
||||
let bodyLength = dictionary.bodyLength,
|
||||
guard let bodyLength = dictionary.bodyLength,
|
||||
bodyLength > 0
|
||||
else {
|
||||
return []
|
||||
}
|
||||
|
||||
let parameters = dictionary.enclosedVarParameters +
|
||||
dictionary.substructure.filter { $0.declarationKind == .varLocal } // capture lists
|
||||
let nameOffset = dictionary.nameOffset ?? 0
|
||||
let nameLength = dictionary.nameLength ?? 0
|
||||
|
||||
let captureLists = dictionary.substructure.flatMap { dict -> [SourceKittenDictionary] in
|
||||
if SwiftVersion.current >= .fiveDotSix, dict.expressionKind == .argument {
|
||||
return dict.substructure.filter { $0.declarationKind == .varLocal }
|
||||
}
|
||||
|
||||
return dict.declarationKind == .varLocal ? [dict] : []
|
||||
}
|
||||
let parameters = dictionary.enclosedVarParameters + captureLists
|
||||
let rangeStart = nameOffset + nameLength
|
||||
let regex = Self.openBraceRegex
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ public struct EmptyParenthesesWithTrailingClosureRule: SubstitutionCorrectableAS
|
|||
|
||||
// avoid the more expensive regex match if there's no trailing closure in the substructure
|
||||
if SwiftVersion.current >= .fourDotTwo,
|
||||
dictionary.substructure.last?.expressionKind != .closure {
|
||||
!dictionary.hasTrailingClosure {
|
||||
return []
|
||||
}
|
||||
|
||||
|
@ -99,3 +99,17 @@ public struct EmptyParenthesesWithTrailingClosureRule: SubstitutionCorrectableAS
|
|||
return [match]
|
||||
}
|
||||
}
|
||||
|
||||
private extension SourceKittenDictionary {
|
||||
var hasTrailingClosure: Bool {
|
||||
guard let lastStructure = substructure.last else {
|
||||
return false
|
||||
}
|
||||
|
||||
if SwiftVersion.current >= .fiveDotSix, lastStructure.expressionKind == .argument {
|
||||
return lastStructure.substructure.last?.expressionKind == .closure
|
||||
} else {
|
||||
return lastStructure.expressionKind == .closure
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,16 +10,8 @@ public struct PreferSelfInStaticReferencesRule: SubstitutionCorrectableASTRule,
|
|||
nonTriggeringExamples: [
|
||||
Example("""
|
||||
class C {
|
||||
static private(set) var i = 0, j = C.i
|
||||
let h = C.i
|
||||
@GreaterThan(C.j) var k: Int
|
||||
}
|
||||
"""),
|
||||
Example("""
|
||||
class `Self` {
|
||||
static let i = 0
|
||||
func f() -> Int { Self.i }
|
||||
}
|
||||
static let primes = [2, 3, 5, 7]
|
||||
func isPrime(i: Int) -> Bool { Self.primes.contains(i) }
|
||||
"""),
|
||||
Example("""
|
||||
struct T {
|
||||
|
@ -29,9 +21,24 @@ public struct PreferSelfInStaticReferencesRule: SubstitutionCorrectableASTRule,
|
|||
static let i = 0
|
||||
}
|
||||
extension T {
|
||||
static let j = S.i + Self.i
|
||||
static let j = S.i + T.i
|
||||
static let k = { T.j }()
|
||||
}
|
||||
"""),
|
||||
Example("""
|
||||
class `Self` {
|
||||
static let i = 0
|
||||
func f() -> Int { Self.i }
|
||||
}
|
||||
"""),
|
||||
Example("""
|
||||
class C {
|
||||
static private(set) var i = 0, j = C.i
|
||||
static let k = { C.i }()
|
||||
let h = C.i
|
||||
@GreaterThan(C.j) var k: Int
|
||||
}
|
||||
""", excludeFromDocumentation: true),
|
||||
Example("""
|
||||
struct S {
|
||||
struct T {
|
||||
|
@ -45,7 +52,7 @@ public struct PreferSelfInStaticReferencesRule: SubstitutionCorrectableASTRule,
|
|||
static let j = Self.T.R.i + Self.R.j
|
||||
let h = Self.T.R.i + Self.R.j
|
||||
}
|
||||
"""),
|
||||
""", excludeFromDocumentation: true),
|
||||
Example("""
|
||||
class C {
|
||||
static let s = 2
|
||||
|
@ -55,31 +62,9 @@ public struct PreferSelfInStaticReferencesRule: SubstitutionCorrectableASTRule,
|
|||
}
|
||||
func g() -> Any { C.self }
|
||||
}
|
||||
"""),
|
||||
Example("""
|
||||
struct S {
|
||||
static let i = 1
|
||||
static let j = { Self.i }()
|
||||
}
|
||||
extension S {
|
||||
static let k = { S.j }()
|
||||
}
|
||||
""")
|
||||
""", excludeFromDocumentation: true)
|
||||
],
|
||||
triggeringExamples: [
|
||||
Example("""
|
||||
struct C {
|
||||
static let i = 0
|
||||
static let j = ↓C.i
|
||||
}
|
||||
"""),
|
||||
Example("""
|
||||
struct S {
|
||||
static let i = 0
|
||||
func f() -> Int { ↓S.i }
|
||||
func g() -> Any { ↓S.self }
|
||||
}
|
||||
"""),
|
||||
Example("""
|
||||
class C {
|
||||
struct S {
|
||||
|
@ -88,8 +73,16 @@ public struct PreferSelfInStaticReferencesRule: SubstitutionCorrectableASTRule,
|
|||
}
|
||||
static let i = 1
|
||||
let h = C.i
|
||||
func f() -> Int { ↓C.i + h }
|
||||
}
|
||||
"""),
|
||||
Example("""
|
||||
struct S {
|
||||
static let i = 1
|
||||
static func f() -> Int { ↓S.i }
|
||||
func g() -> Any { ↓S.self }
|
||||
}
|
||||
"""),
|
||||
Example("""
|
||||
struct S {
|
||||
struct T {
|
||||
|
@ -105,28 +98,19 @@ public struct PreferSelfInStaticReferencesRule: SubstitutionCorrectableASTRule,
|
|||
corrections: [
|
||||
Example("""
|
||||
struct S {
|
||||
struct T {
|
||||
static let i = 3
|
||||
}
|
||||
static let h = ↓S.T.i
|
||||
static let i = 1
|
||||
static let j = ↓S.i
|
||||
let k = ↓S.j
|
||||
static func f(_ l: Int = ↓S.i) -> Int { l*↓S.j }
|
||||
func g() { ↓S.i + ↓S.f() + k }
|
||||
}
|
||||
"""): Example("""
|
||||
struct S {
|
||||
struct T {
|
||||
static let i = 3
|
||||
}
|
||||
static let h = Self.T.i
|
||||
}
|
||||
"""),
|
||||
Example("""
|
||||
class S {
|
||||
static func f() { ↓S.g(↓S.f) }
|
||||
static func g(f: () -> Void) { f() }
|
||||
}
|
||||
"""): Example("""
|
||||
class S {
|
||||
static func f() { Self.g(Self.f) }
|
||||
static func g(f: () -> Void) { f() }
|
||||
static let i = 1
|
||||
static let j = Self.i
|
||||
let k = Self.j
|
||||
static func f(_ l: Int = Self.i) -> Int { l*Self.j }
|
||||
func g() { Self.i + Self.f() + k }
|
||||
}
|
||||
""")
|
||||
]
|
||||
|
|
|
@ -82,8 +82,16 @@ public struct TrailingClosureRule: OptInRule, ConfigurationProviderRule {
|
|||
return shouldTrigger()
|
||||
}
|
||||
|
||||
let argumentsCountIsExpected: Bool = {
|
||||
if SwiftVersion.current >= .fiveDotSix, arguments.count == 1,
|
||||
arguments[0].expressionKind == .argument {
|
||||
return true
|
||||
}
|
||||
|
||||
return arguments.isEmpty
|
||||
}()
|
||||
// check if there's only one unnamed parameter that is a closure
|
||||
if arguments.isEmpty,
|
||||
if argumentsCountIsExpected,
|
||||
let offset = dictionary.offset,
|
||||
let totalLength = dictionary.length,
|
||||
let nameOffset = dictionary.nameOffset,
|
||||
|
|
Loading…
Reference in New Issue