New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-react-x

Package Overview
Dependencies
Maintainers
1
Versions
728
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-react-x

ESLint React's ESLint plugin for React related rules.

  • 1.5.24-next.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
203K
decreased by-2.28%
Maintainers
1
Weekly downloads
 
Created
Source

eslint-plugin-react-x

Core rules (DOM Irrelevant, Render Target Agnostic, Formatting Independent).

[!TIP] This plugin is already included in @eslint-react/eslint-plugin. You don't need to install it separately if you are using @eslint-react/eslint-plugin.

Install

# npm
npm install --save-dev eslint-plugin-react-x

Setup

Add the plugin to your eslint.config.js:

// @ts-check

import js from "@eslint/js";
import reactx from "eslint-plugin-react-x";

export default [
  js.configs.recommended,
  {
    files: ["**/*.{ts,tsx}"],
    plugins: [
      "react-x": reactx,
      rules: {
        // react-x recommended rules
        "react-x/ensure-forward-ref-using-ref": "warn",
        "react-x/no-access-state-in-setstate": "error",
        "react-x/no-array-index-key": "warn",
        "react-x/no-children-count": "warn",
        "react-x/no-children-for-each": "warn",
        "react-x/no-children-map": "warn",
        "react-x/no-children-only": "warn",
        "react-x/no-children-to-array": "warn",
        "react-x/no-clone-element": "warn",
        "react-x/no-comment-textnodes": "warn",
        "react-x/no-component-will-mount": "error",
        "react-x/no-component-will-receive-props": "error",
        "react-x/no-component-will-update": "error",
        "react-x/no-create-ref": "error",
        "react-x/no-direct-mutation-state": "error",
        "react-x/no-duplicate-key": "error",
        "react-x/no-missing-key": "error",
        "react-x/no-nested-components": "warn",
        "react-x/no-redundant-should-component-update": "error",
        "react-x/no-set-state-in-component-did-mount": "warn",
        "react-x/no-set-state-in-component-did-update": "warn",
        "react-x/no-set-state-in-component-will-update": "warn",
        "react-x/no-string-refs": "error",
        "react-x/no-unsafe-component-will-mount": "warn",
        "react-x/no-unsafe-component-will-receive-props": "warn",
        "react-x/no-unsafe-component-will-update": "warn",
        "react-x/no-unstable-context-value": "error",
        "react-x/no-unstable-default-props": "error",
        "react-x/no-unused-class-component-members": "warn",
        "react-x/no-unused-state": "warn",
        "react-x/no-useless-fragment": "warn",
      }
    ],
  },
];

Rules

RuleDescription💼💭
avoid-shorthand-booleanEnforces the use of shorthand syntax for boolean attributes.🎨
avoid-shorthand-fragmentEnforces the use of shorthand syntax for fragments.🎨
ensure-forward-ref-using-refRequires that components wrapped with forwardRef must have a ref parameter.✔️
no-access-state-in-setstatePrevents accessing this.state inside setState calls.✔️
no-array-index-keyWarns when an array index is used as a key prop.👀
no-children-countPrevents usage of Children.count.
no-children-for-eachPrevents usage of Children.forEach.
no-children-mapPrevents usage of Children.map.
no-children-onlyPrevents usage of Children.only.
no-children-propPrevents usage of children as a prop.
no-children-to-arrayPrevents usage of Children.toArray.
no-class-componentPrevents usage of class component.
no-clone-elementPrevents usage of cloneElement.
no-comment-textnodesPrevents comments from being inserted as text nodes.👀
no-component-will-mountPrevents usage of componentWillMount.
no-component-will-receive-propsPrevents usage of componentWillReceiveProps.
no-component-will-updatePrevents usage of componentWillUpdate.
no-create-refPrevents usage of createRef.
no-direct-mutation-statePrevents direct mutation of this.state.✔️
no-duplicate-keyPrevents duplicate key props on elements in the same array or a list of children.✔️
no-leaked-conditional-renderingPrevents problematic leaked values from being rendered.👀💭
no-missing-component-display-nameEnforces that all components have a displayName which can be used in devtools.🐞
no-missing-keyPrevents missing key prop on items in list rendering.✔️
no-nested-componentsPrevents nesting component definitions inside other components.✔️
no-redundant-should-component-updatePrevents usage of shouldComponentUpdate when extending React.PureComponent.✔️
no-set-state-in-component-did-mountDisallows calling this.setState in componentDidMount outside of functions, such as callbacks.👀
no-set-state-in-component-did-updateDisallows calling this.setState in componentDidUpdate outside of functions, such as callbacks.👀
no-set-state-in-component-will-updateDisallows calling this.setState in componentWillUpdate outside of functions, such as callbacks.👀
no-string-refsDisallows using deprecated string refs.
no-unsafe-component-will-mountWarns usage of UNSAFE_componentWillMount in class components.👀
no-unsafe-component-will-receive-propsWarns usage of UNSAFE_componentWillReceiveProps in class components.👀
no-unsafe-component-will-updateWarns usage of UNSAFE_componentWillUpdate in class components.👀
no-unstable-context-valuePrevents non-stable values (i.e. object literals) from being used as a value for Context.Provider.🚀
no-unstable-default-propsPrevents usage of referential-type values as default props in object destructuring.🚀
no-unused-class-component-membersWarns unused class component methods and properties.✔️
no-unused-stateWarns unused class component state.✔️
no-useless-fragmentPrevents the use of useless fragment components or <> syntax.✔️
prefer-read-only-propsEnforces that function components props are readonly.✔️💭
prefer-destructuring-assignmentEnforces the use of destructuring assignment over property assignment.🎨
prefer-shorthand-booleanEnforces the use of shorthand syntax for boolean attributes.🎨
prefer-shorthand-fragmentEnforces the use of shorthand syntax for fragments.🎨

FAQs

Package last updated on 10 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc