Skip to content

Add no-deprecated-flash ESLint rule to warn against Flash component usage #384

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 8, 2025

This PR adds a new ESLint rule no-deprecated-flash that warns when the Flash component is used and suggests using the Banner component from @primer/react/experimental instead.

Changes

  • New Rule: src/rules/no-deprecated-flash.js - Detects Flash component imports and JSX usage from @primer/react
  • Warning-Only: Rule reports warnings without auto-fixing to allow manual migration
  • Comprehensive Tests: Test cases covering various scenarios including mixed imports and existing experimental imports
  • Documentation: Complete rule documentation with examples

Rule Features

The rule detects and warns about:

// This will trigger warnings
import {Flash} from '@primer/react'
<Flash variant="warning">Warning message</Flash>

// Recommended alternative
import {Banner} from '@primer/react/experimental'
<Banner variant="warning">Warning message</Banner>

Key capabilities:

  • Detects Flash imports from @primer/react
  • Warns about Flash JSX usage
  • Handles mixed imports (Flash with other components)
  • Works with existing experimental imports like TooltipV2
  • Provides clear warning messages suggesting Banner as replacement

Testing

The implementation includes comprehensive test coverage with scenarios for:

  • Basic Flash detection and warnings
  • Mixed imports with other Primer components
  • Existing experimental imports (no duplication issues)
  • Self-closing tags and complex JSX structures
  • Multiple Flash components in one file

All existing tests continue to pass (293/293) and the code follows project linting standards.

Fixes #383.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI assigned Copilot and pksjce Aug 8, 2025
Copy link

changeset-bot bot commented Aug 8, 2025

🦋 Changeset detected

Latest commit: bd99191

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 Patch

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

@Copilot Copilot AI changed the title [WIP] Add an eslint rule to discourage use of Flash and use Banner component instead. Add no-deprecated-flash ESLint rule to discourage Flash component usage Aug 8, 2025
@Copilot Copilot AI requested a review from pksjce August 8, 2025 03:29
Copilot finished work on behalf of pksjce August 8, 2025 03:29
return (
<Banner
variant="warning"
sx={{fontSize: 0, borderRadius: 0, py: 2, px: 3}}
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this sx prop as we are discouraging those too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the sx prop from the documentation example as requested. The example now only shows variant and className props. (427e5b2)

errors: [{messageId: 'flashDeprecated'}, {messageId: 'flashDeprecated'}],
},
],
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Also consider a case where other stuff is already being imported from primer/react/experimental like TooltipV2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a test case for existing imports from @primer/react/experimental like TooltipV2. The rule now properly handles scenarios where other experimental components are already being imported. (427e5b2)

recommended: true,
url: url(module),
},
fixable: 'code',
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this issue is always fixable so just throw a warning in lint for now and remove all the logic to fix this lint error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed all auto-fixing logic as requested. The rule now only throws warnings without attempting to fix the code. Removed fixable: 'code' from meta and all fix functions from the rule implementation. (427e5b2)

@pksjce
Copy link
Contributor

pksjce commented Aug 11, 2025

@copilot - Can you fix review comments

Copy link
Contributor Author

Copilot AI commented Aug 11, 2025

@copilot - Can you fix review comments

All review comments have been addressed: removed sx prop from docs, removed auto-fixing capability to make it warning-only, and added test case for existing experimental imports. (427e5b2)

@Copilot Copilot AI changed the title Add no-deprecated-flash ESLint rule to discourage Flash component usage Add no-deprecated-flash ESLint rule to warn against Flash component usage Aug 11, 2025
@Copilot Copilot AI requested a review from pksjce August 11, 2025 05:56
Copilot finished work on behalf of pksjce August 11, 2025 05:56
@pksjce pksjce marked this pull request as ready for review August 12, 2025 02:53
@Copilot Copilot AI review requested due to automatic review settings August 12, 2025 02:53
@pksjce pksjce requested a review from a team as a code owner August 12, 2025 02:53
@pksjce pksjce requested a review from TylerJDev August 12, 2025 02:53
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new ESLint rule no-deprecated-flash to warn developers when using the deprecated Flash component from @primer/react and suggests migrating to the Banner component from @primer/react/experimental.

Key changes:

  • Implements warning-only detection (no auto-fixing) for Flash component usage
  • Provides comprehensive test coverage for various import and usage scenarios
  • Includes complete documentation with examples

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/rules/no-deprecated-flash.js Main rule implementation that detects Flash imports and JSX usage from @primer/react
src/rules/__tests__/no-deprecated-flash.test.js Comprehensive test suite covering valid/invalid scenarios including mixed imports
src/index.js Exports the new rule in the plugin's rule registry
docs/rules/no-deprecated-flash.md Documentation with usage examples and migration guidance
Comments suppressed due to low confidence (1)

docs/rules/no-deprecated-flash.md:1

  • The documentation incorrectly states that this rule provides automatic fixes. According to the PR description, this is a "warning-only" rule without auto-fixing capabilities. The documentation should be updated to reflect that this rule only warns about deprecated usage and does not provide automatic fixes.
# No Deprecated Flash

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.

Add an eslint rule to discourage use of Flash and use Banner component instead.
2 participants