Run SwiftSyntax-mode custom rules without SourceKit - #6847
Draft
bprinsta wants to merge 1 commit into
Draft
Conversation
`execution_mode: swiftsyntax` only affected how `custom_rules` was classified: `isEffectivelySourceKitFree` reported the rule as SourceKit-free, but `validate` still resolved syntax kinds through the SourceKit-backed syntax map. With SourceKit access prohibited (the fully static Linux binary or `--disable-sourcekit`), SwiftSyntax-mode rules therefore crashed with "SourceKit is disabled by configuration" instead of linting. Derive syntax kinds from SwiftSyntax classifications via the existing SwiftSyntaxKindBridge when a custom rule's effective execution mode is `swiftsyntax`, leaving the SourceKit path untouched for rules in SourceKit mode. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Generated by 🚫 Danger |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes (partially) #6129.
execution_mode: swiftsyntax(#6128) currently only affects howcustom_rulesis classified:CustomRules.isEffectivelySourceKitFreereports the rule as SourceKit-free, butvalidatestill matches viafile.match(pattern:excludingSyntaxKinds:), which readsfile.syntaxMap— a SourceKit request.This has two consequences when SourceKit access is prohibited (the fully static Linux binary built with
SWIFTLINT_DISABLE_SOURCEKIT, or--disable-sourcekit):custom_rulesgroup get skipped withSkipping enabled rule 'custom_rules' because it requires SourceKit and SourceKit access is prohibited.— expected, but it means pure-regex custom rules cannot run on the static Linux binary at all.swiftsyntaxmode crash the process: the skip-gate opens because the rule claims to be SourceKit-free, then the first match hitsRequest.sendIfNotDisabled()→queuedFatalError("SourceKit is disabled by configuration.")(exit 134).Repro for the crash on 0.63.2–0.65.0:
SwiftSyntaxKindBridgealready exists to serve exactly this purpose but nothing calls it. This PR wires it in:CustomRules.validateresolves each rule's effective execution mode (shared withisEffectivelySourceKitFreevia a newCustomRulesConfiguration.effectiveExecutionMode(for:)) and, forswiftsyntax-mode rules, matches with syntax kinds derived from SwiftSyntax classifications instead of SourceKit.SwiftLintFile.matchWithSwiftSyntaxKinds(pattern:excludingSyntaxKinds:range:captureGroup:)implements the SourceKit-free variant, reusing the existing match plumbing with aSwiftLintSyntaxMapbuilt fromswiftSyntaxDerivedSourceKittenTokens.SwiftLintSyntaxMapgains apackage init(tokens:).match_kinds/excluded_match_kindsfiltering works in both modes; kinds in SwiftSyntax mode come fromSwiftSyntaxKindBridge.mapClassification, so results can differ slightly from SourceKit's syntax map in edge cases (as documented on the bridge).Tests: two new tests in
CustomRulesTestsrun swiftsyntax-mode rules (with and withoutmatch_kinds) underRequest.disableSourceKitOverride = true— both crash before this change.