Skip to content

Latest commit

Β 

History

History
138 lines (124 loc) Β· 104 KB

react.md

File metadata and controls

138 lines (124 loc) Β· 104 KB

react config

Config for React projects.

πŸ—οΈ Setup

  1. If you haven't already, make sure to install @code-pushup/eslint-config and its required peer dependencies.

  2. Since this plugin requires additional peer dependencies, you have to install them as well:

    npm install -D eslint-plugin-{jsx-a11y,react,react-hooks}
  3. Add to your eslint.config.js file:

    import react from '@code-pushup/eslint-config/react.js';
    import tseslint from 'typescript-eslint';
    
    export default tseslint.config(...react);

πŸ“ Rules (403)

302 rules are included from javascript config. For brevity, only the 101 additional rules are listed in this document.

πŸ”§ Automatically fixable by the --fix CLI option.
πŸ’‘ Manually fixable by editor suggestions.
πŸ§ͺ🚫 Disabled for test files.
πŸ§ͺ⚠️ Severity lessened to warning for test files.

🚨 Errors (72)

Plugin Rule Options Autofix Overrides
jsx-a11y alt-text
Enforce all elements that require alternative text have meaningful information to relay back to end user.
jsx-a11y anchor-has-content
Enforce all anchors to contain accessible content.
jsx-a11y anchor-is-valid
Enforce all anchors are valid, navigable elements.
jsx-a11y aria-activedescendant-has-tabindex
Enforce elements with aria-activedescendant are tabbable.
jsx-a11y aria-props
Enforce all aria-* props are valid.
jsx-a11y aria-proptypes
Enforce ARIA state and property values are valid.
jsx-a11y aria-role
Enforce that elements with ARIA roles must use a valid, non-abstract ARIA role.
jsx-a11y aria-unsupported-elements
Enforce that elements that do not support ARIA roles, states, and properties do not have those attributes.
jsx-a11y autocomplete-valid
Enforce that autocomplete attributes are used correctly.
jsx-a11y click-events-have-key-events
Enforce a clickable non-interactive element has at least one keyboard event listener.
jsx-a11y heading-has-content
Enforce heading (h1, h2, etc) elements contain accessible content.
jsx-a11y html-has-lang
Enforce <html> element has lang prop.
jsx-a11y iframe-has-title
Enforce iframe elements have a title attribute.
jsx-a11y img-redundant-alt
Enforce <img> alt prop does not contain the word "image", "picture", or "photo".
jsx-a11y interactive-supports-focus
Enforce that elements with interactive handlers like onClick must be focusable.
tabbable: button, checkbox,...
{
  "tabbable": [
    "button",
    "checkbox",
    "link",
    "searchbox",
    "spinbutton",
    "switch",
    "textbox"
  ]
}
jsx-a11y label-has-associated-control
Enforce that a label tag has a text label and an associated control.
jsx-a11y media-has-caption
Enforces that <audio> and <video> elements must have a <track> for captions.
jsx-a11y mouse-events-have-key-events
Enforce that onMouseOver/onMouseOut are accompanied by onFocus/onBlur for keyboard-only users.
jsx-a11y no-access-key
Enforce that the accessKey prop is not used on any element to avoid complications with keyboard commands used by a screen reader.
jsx-a11y no-distracting-elements
Enforce distracting elements are not used.
jsx-a11y no-interactive-element-to-noninteractive-role
Interactive elements should not be assigned non-interactive roles.
tr: none, presentation, can...
{
  "tr": [
    "none",
    "presentation"
  ],
  "canvas": [
    "img"
  ]
}
jsx-a11y no-noninteractive-element-interactions
Non-interactive elements should not be assigned mouse or keyboard event listeners.
handlers: onClick, onError,...
{
  "handlers": [
    "onClick",
    "onError",
    "onLoad",
    "onMouseDown",
    "onMouseUp",
    "onKeyPress",
    "onKeyDown",
    "onKeyUp"
  ],
  "alert": [
    "onKeyUp",
    "onKeyDown",
    "onKeyPress"
  ],
  "body": [
    "onError",
    "onLoad"
  ],
  "dialog": [
    "onKeyUp",
    "onKeyDown",
    "onKeyPress"
  ],
  "iframe": [
    "onError",
    "onLoad"
  ],
  "img": [
    "onError",
    "onLoad"
  ]
}
jsx-a11y no-noninteractive-element-to-interactive-role
Non-interactive elements should not be assigned interactive roles.
ul: listbox, menu, menubar,...
{
  "ul": [
    "listbox",
    "menu",
    "menubar",
    "radiogroup",
    "tablist",
    "tree",
    "treegrid"
  ],
  "ol": [
    "listbox",
    "menu",
    "menubar",
    "radiogroup",
    "tablist",
    "tree",
    "treegrid"
  ],
  "li": [
    "menuitem",
    "menuitemradio",
    "menuitemcheckbox",
    "option",
    "row",
    "tab",
    "treeitem"
  ],
  "table": [
    "grid"
  ],
  "td": [
    "gridcell"
  ],
  "fieldset": [
    "radiogroup",
    "presentation"
  ]
}
jsx-a11y no-noninteractive-tabindex
tabIndex should only be declared on interactive elements.
tags: , roles: tabpanel, al...
{
  "tags": [],
  "roles": [
    "tabpanel"
  ],
  "allowExpressionValues": true
}
jsx-a11y no-static-element-interactions
Enforce that non-interactive, visible elements (such as <div>) that have click handlers use the role attribute.
allowExpressionValues: true...
{
  "allowExpressionValues": true,
  "handlers": [
    "onClick",
    "onMouseDown",
    "onMouseUp",
    "onKeyPress",
    "onKeyDown",
    "onKeyUp"
  ]
}
jsx-a11y role-has-required-aria-props
Enforce that elements with ARIA roles must have all required attributes for that role.
jsx-a11y role-supports-aria-props
Enforce that elements with explicit or implicit roles defined contain only aria-* properties supported by that role.
jsx-a11y scope
Enforce scope prop is only used on <th> elements.
jsx-a11y tabindex-no-positive
Enforce tabIndex value is not greater than zero.
react button-has-type
Disallow usage of button elements without an explicit type attribute
react default-props-match-prop-types
Enforce all defaultProps have a corresponding non-required PropType
react forbid-prop-types
Disallow certain propTypes
react forward-ref-uses-ref
Require all forwardRef components include a ref parameter
πŸ’‘
react iframe-missing-sandbox
Enforce sandbox attribute on iframe elements
react jsx-key
Disallow missing key props in iterators/collection literals
react jsx-no-bind
Disallow .bind() or arrow functions in JSX props
react jsx-no-comment-textnodes
Disallow comments from being inserted as text nodes
react jsx-no-constructed-context-values
Disallows JSX context provider values from taking values that will cause needless rerenders
react jsx-no-duplicate-props
Disallow duplicate properties in JSX
react jsx-no-script-url
Disallow usage of javascript: URLs
react jsx-no-target-blank
Disallow target="_blank" attribute without rel="noreferrer"
πŸ”§
react jsx-no-undef
Disallow undeclared variables in JSX
react jsx-uses-react
Disallow React to be incorrectly marked as unused
react jsx-uses-vars
Disallow variables used in JSX to be incorrectly marked as unused
react no-access-state-in-setstate
Disallow when this.state is accessed within setState
react no-array-index-key
Disallow usage of Array index in keys
react no-children-prop
Disallow passing of children as props
react no-danger
Disallow usage of dangerous JSX properties
react no-danger-with-children
Disallow when a DOM element is using both children and dangerouslySetInnerHTML
react no-deprecated
Disallow usage of deprecated methods
react no-did-mount-set-state
Disallow usage of setState in componentDidMount
react no-did-update-set-state
Disallow usage of setState in componentDidUpdate
react no-direct-mutation-state
Disallow direct mutation of this.state
react no-find-dom-node
Disallow usage of findDOMNode
react no-invalid-html-attribute
Disallow usage of invalid attributes
πŸ’‘
react no-is-mounted
Disallow usage of isMounted
react no-namespace
Enforce that namespaces are not used in React elements
react no-object-type-as-default-prop
Disallow usage of referential-type variables as default param in functional component
react no-render-return-value
Disallow usage of the return value of ReactDOM.render
react no-string-refs
Disallow using string references
react no-this-in-sfc
Disallow this from being used in stateless functional components
react no-typos
Disallow common typos
react no-unescaped-entities
Disallow unescaped HTML entities from appearing in markup
πŸ’‘
react no-unknown-property
Disallow usage of unknown DOM property
πŸ”§
react no-unstable-nested-components
Disallow creating unstable components inside components
react no-will-update-set-state
Disallow usage of setState in componentWillUpdate
react prop-types
Disallow missing props validation in a React component definition
react react-in-jsx-scope
Disallow missing React when using JSX
react require-render-return
Enforce ES5 or ES6 class for returning value in render function
react void-dom-elements-no-children
Disallow void DOM elements (e.g. <img />, <br />) from receiving children
react-hooks exhaustive-deps
verifies the list of dependencies for Hooks like useEffect and similar
πŸ”§, πŸ’‘
react-hooks rules-of-hooks
enforces the Rules of Hooks

⚠️ Warnings (29)

Plugin Rule Options Autofix Overrides
jsx-a11y no-autofocus
Enforce autoFocus prop is not used.
jsx-a11y no-redundant-roles
Enforce explicit role property is not the same as implicit/default role property on element.
jsx-a11y prefer-tag-over-role
Enforces using semantic DOM elements over the ARIA role property.
react display-name
Disallow missing displayName in a React component definition
react forbid-component-props
Disallow certain props on components
react function-component-definition
Enforce a specific function type for function components
πŸ”§
react hook-use-state
Ensure destructuring and symmetric naming of useState hook value and setter variables
πŸ’‘
react jsx-boolean-value
Enforce boolean attributes notation in JSX
πŸ”§
react jsx-curly-brace-presence
Disallow unnecessary JSX expressions when literals alone are sufficient or enforce JSX expressions on literals in JSX children or attributes
props: never, children: nev...
{
  "props": "never",
  "children": "never",
  "propElementValues": "always"
}
πŸ”§
react jsx-filename-extension
Disallow file extensions that may contain JSX
extensions: .jsx, .tsx
{
  "extensions": [
    ".jsx",
    ".tsx"
  ]
}
react jsx-fragments
Enforce shorthand or standard form for React fragments
πŸ”§
react jsx-handler-names
Enforce event handler naming conventions in JSX
react jsx-max-depth
Enforce JSX maximum depth
max: 10
{
  "max": 10
}
react jsx-no-leaked-render
Disallow problematic leaked values from being rendered
πŸ”§
react jsx-no-useless-fragment
Disallow unnecessary fragments
πŸ”§
react jsx-pascal-case
Enforce PascalCase for user-defined JSX components
react jsx-props-no-spread-multi
Disallow JSX prop spreading the same identifier multiple times
react no-arrow-function-lifecycle
Lifecycle methods should be methods on the prototype, not class fields
πŸ”§
react no-multi-comp
Disallow multiple component definition per file
ignoreStateless: true
{
  "ignoreStateless": true
}
react no-redundant-should-component-update
Disallow usage of shouldComponentUpdate when extending React.PureComponent
react no-unused-class-component-methods
Disallow declaring unused methods of component class
react no-unused-prop-types
Disallow definitions of unused propTypes
react no-unused-state
Disallow definitions of unused state
react prefer-es6-class
Enforce ES5 or ES6 class for React Components
react prefer-stateless-function
Enforce stateless components to be written as a pure function
react self-closing-comp
Disallow extra closing tags for components without children
πŸ”§
react state-in-constructor
Enforce class component state initialization style
react static-property-placement
Enforces where React component static properties should be positioned.
react style-prop-object
Enforce style prop value is an object