github / eslint-plugin-github

An opinionated collection of ESLint rules used by GitHub.
MIT License
286 stars 51 forks source link

Add polymorphic component check in `getElementType` #449

Closed kendallgassner closed 11 months ago

kendallgassner commented 11 months ago

What

Refine how we check the semantics of custom component. Allow polymorphicPropName to be passed in via the settings field. This allows linting configurations to customize the propname they use for polymorphic components.

{
  "settings": {
    "github": {
      "polymorphicPropName": "asChild",
      "components": {
        "Box": "p",
        "Link": "a"
      }
    }
  }
}

Open questions

  1. Would we ever want to allow multiple polymorphicPropName? ['as', 'asChild']?
  2. Do we want to recursiely check the components map? i.e. Box => a (this is implemented but might be overkill)
        "components": {
          "Box": "Link",
          "Link": "a"
        }
kendallgassner commented 11 months ago

@khiga Regarding your comment on question 2, I will switch to the 1:1 mapping and we can add in the recursive nature if we find that its needed.

kendallgassner commented 11 months ago

@TylerJDev @khiga8 I will follow up in a new pr if we find that we need multiple as types:

"polymorphicPropName": ["asChild", "as"]