πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
DemoInstallSign in
Socket

eslint-plugin-react-x

Package Overview
Dependencies
Maintainers
0
Versions
1147
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.9.2-next.7
Source
npm
Version published
Weekly downloads
271K
4.71%
Maintainers
0
Weekly downloads
Β 
Created
Source

eslint-plugin-react-x

Core rules (renderer-agnostic, compatible with x-platform).

[!NOTE] 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-default-props": "error",
        "react-x/no-direct-mutation-state": "error",
        "react-x/no-duplicate-key": "error",
        "react-x/no-implicit-key": "warn",
        "react-x/no-missing-key": "error",
        "react-x/no-nested-components": "warn",
        "react-x/no-prop-types": "error",
        "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",
      }
    ],
  },
];

Rules

RuleDescriptionπŸ’ΌπŸ’­
avoid-shorthand-booleanEnforces using shorthand syntax for boolean attributes.🎨
avoid-shorthand-fragmentEnforces using 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-keyPrevents using array index as key.🧐
no-children-countPrevents using Children.count.β›”
no-children-for-eachPrevents using Children.forEach.β›”
no-children-mapPrevents using Children.map.β›”
no-children-onlyPrevents using Children.only.β›”
no-children-propPrevents using children as a prop.β›”
no-children-to-arrayPrevents using Children.toArray.β›”
no-class-componentPrevents using class component.β›”
no-clone-elementPrevents using cloneElement.β›”
no-comment-textnodesPrevents comments from being inserted as text nodes.🧐
no-complex-conditional-renderingPrevents complex conditional rendering in JSX.🀯
no-component-will-mountPrevents using componentWillMount.β›”
no-component-will-receive-propsPrevents using componentWillReceiveProps.β›”
no-component-will-updatePrevents using componentWillUpdate.β›”
no-create-refPrevents using createRef.β›”
no-default-propsPrevents using defaultProps property in favor of ES6 default parameters.βœ”οΈ
no-direct-mutation-statePrevents direct mutation of this.state.βœ”οΈ
no-duplicate-keyPrevents duplicate key on elements in the same array or a list of children.βœ”οΈ
no-implicit-keyPrevents key from not being explicitly specified (e.g. spreading key from objects).🧐
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 on items in list rendering.βœ”οΈ
no-nested-componentsPrevents nesting component definitions inside other components.βœ”οΈ
no-props-typesPrevents using propTypes in favor of TypeScript or another type-checking solution.β›”
no-redundant-should-component-updatePrevents using shouldComponentUpdate when extending React.PureComponent.βœ”οΈ
no-set-state-in-component-did-mountPrevents calling this.setState in componentDidMount outside of functions, such as callbacks.🧐
no-set-state-in-component-did-updatePrevents calling this.setState in componentDidUpdate outside of functions, such as callbacks.🧐
no-set-state-in-component-will-updatePrevents calling this.setState in componentWillUpdate outside of functions, such as callbacks.🧐
no-string-refsPrevents using deprecated string refs.β›”
no-unsafe-component-will-mountWarns the usage of UNSAFE_componentWillMount in class components.🧐
no-unsafe-component-will-receive-propsWarns the usage of UNSAFE_componentWillReceiveProps in class components.🧐
no-unsafe-component-will-updateWarns the 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 using 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 using useless fragment components or <> syntax.βœ”οΈ
prefer-destructuring-assignmentEnforces using destructuring assignment over property assignment.🎨
prefer-read-only-propsEnforce read-only props in components.βœ”οΈπŸ’­
prefer-shorthand-booleanEnforces using shorthand syntax for boolean attributes.🎨
prefer-shorthand-fragmentEnforces using shorthand syntax for fragments.🎨

Keywords

eslint

FAQs

Package last updated on 11 Aug 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