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

Rule Request: identifier_name customization allow 'id' when type is conforming to Identifiable protocol #3651

Closed
2 tasks done
edorphy opened this issue Jun 7, 2021 · 2 comments · Fixed by #3730
Closed
2 tasks done

Comments

@edorphy
Copy link

edorphy commented Jun 7, 2021

New Issue Checklist

New rule request

Please describe the rule idea, format
this issue's title as Rule Request: [Rule Name] and describe:

  1. Why should this rule be added? Share links to existing discussion about what
    the community thinks about this.

Swift has introduced a very commonly used protocol named Identifiable. It is used all over the place in SwiftUI. Out of the box, this id should be allowed when type conforms to the protocol. As a user of the library, I don't want to have to have to configure the exclusion list for this rule to include id because that could potentially allow real issues to slip through.

  1. Provide several examples of what would and wouldn't trigger violations.

Shouldn't trigger

struct TaproomAnnotation: Identifiable {
    let id: UUID = UUID()
    let coordinate: CLLocationCoordinate2D
}

Should trigger

struct TaproomAnnotation {
    let id: UUID = UUID()
    let coordinate: CLLocationCoordinate2D
}
  1. Should the rule be configurable, if so what parameters should be configurable?

Yes, this is a proposal to allow a configuration point for the existing identifier_name rule. There would be benefits to catch names that are id outside of Identifiable types that should still flag as a warning.

  1. Should the rule be opt-in or enabled by default? Why?

Enabled by default, it is part of the SwiftUI framework. Unlikely that Apple will break their protocol at this point and rename id to identifier.

@72A12F4E
Copy link

I've looked into what it might take to make this work. I'm stuck at the point where I need to get the enclosing type's information for the variable declaration being linted, but I'm not sure how to really do that.

My branch is here if anyone wants to take a look.

https://github.com/72A12F4E/SwiftLint/tree/fix_identifier_name_identifiable

@agarmash
Copy link
Contributor

agarmash commented Oct 4, 2021

I believe it's a good idea to exclude id from this rule by default since it's a well-established term in programming

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

Successfully merging a pull request may close this issue.

3 participants