-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ExplicitSelfRule] Fix violation location and misplaced corrections (#…
- Loading branch information
Showing
3 changed files
with
185 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
173 changes: 173 additions & 0 deletions
173
Source/SwiftLintFramework/Rules/Style/ExplicitSelfRuleExamples.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
struct ExplicitSelfRuleExamples { | ||
static let nonTriggeringExamples = [ | ||
Example(""" | ||
struct A { | ||
func f1() {} | ||
func f2() { | ||
self.f1() | ||
} | ||
} | ||
"""), | ||
Example(""" | ||
struct A { | ||
let p1: Int | ||
func f1() { | ||
_ = self.p1 | ||
} | ||
} | ||
"""), | ||
Example(""" | ||
@propertyWrapper | ||
struct Wrapper<Value> { | ||
let wrappedValue: Value | ||
var projectedValue: [Value] { | ||
[self.wrappedValue] | ||
} | ||
} | ||
struct A { | ||
@Wrapper var p1: Int | ||
func f1() { | ||
self.$p1 | ||
self._p1 | ||
} | ||
} | ||
func f1() { | ||
A(p1: 10).$p1 | ||
} | ||
""") | ||
] | ||
|
||
static let triggeringExamples = [ | ||
Example(""" | ||
struct A { | ||
func f1() {} | ||
func f2() { | ||
↓f1() | ||
} | ||
} | ||
"""), | ||
Example(""" | ||
struct A { | ||
let p1: Int | ||
func f1() { | ||
_ = ↓p1 | ||
} | ||
} | ||
"""), | ||
Example(""" | ||
struct A { | ||
func f1(a b: Int) {} | ||
func f2() { | ||
↓f1(a: 0) | ||
} | ||
} | ||
"""), | ||
Example(""" | ||
@propertyWrapper | ||
struct Wrapper<Value> { | ||
let wrappedValue: Value | ||
var projectedValue: [Value] { | ||
[self.wrappedValue] | ||
} | ||
} | ||
struct A { | ||
@Wrapper var p1: Int | ||
func f1() { | ||
↓$p1 | ||
↓_p1 | ||
} | ||
} | ||
func f1() { | ||
A(p1: 10).$p1 | ||
} | ||
""") | ||
] | ||
|
||
static let corrections = [ | ||
Example(""" | ||
struct A { | ||
func f1() {} | ||
func f2() { | ||
↓f1() | ||
} | ||
} | ||
"""): | ||
Example(""" | ||
struct A { | ||
func f1() {} | ||
func f2() { | ||
self.f1() | ||
} | ||
} | ||
"""), | ||
Example(""" | ||
struct A { | ||
let p1: Int | ||
func f1() { | ||
_ = ↓p1 | ||
} | ||
} | ||
"""): | ||
Example(""" | ||
struct A { | ||
let p1: Int | ||
func f1() { | ||
_ = self.p1 | ||
} | ||
} | ||
"""), | ||
Example(""" | ||
struct A { | ||
func f1(a b: Int) {} | ||
func f2() { | ||
↓f1(a: 0) | ||
} | ||
} | ||
"""): | ||
Example(""" | ||
struct A { | ||
func f1(a b: Int) {} | ||
func f2() { | ||
self.f1(a: 0) | ||
} | ||
} | ||
"""), | ||
Example(""" | ||
@propertyWrapper | ||
struct Wrapper<Value> { | ||
let wrappedValue: Value | ||
var projectedValue: [Value] { | ||
[self.wrappedValue] | ||
} | ||
} | ||
struct A { | ||
@Wrapper var p1: Int | ||
func f1() { | ||
↓$p1 | ||
↓_p1 | ||
} | ||
} | ||
func f1() { | ||
A(p1: 10).$p1 | ||
} | ||
"""): Example(""" | ||
@propertyWrapper | ||
struct Wrapper<Value> { | ||
let wrappedValue: Value | ||
var projectedValue: [Value] { | ||
[self.wrappedValue] | ||
} | ||
} | ||
struct A { | ||
@Wrapper var p1: Int | ||
func f1() { | ||
self.$p1 | ||
self._p1 | ||
} | ||
} | ||
func f1() { | ||
A(p1: 10).$p1 | ||
} | ||
""") | ||
] | ||
} |