Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macro exclusion for line_length missing #5648

Open
2 tasks done
Craz1k0ek opened this issue Jun 30, 2024 · 2 comments
Open
2 tasks done

Macro exclusion for line_length missing #5648

Craz1k0ek opened this issue Jun 30, 2024 · 2 comments
Labels
bug Unexpected and reproducible misbehavior. sourcekit-issue Issues that are caused by a misbehavior in SourceKit and need to be fixed upstream.

Comments

@Craz1k0ek
Copy link

New Issue Checklist

Describe the bug

I have a specific setting in my .swiftlint.yml to exclude function declarations

line_length:
  warning: 120
  error: 200
  ignores_function_declarations: true

However, this ignores the macro definitions

// Line Length Violation: Line should be 120 characters or less; currently it has 126 characters (line_length)
@freestanding(expression)
public macro obfuscate(_ value: String) -> String = #externalMacro(module: "ObfuscatedStringMacros", type: "ObfuscationMacro")
Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint

Gives me

Line Length Violation: Line should be 120 characters or less; currently it has 126 characters (line_length)

Environment

  • SwiftLint version (run swiftlint version to be sure)?
    0.55.1
  • Installation method used (Homebrew, CocoaPods, building from source, etc)?
    Homebrew
  • Paste your configuration file:
disabled_rules:
  - todo
  - trailing_comma
  - trailing_whitespace
opt_in_rules:
  - empty_count
line_length:
  warning: 120
  error: 200
  ignores_comments: true
  ignores_function_declarations: true
  ignores_interpolated_strings: true
  ignores_urls: true
  • Are you using nested configurations?
    If so, paste their relative paths and respective contents.
    No
  • Which Xcode version are you using (check xcodebuild -version)?
    Xcode 15.4
  • Do you have a sample that shows the issue? Run echo "[string here]" | swiftlint lint --no-cache --use-stdin --enable-all-rules
    to quickly test if your example is really demonstrating the issue. If your example is more
    complex, you can use swiftlint lint --path [file here] --no-cache --enable-all-rules.
    Create a macro using Xcode and run the linter to recreate the issue
// This triggers a violation:
@freestanding(expression)
public macro obfuscate(_ value: String) -> String = #externalMacro(module: "ObfuscatedStringMacros", type: "ObfuscationMacro")
@SimplyDanny SimplyDanny added the bug Unexpected and reproducible misbehavior. label Jul 1, 2024
@Craz1k0ek
Copy link
Author

Craz1k0ek commented Jul 2, 2024

I tried fixing this issue myself, but it appears the macro is not correctly parsed, but I can't figure out why. Parts of the code I added

if configuration.ignoresMacroDeclarations {
    print("Configuration set to ignore macros")
    if lineHasKinds(line: line, kinds: macroKinds, kindsByLine: swiftDeclarationKindsByLine.value) {
        print("Ignoring line \(line.index) due to macro declaration: \(line.content)")
        return nil
    } else {
        print("""
        Something went wrong, debug info
        ================================
        Checking line \(line.index): \(line.content)

        swiftDeclarationKindsByLine.value: \(swiftDeclarationKindsByLine.value)
        """)
    }
}

Outputs the following

Configuration set to ignore macros
Something went wrong, debug info
================================
Checking line 19: public macro obfuscate(_ value: String) -> String = #externalMacro(module: "ObfuscatedStringMacros", type: "ObfuscationMacro")

swiftDeclarationKindsByLine.value: [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [SourceKittenFramework.SwiftDeclarationKind.varParameter]]

This appears to be a SourceKitten issue. I've added an issue there.

@SimplyDanny
Copy link
Collaborator

This seems to be a SourceKit issue, see swiftlang/swift#66666.

@SimplyDanny SimplyDanny added the sourcekit-issue Issues that are caused by a misbehavior in SourceKit and need to be fixed upstream. label Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected and reproducible misbehavior. sourcekit-issue Issues that are caused by a misbehavior in SourceKit and need to be fixed upstream.
Projects
None yet
Development

No branches or pull requests

2 participants