Commit f281814
committed
Migrate Custom Rules from SourceKit to SwiftSyntax
**Breaking Change**: Custom rules now default to SwiftSyntax mode for pattern matching.
This provides significant performance improvements but may have subtle behavioral differences
from the previous SourceKit implementation. Users should test their custom rules and adjust
as needed. A temporary `sourcekit` mode is available for rules that cannot be migrated yet.
## Breaking Change Details
- **New Default**: Custom rules now use `swiftsyntax` mode by default
- **Legacy Option**: Set `mode: sourcekit` or `default_execution_mode: sourcekit` to
restore previous behavior temporarily
- **Action Required**: Test your custom rules after upgrading and migrate to SwiftSyntax
mode where possible
## Configuration
Control execution mode at two levels:
```yaml
custom_rules:
# To restore previous behavior for all rules (temporary):
default_execution_mode: sourcekit
my_rule:
regex: "pattern"
# Defaults to swiftsyntax now
legacy_rule:
regex: "pattern"
mode: sourcekit # Use legacy mode for specific rules
```
## Why This Change?
- **Performance**: SwiftSyntax mode eliminates SourceKit process overhead
- **Reliability**: No more SourceKit crashes or hangs
- **Future-Proof**: SwiftLint is migrating away from SourceKit entirely
## Migration Guide
1. **Test First**: Run your existing custom rules and check for differences
2. **Adjust Rules**: Most rules should work identically in SwiftSyntax mode
3. **Use Legacy Mode**: For rules that must maintain exact SourceKit behavior,
set `mode: sourcekit` temporarily
4. **Report Issues**: Help us improve SwiftSyntax mode by reporting incompatibilities
## Technical Implementation
### SwiftSyntaxKindBridge
Enables kind filtering (`match_kinds`/`excluded_match_kinds`) without SourceKit:
- Maps SwiftSyntax classifications to SourceKit syntax kinds
- Covers common use cases with best-effort compatibility
- Some edge cases may differ from SourceKit behavior
### ConditionallySourceKitFree Protocol
Allows CustomRules to skip SourceKit initialization when all rules use SwiftSyntax:
- Dramatic performance improvement when SourceKit isn't needed
- Maintains SourceKit availability for legacy rules
## Important Notes
- **Not Full Compatibility**: While we've worked to maintain compatibility, differences
exist. Test thoroughly.
- **Temporary Legacy Support**: The `sourcekit` mode is a temporary measure. Plan to
migrate all rules to SwiftSyntax.
- **Future Deprecation**: SourceKit mode will be removed in a future version.
## Benefits of Migrating
- Faster linting (no SourceKit startup cost)
- Lower memory usage
- Better reliability (no SourceKit crashes)
- Future-proof your configuration
This change represents a major step in SwiftLint's evolution toward a fully SwiftSyntax-based
architecture. We encourage all users to test and migrate their custom rules to the new
SwiftSyntax mode, using the legacy SourceKit mode only as a temporary measure for rules
that cannot yet be migrated.1 parent ab7d117 commit f281814
File tree
5 files changed
+471
-7
lines changed- Source
- SwiftLintCore/Extensions
- SwiftLintFramework/Rules
- Tests/FrameworkTests
5 files changed
+471
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
14 | 22 | | |
15 | 23 | | |
16 | 24 | | |
| |||
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
15 | 29 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
106 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
107 | 150 | | |
108 | 151 | | |
109 | 152 | | |
| |||
134 | 177 | | |
135 | 178 | | |
136 | 179 | | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | 14 | | |
21 | 15 | | |
22 | 16 | | |
| |||
0 commit comments