-
Notifications
You must be signed in to change notification settings - Fork 10
Add new rule no-deprecated-experimental-components
#325
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
TylerJDev
merged 12 commits into
main
from
add-no-deprecated-experimental-components-rule
Apr 10, 2025
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5781a76
Add new rule `no-deprecated-experimental-components`
TylerJDev 8aebb76
Lint and format
TylerJDev 0f06ed2
Add changeset
TylerJDev 364ff17
Update README.md
TylerJDev a5d1f8e
Update docs/rules/no-deprecated-experimental-components.md
TylerJDev ad1531b
Update message
TylerJDev d4353f4
Add link to docs
TylerJDev 50f33ef
Update docs/rules/no-deprecated-experimental-components.md
TylerJDev d099c40
Update src/rules/no-deprecated-experimental-components.js
TylerJDev 9c69048
Merge branch 'main' into add-no-deprecated-experimental-components-rule
hectahertz 0f96e8d
Update src/configs/recommended.js
TylerJDev 481a89c
Edit to message
TylerJDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'eslint-plugin-primer-react': minor | ||
--- | ||
|
||
Add `no-deprecated-experimental-components` rule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# No deprecated experimental components | ||
|
||
## Rule Details | ||
|
||
This rule discourages the usage of specific imports from `@primer/react/experimental`. | ||
|
||
👎 Examples of **incorrect** code for this rule | ||
|
||
```jsx | ||
import {SelectPanel} from '@primer/react/experimental' | ||
|
||
function ExampleComponent() { | ||
return <SelectPanel /> | ||
} | ||
``` | ||
|
||
👍 Examples of **correct** code for this rule: | ||
|
||
You can satisfy the rule by either converting to the non-experimental version: | ||
|
||
```jsx | ||
import {SelectPanel} from '@primer/react' | ||
|
||
function ExampleComponent() { | ||
return <SelectPanel /> | ||
} | ||
``` | ||
|
||
Or by removing usage of the component. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/rules/__tests__/no-deprecated-experimental-components.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict' | ||
|
||
const {RuleTester} = require('eslint') | ||
const rule = require('../no-deprecated-experimental-components') | ||
|
||
const ruleTester = new RuleTester({ | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
ecmaFeatures: { | ||
jsx: true, | ||
}, | ||
}, | ||
}) | ||
|
||
ruleTester.run('no-deprecated-experimental-components', rule, { | ||
valid: [ | ||
{ | ||
code: `import {SelectPanel} from '@primer/react'`, | ||
}, | ||
{ | ||
code: `import {DataTable} from '@primer/react/experimental'`, | ||
}, | ||
{ | ||
code: `import {DataTable, ActionBar} from '@primer/react/experimental'`, | ||
}, | ||
], | ||
invalid: [ | ||
// Single experimental import | ||
{ | ||
code: `import {SelectPanel} from '@primer/react/experimental'`, | ||
errors: [ | ||
'SelectPanel is deprecated. Please import them from the stable entrypoint (@primer/react) if available, or check https://primer.style/product/components/ for alternative components.', | ||
], | ||
}, | ||
// Multiple experimental import | ||
{ | ||
code: `import {SelectPanel, DataTable, ActionBar} from '@primer/react/experimental'`, | ||
errors: [ | ||
'SelectPanel is deprecated. Please import them from the stable entrypoint (@primer/react) if available, or check https://primer.style/product/components/ for alternative components.', | ||
], | ||
}, | ||
], | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'use strict' | ||
|
||
const url = require('../url') | ||
|
||
const components = [ | ||
{ | ||
identifier: 'SelectPanel', | ||
entrypoint: '@primer/react/experimental', | ||
}, | ||
] | ||
|
||
const entrypoints = new Map() | ||
|
||
for (const component of components) { | ||
if (!entrypoints.has(component.entrypoint)) { | ||
entrypoints.set(component.entrypoint, new Set()) | ||
} | ||
entrypoints.get(component.entrypoint).add(component.identifier) | ||
} | ||
|
||
/** | ||
* @type {import('eslint').Rule.RuleModule} | ||
*/ | ||
module.exports = { | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
description: 'Use a stable component from the `@primer/react` entrypoint, or check the docs for alternatives', | ||
recommended: true, | ||
url: url(module), | ||
}, | ||
fixable: true, | ||
schema: [], | ||
}, | ||
create(context) { | ||
return { | ||
ImportDeclaration(node) { | ||
if (!entrypoints.has(node.source.value)) { | ||
return | ||
} | ||
|
||
const entrypoint = entrypoints.get(node.source.value) | ||
|
||
const experimental = node.specifiers.filter(specifier => { | ||
return entrypoint.has(specifier.imported.name) | ||
}) | ||
|
||
const components = experimental.map(specifier => specifier.imported.name) | ||
|
||
if (experimental.length === 0) { | ||
return | ||
} | ||
|
||
if (experimental.length > 0) { | ||
const message = `${components.join(', ')} ${ | ||
components.length > 1 ? 'are' : 'is' | ||
} deprecated. Please import them from the stable entrypoint (@primer/react) if available, or check https://primer.style/product/components/ for alternative components.` | ||
|
||
context.report({ | ||
node, | ||
message, | ||
}) | ||
} | ||
}, | ||
} | ||
}, | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.