noRestrictedElements
Summary
Section titled Summary- Diagnostic Category:
lint/nursery/noRestrictedElements
- This rule doesn’t have a fix.
- The default severity of this rule is information.
- Sources:
- Same as
react/forbid-elements
- Same as
Description
Section titled DescriptionDisallow the use of configured elements.
This rule disallows the use of configured elements. Without elements configured, this rule doesn’t do anything.
This rule is useful in situations where you want to enforce the use of specific components
instead of certain HTML or custom elements. For example, in a React project,
you might want to ensure that developers use a custom TextField
component
instead of the native <input>
element to maintain consistency and apply
custom styling or behavior.
Here are some scenarios where this rule can be beneficial:
- Consistency: Ensuring that all input fields use a custom component instead of the native element to maintain a consistent look and feel across the application.
- Accessibility: Enforcing the use of custom components that have built-in accessibility features, ensuring that the application is accessible to all users.
- Custom Behavior: Requiring the use of components that encapsulate specific business logic or validation, reducing the risk of errors and improving code maintainability.
- Styling: Ensuring that all elements adhere to the design system by using custom components that apply consistent styling.
By disallowing certain elements and enforcing the use of custom components, this rule helps maintain code quality and consistency across the codebase.
Options
Section titled Options{ "options": { "elements": { "input": "input is not allowed, use TextField component instead", "CustomComponent": "deprecated" } }}
Examples
Section titled ExamplesInvalid
Section titled InvalidRestricting the use of HTML elements:
<input />
Restricting the use of custom components:
<CustomComponent />
Valid
Section titled Valid<TextField />
How to configure
Section titled How to configure{ "linter": { "rules": { "nursery": { "noRestrictedElements": "error" } } }}