-
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.
Configure expression folding by argument of @SwiftSyntaxRule macro (#…
- Loading branch information
1 parent
4716f59
commit f6e5f77
Showing
12 changed files
with
144 additions
and
91 deletions.
There are no files selected for viewing
3 changes: 1 addition & 2 deletions
3
Source/SwiftLintBuiltInRules/Rules/Idiomatic/LegacyMultipleRule.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
3 changes: 1 addition & 2 deletions
3
Source/SwiftLintBuiltInRules/Rules/Lint/IdenticalOperandsRule.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
3 changes: 1 addition & 2 deletions
3
Source/SwiftLintBuiltInRules/Rules/Performance/ContainsOverFirstNotNilRule.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
3 changes: 1 addition & 2 deletions
3
Source/SwiftLintBuiltInRules/Rules/Performance/ContainsOverRangeNilComparisonRule.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
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
3 changes: 1 addition & 2 deletions
3
Source/SwiftLintBuiltInRules/Rules/Style/ShorthandOperatorRule.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
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 was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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,97 @@ | ||
@testable import SwiftLintCoreMacros | ||
import SwiftSyntaxMacrosTestSupport | ||
import XCTest | ||
|
||
private let macros = [ | ||
"SwiftSyntaxRule": SwiftSyntaxRule.self | ||
] | ||
|
||
final class SwiftSyntaxRuleTests: XCTestCase { | ||
func testNoFoldArgument() { | ||
assertMacroExpansion( | ||
""" | ||
@SwiftSyntaxRule | ||
struct Hello {} | ||
""", | ||
expandedSource: """ | ||
struct Hello {} | ||
extension Hello: SwiftSyntaxRule { | ||
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor { | ||
Visitor(viewMode: .sourceAccurate) | ||
} | ||
} | ||
""", | ||
macros: macros | ||
) | ||
} | ||
|
||
func testFalseFoldArgument() { | ||
assertMacroExpansion( | ||
""" | ||
@SwiftSyntaxRule(foldExpressions: false) | ||
struct Hello {} | ||
""", | ||
expandedSource: """ | ||
struct Hello {} | ||
extension Hello: SwiftSyntaxRule { | ||
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor { | ||
Visitor(viewMode: .sourceAccurate) | ||
} | ||
} | ||
""", | ||
macros: macros | ||
) | ||
} | ||
|
||
func testTrueFoldArgument() { | ||
assertMacroExpansion( | ||
""" | ||
@SwiftSyntaxRule(foldExpressions: true) | ||
struct Hello {} | ||
""", | ||
expandedSource: """ | ||
struct Hello {} | ||
extension Hello: SwiftSyntaxRule { | ||
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor { | ||
Visitor(viewMode: .sourceAccurate) | ||
} | ||
func preprocess(file: SwiftLintFile) -> SourceFileSyntax? { | ||
file.foldedSyntaxTree | ||
} | ||
} | ||
""", | ||
macros: macros | ||
) | ||
} | ||
|
||
func testArbitraryFoldArgument() { | ||
assertMacroExpansion( | ||
""" | ||
@SwiftSyntaxRule(foldExpressions: variable) | ||
struct Hello {} | ||
""", | ||
expandedSource: """ | ||
struct Hello {} | ||
extension Hello: SwiftSyntaxRule { | ||
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor { | ||
Visitor(viewMode: .sourceAccurate) | ||
} | ||
func preprocess(file: SwiftLintFile) -> SourceFileSyntax? { | ||
if variable { | ||
file.foldedSyntaxTree | ||
} else { | ||
nil | ||
} | ||
} | ||
} | ||
""", | ||
macros: macros | ||
) | ||
} | ||
} |