Skip to content

Conversation

@C2dricLeroy
Copy link
Contributor

@C2dricLeroy C2dricLeroy commented Nov 16, 2024

IMP #494

This commit is my first contribution, let me know if I can correct anything.

To test the config:
npx eslint . --ext .js,.jsx,.ts,.tsx

Summary by CodeRabbit

  • New Features

    • Enhanced accessibility linting for JSX elements with the addition of the eslint-plugin-jsx-a11y.
    • New linting rules introduced to ensure images have alt text and anchor elements are valid.
  • Chores

    • Updated ESLint configuration to include accessibility best practices.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 16, 2024

Walkthrough

The changes in this pull request involve updates to the ESLint configuration and the package.json file for the @radui/ui package. The ESLint configuration file .eslintrc.cjs has been enhanced to include accessibility linting rules for JSX elements by adding the jsx-a11y plugin and extending the recommended configuration. Additionally, the package.json file has been modified to include the eslint-plugin-jsx-a11y dependency, which supports the newly introduced accessibility rules.

Changes

File Change Summary
.eslintrc.cjs - Added plugin:jsx-a11y/recommended to extends array.
- Added jsx-a11y to plugins array.
- Introduced rules: jsx-a11y/alt-text (warn) and jsx-a11y/anchor-is-valid (warn).
package.json - Added eslint-plugin-jsx-a11y dependency with version ^6.10.2 in devDependencies.

Poem

In the garden of code, we hop with glee,
Adding rules for accessibility! 🌼
With alt text for images, anchors so bright,
Our JSX blooms, a wonderful sight!
Hooray for the changes, let’s dance and play,
For a more inclusive path, we pave the way! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

.eslintrc.cjs

Oops! Something went wrong! :(

ESLint: 8.56.0

Error: Failed to load parser '@babel/eslint-parser' declared in '.eslintrc.cjs': Cannot find module '@babel/core/package.json'
Require stack:

  • /node_modules/@babel/eslint-parser/lib/parse.cjs
  • /node_modules/@babel/eslint-parser/lib/index.cjs
  • /node_modules/@eslint/eslintrc/dist/eslintrc.cjs
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Function.resolve (node:internal/modules/helpers:145:19)
    at Object. (/node_modules/@babel/eslint-parser/lib/parse.cjs:14:19)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Module.load (node:internal/modules/cjs/loader:1317:32)
    at Module._load (node:internal/modules/cjs/loader:1127:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (2)
.eslintrc.cjs (1)

10-11: Consider adding stricter accessibility rules

While using plugin:jsx-a11y/recommended is a good start, consider also extending plugin:jsx-a11y/strict for more comprehensive accessibility coverage. This would help catch additional accessibility issues early in development.

    extends: [
        'plugin:react/recommended',
        'eslint:recommended',
        'standard',
        'plugin:jsx-a11y/recommended',
+       'plugin:jsx-a11y/strict'
    ],
package.json (1)

98-98: Consider documenting ESLint configuration strategy

Since you're adding accessibility linting capabilities, it would be helpful to document:

  1. The purpose and scope of each ESLint plugin
  2. How rules are configured (error vs warning levels)
  3. Any custom rule configurations

This documentation could live in the project's README or a separate CONTRIBUTING.md file.

Would you like me to help create a template for the linting documentation?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3ad695f and 7a4cd28.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • .eslintrc.cjs (2 hunks)
  • package.json (1 hunks)
🔇 Additional comments (3)
.eslintrc.cjs (2)

21-22: LGTM!

The plugins configuration is correct and properly ordered.


Line range hint 1-67: Verify accessibility rule impact on existing components

Let's ensure these new accessibility rules won't cause unexpected issues in the existing codebase.

✅ Verification successful

ESLint accessibility rules are safe to implement

The codebase already follows good accessibility practices:

  • Images have proper alt text (AvatarPrimitiveImage.tsx)
  • Anchors have href attributes (Link.tsx)
  • ARIA attributes are correctly used in interactive components (Toggle.tsx, AccordionTrigger.tsx)

Setting these rules to 'warn' is a good balance as it will:

  • Help catch any future accessibility issues
  • Not break existing code since components already follow these practices
  • Allow gradual improvements where needed
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential accessibility issues in existing components

# Look for img tags without alt attributes
echo "Checking for images without alt attributes..."
rg -l '<img\s+(?!.*alt=)[^>]*>' --type jsx --type tsx

# Look for anchor tags without href or invalid href
echo "Checking for potentially invalid anchors..."
rg -l '<a\s+(?!.*href=)[^>]*>' --type jsx --type tsx

# Look for potential ARIA attribute usage
echo "Checking current ARIA attribute usage..."
rg -l 'aria-[a-zA-Z]+=' --type jsx --type tsx

Length of output: 940


Script:

#!/bin/bash
# Let's try a different approach with simpler patterns

# Check for image elements
echo "Checking for image elements..."
rg -l '<img' --type js --type ts

# Check for anchor elements
echo "Checking for anchor elements..."
rg -l '<a\s' --type js --type ts

# Check for ARIA attributes with simpler pattern
echo "Checking for ARIA attributes..."
rg -l 'aria-' --type js --type ts

# Check for existing JSX files to ensure we're searching in the right place
echo "Checking for JSX/TSX files..."
fd -e jsx -e tsx

Length of output: 6228


Script:

#!/bin/bash
# Let's examine the actual usage in some key files

# Check image elements implementation
echo "Checking image implementations..."
rg -C 3 '<img' src/core/primitives/Avatar/fragments/AvatarPrimitiveImage.tsx

# Check anchor implementation
echo "Checking anchor implementations..."
rg -C 3 '<a\s' src/components/ui/Link/Link.tsx

# Check ARIA usage in components
echo "Checking ARIA implementations in Toggle..."
rg -C 3 'aria-' src/components/ui/Toggle/Toggle.tsx

echo "Checking ARIA implementations in Accordion..."
rg -C 3 'aria-' src/components/ui/Accordion/fragments/AccordionTrigger.tsx

Length of output: 1683

package.json (1)

98-98: Verify ESLint configuration for jsx-a11y

The plugin addition looks good, but let's ensure it's properly configured in the ESLint setup.

✅ Verification successful

jsx-a11y plugin is properly configured

The ESLint configuration in .eslintrc.cjs shows that the jsx-a11y plugin is correctly set up:

  • It's included in the plugins array
  • The recommended configuration is extended via 'plugin:jsx-a11y/recommended'
  • There are specific jsx-a11y rules configured (jsx-a11y/alt-text and jsx-a11y/anchor-is-valid)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify ESLint configuration for jsx-a11y plugin

# Check if .eslintrc exists and contains jsx-a11y configuration
echo "Checking .eslintrc files..."
fd -e json -e js -e cjs -e yaml -e yml '\.eslintrc' | while read -r config; do
  echo "=== $config ==="
  cat "$config"
done

# Check for any existing jsx-a11y rules in the codebase
echo -e "\nChecking for existing jsx-a11y rule usage..."
rg -l "jsx-a11y/" .

Length of output: 305


Script:

#!/bin/bash
# Let's check for ESLint config in other common locations and formats
echo "=== Checking for ESLint config in package.json ==="
jq '.eslintConfig' package.json

echo -e "\n=== Checking for .eslintrc.* files with any extension ==="
find . -maxdepth 1 -name ".eslintrc*"

echo -e "\n=== Checking for eslint-related files in config directory ==="
fd -t f "eslint" "config/"

Length of output: 593


Script:

#!/bin/bash
# Let's check the content of .eslintrc.cjs file
echo "=== Content of .eslintrc.cjs ==="
cat .eslintrc.cjs

Length of output: 2078

Comment on lines +25 to +26
'jsx-a11y/alt-text': 'warn',
'jsx-a11y/anchor-is-valid': 'warn',
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance accessibility rule configuration

While the current configuration is a good start, consider the following improvements:

  1. Some critical accessibility rules should be set to 'error' instead of 'warn' to ensure they're not overlooked:

    • alt-text is crucial for screen readers
    • anchor-is-valid prevents broken navigation
  2. Consider adding more specific configurations for these rules:

    rules: {
-       'jsx-a11y/alt-text': 'warn',
-       'jsx-a11y/anchor-is-valid': 'warn',
+       'jsx-a11y/alt-text': ['error', {
+           elements: ['img', 'object', 'area', 'input[type="image"]'],
+           img: ['Image'],
+           object: ['Object'],
+           area: ['Area'],
+           'input[type="image"]': ['InputImage']
+       }],
+       'jsx-a11y/anchor-is-valid': ['error', {
+           components: ['Link'],
+           specialLink: ['to'],
+           aspects: ['noHref', 'invalidHref', 'preferButton']
+       }],
+       // Additional important a11y rules
+       'jsx-a11y/aria-props': 'error',
+       'jsx-a11y/aria-proptypes': 'error',
+       'jsx-a11y/aria-role': 'error',
+       'jsx-a11y/role-has-required-aria-props': 'error'
    },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'jsx-a11y/alt-text': 'warn',
'jsx-a11y/anchor-is-valid': 'warn',
'jsx-a11y/alt-text': ['error', {
elements: ['img', 'object', 'area', 'input[type="image"]'],
img: ['Image'],
object: ['Object'],
area: ['Area'],
'input[type="image"]': ['InputImage']
}],
'jsx-a11y/anchor-is-valid': ['error', {
components: ['Link'],
specialLink: ['to'],
aspects: ['noHref', 'invalidHref', 'preferButton']
}],
// Additional important a11y rules
'jsx-a11y/aria-props': 'error',
'jsx-a11y/aria-proptypes': 'error',
'jsx-a11y/aria-role': 'error',
'jsx-a11y/role-has-required-aria-props': 'error'

"eslint-config-love": "^62.0.0",
"eslint-config-standard": "17.1.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jsx-a11y": "^6.10.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix invalid version number for eslint-plugin-jsx-a11y

The specified version ^6.10.2 is invalid as it doesn't exist. The latest version in the 6.x series is 6.8.0.

Apply this change:

-    "eslint-plugin-jsx-a11y": "^6.10.2",
+    "eslint-plugin-jsx-a11y": "^6.8.0",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"eslint-plugin-jsx-a11y": "^6.10.2",
"eslint-plugin-jsx-a11y": "^6.8.0",

@kotAPI kotAPI merged commit 11bf360 into rad-ui:main Nov 16, 2024
1 check passed
This was referenced Nov 16, 2024
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.

Feature Suggestion - Add eslint-plugin-jsx-a11y to our Eslint config

2 participants