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

Fix issue where linter would disallow "@unchecked Sendable" string in comments #241

Merged
merged 1 commit into from Sep 25, 2023

Conversation

calda
Copy link
Member

@calda calda commented Sep 25, 2023

This PR fixes an issue where the linter would not allow you to use the string @unchecked Sendable in a comment.

This was previously disallowed by the linter, because the regex matched the "@unchecked Sendable" text in the comment:

// Conform to @unchecked Sendable since the type is internally thread-safe
// swiftlint:disable:next no_unchecked_sendable
extension MyType: @unchecked Sendable

but is now allowed as expected

@@ -55,5 +55,8 @@ custom_rules:
no_unchecked_sendable:
name: "`@unchecked Sendable` is discouraged."
regex: "@unchecked Sendable"
match_kinds:
- attribute.builtin
- typeidentifier
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Determined this by using the command recommended in the SwiftLint documentation:

$ sourcekitten syntax --text "extension Foo: @unchecked Sendable { }"
[
  {
    "length" : 9,
    "offset" : 0,
    "type" : "source.lang.swift.syntaxtype.keyword"
  },
  {
    "length" : 3,
    "offset" : 10,
    "type" : "source.lang.swift.syntaxtype.typeidentifier"
  },
  {
    "length" : 10,
    "offset" : 15,
    "type" : "source.lang.swift.syntaxtype.attribute.builtin"
  },
  {
    "length" : 8,
    "offset" : 26,
    "type" : "source.lang.swift.syntaxtype.typeidentifier"
  }
]

Copy link
Contributor

@bachand bachand Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering how SwiftLint handled the fact that @unchecked Sendable matches both attribute.builtin and syntaxtype.typeidentifier. This seems like the answer.
Screenshot 2023-09-25 at 10 08 33 PM

Copy link
Contributor

@rholmes rholmes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@calda calda merged commit 0763661 into master Sep 25, 2023
3 checks passed
@calda calda deleted the cal--unchecked-sendable-comments branch September 25, 2023 21:06
Copy link
Contributor

@bachand bachand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @calda ! LGTM.

@@ -55,5 +55,8 @@ custom_rules:
no_unchecked_sendable:
name: "`@unchecked Sendable` is discouraged."
regex: "@unchecked Sendable"
match_kinds:
- attribute.builtin
- typeidentifier
Copy link
Contributor

@bachand bachand Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering how SwiftLint handled the fact that @unchecked Sendable matches both attribute.builtin and syntaxtype.typeidentifier. This seems like the answer.
Screenshot 2023-09-25 at 10 08 33 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants