Add rule for Link to not be allowed without href - #364
Conversation
🦋 Changeset detectedLatest commit: 024794c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new ESLint rule to enforce accessibility best practices by preventing the use of Link components from @primer/react without an href attribute. The rule suggests using a Button component instead for interactive elements that don't navigate to a URL.
- Implements new rule
enforce-button-for-link-with-nohrefto detect Link components without href attributes - Provides comprehensive test coverage for valid and invalid usage scenarios
- Includes proper error messaging and rule metadata configuration
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/rules/enforce-button-for-link-with-nohref.js | Main rule implementation that checks for Link components without href attributes |
| src/rules/tests/enforce-button-for-link-with-nohref.test.js | Test suite covering valid and invalid usage scenarios |
| url: url(module), | ||
| }, | ||
| messages: { | ||
| noLinkWithoutHref: |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| noLinkWithoutHref: | ||
| 'Links without href and other side effects are not accessible. Use a Button instead.', | ||
| }, | ||
| fixable: 'code', |
There was a problem hiding this comment.
The rule is marked as fixable but no fix function is implemented. Either implement the fix logic or remove the 'fixable' property.
If a
Linkcomponent from@primer/reactis used without anhrefattribute, it is now flagged as an error."Links without href and other side effects are not accessible. Use a Button instead."