Skip to content

Provide component mapping for github/react preset #34

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

Merged
merged 8 commits into from
Jul 25, 2022

Conversation

khiga8
Copy link
Contributor

@khiga8 khiga8 commented Jul 22, 2022

Context

The latest release of github/eslint-plugin-github includes a new React preset which will be recommended to GitHub React projects. This React preset currently:

  • extends the jsx-a11y plugin to ensure React projects always include the accessibility rules.
  • includes custom JSX accessibility rules

We want the JSX linters to also run on relevant components. For instance, we have a rule that discourages generic link text should also run on <Link>. For greater coverage, eslint-plugin-github added a component mapping configuration that allows custom components (with relevant props) to be treated as a given HTML element.

Update

I am adding the component mapping config for github/react here.

Providing this config here will minimize the need for Primer React consumers to define their own component mappings.

To reviewer

Upcoming work

We should provide component mappings for jsx-a11y too since that plugin similarly supports component to HTML element mapping. Without it, none of the React components will have accessibility linting coverage. You can read more about this mapping setting for jsx-a11y at the end of this section. Notably, this jsx-a11y setting is less robust since it only allows a 1:1 mapping versus the configuration we created for eslint-plugin-github.

@changeset-bot
Copy link

changeset-bot bot commented Jul 22, 2022

🦋 Changeset detected

Latest commit: a398c56

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-primer-react Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@khiga8
Copy link
Contributor Author

khiga8 commented Jul 22, 2022

Hmm I think this config will have a dependency on eslint-plugin-github and eslint-plugin-jsx-a11y plugin (since github/react preset includes it).

do you think I should pull this out into a separate config from primer-react/recommended. maybe have a primer-react/github? Or is this fine? Not sure what practices around ESLint config organization is.

@colebemis
Copy link
Contributor

@khiga8 It seems reasonable to include this in the primer-react/recommended config. Do we need to add eslint-plugin-github and eslint-plugin-jsx-a11y as dependencies in the package.json?

Should we consider this a breaking change? plugin:github/react will probably flag more errors and warnings than before.

@khiga8
Copy link
Contributor Author

khiga8 commented Jul 22, 2022

@colebemis yes I think we'll need to do that! At least that's what we seem to do in eslint-plugin-github package.json since the presets depend on external plugins. does that sound okay with you?

eslint-plugin-github already specifies jsx-a11y as a dependency. would we need to specify it here too? 🤔

@khiga8
Copy link
Contributor Author

khiga8 commented Jul 22, 2022

Should we consider this a breaking change? plugin:github/react will probably flag more errors and warnings than before.

yes, we should to be safe!

@khiga8 khiga8 force-pushed the kh-github-component-mapping branch from 84a2db9 to f0f5abd Compare July 22, 2022 23:22
"jest": "^27.0.6"
},
"peerDependencies": {
"eslint": ">=4.19.0",
"eslint": "^8.0.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ran into dependency conflict because of the eslint version specified in eslint-plugin-github so I had to bump this up.

Copy link
Contributor Author

@khiga8 khiga8 Jul 22, 2022

Choose a reason for hiding this comment

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

not sure why it broke a test

EDIT: I fixed it with the change in src/rules/no-deprecated-colors.js. it had to do with an 8.0.0 feature.

(related: Rules require meta.hasSuggestions to provide suggestions)

"eslint-plugin-primer-react": major
---

Provide component mapping for `github/react` preset and add dependencies to `eslint-plugin-github` and `eslint-plugin-jsx-a11y`
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we also mention that the eslint peer dependency is now ^8.0.1?

Copy link
Contributor

@colebemis colebemis left a comment

Choose a reason for hiding this comment

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

Great work, @khiga8! ✨

Just left a minor comment about the changeset

@khiga8
Copy link
Contributor Author

khiga8 commented Jul 25, 2022

Tested this change on dotcom and made a couple fixes to the setting.
Verified it's working as expected.
Merging! :)

@khiga8 khiga8 merged commit da7e914 into main Jul 25, 2022
@khiga8 khiga8 deleted the kh-github-component-mapping branch July 25, 2022 18:33
@primer-css primer-css mentioned this pull request Jul 25, 2022
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 this pull request may close these issues.

2 participants