UNPKG

@lego/eslint-config-react

Version:

LEGO shareable eslint config for js projects

328 lines 13.6 kB
"use strict"; const config = { settings: { react: { // React version. "detect" automatically picks the version you have installed. version: 'detect', }, }, rules: { // Enforces consistent naming for boolean props 'react/boolean-prop-naming': [ 'error', { rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+', }, ], // Forbid "button" element without an explicit "type" attribute 'react/button-has-type': 'off', // Prevent extraneous defaultProps on components 'react/default-props-match-prop-types': [ 'error', { allowRequiredDefaults: true, }, ], // Rule enforces consistent usage of destructuring assignment in component 'react/destructuring-assignment': ['error', 'always'], // Prevent missing displayName in a React component definition 'react/display-name': [ 'warn', { ignoreTranspilerName: false, }, ], // Forbid certain props on Components 'react/forbid-component-props': 'off', // Forbid certain props on DOM Nodes 'react/forbid-dom-props': 'off', // Forbid certain elements 'react/forbid-elements': 'off', // Forbid foreign propTypes 'react/forbid-foreign-prop-types': 'off', // Forbid certain propTypes 'react/forbid-prop-types': 'off', // Enforce a specific function type for function components 'react/function-component-definition': 'off', // Enforce boolean attributes notation in JSX (fixable) 'react/jsx-boolean-value': ['warn', 'always'], // Enforce or disallow spaces inside of curly braces in JSX attributes and expressions. 'react/jsx-child-element-spacing': 'error', // Validate closing bracket location in JSX (fixable) 'react/jsx-closing-bracket-location': 'off', // Validate closing tag location in JSX (fixable) 'react/jsx-closing-tag-location': 'off', // Enforce curly braces or disallow unnecessary curly braces in JSX 'react/jsx-curly-brace-presence': [ 'error', { children: 'never', props: 'never', }, ], // Enforce or disallow newlines inside of curly braces in JSX attributes and expressions (fixable) 'react/jsx-curly-newline': [ 'warn', { multiline: 'consistent', singleline: 'consistent', }, ], // Enforce or disallow spaces inside of curly braces in JSX attributes and expressions (fixable) 'react/jsx-curly-spacing': [ 'error', { spacing: { objectLiterals: 'never', }, when: 'never', }, ], // Enforce or disallow spaces around equal signs in JSX attributes (fixable) 'react/jsx-equals-spacing': ['error', 'never'], // Restrict file extensions that may contain JSX 'react/jsx-filename-extension': [ 'warn', { extensions: ['.js', '.jsx'], }, ], // Enforce position of the first prop in JSX (fixable) 'react/jsx-first-prop-new-line': ['warn', 'multiline-multiprop'], // Enforce shorthand or standard form for React fragments 'react/jsx-fragments': ['error', 'element'], // Enforce event handler naming conventions in JSX 'react/jsx-handler-names': [ 'warn', { eventHandlerPrefix: 'handle', eventHandlerPropPrefix: 'on', }, ], // Validate JSX indentation (fixable) 'react/jsx-indent': 'off', // Validate props indentation in JSX (fixable) 'react/jsx-indent-props': 'off', // Validate JSX has key prop when in array or iterator 'react/jsx-key': 'warn', // Validate JSX maximum depth 'react/jsx-max-depth': 'off', // Limit maximum of props on a single line in JSX (fixable) 'react/jsx-max-props-per-line': 'off', // Require or prevent a new line after jsx elements and expressions. (react/jsx-newline) 'react/jsx-newline': [ 'warn', { prevent: true, }, ], // Prevent usage of .bind() and arrow functions in JSX props 'react/jsx-no-bind': 'error', // Prevent comments from being inserted as text nodes 'react/jsx-no-comment-textnodes': 'error', // Prevent react contexts from taking non-stable values 'react/jsx-no-constructed-context-values': 'error', // Prevent duplicate props in JSX 'react/jsx-no-duplicate-props': [ 'error', { ignoreCase: false, }, ], // Prevent usage of unwrapped JSX strings 'react/jsx-no-literals': 'off', // Prevent usage of javascript: URLs 'react/jsx-no-script-url': 'off', // Prevent usage of unsafe target='_blank' 'react/jsx-no-target-blank': 'warn', // Disallow undeclared variables in JSX 'react/jsx-no-undef': 'warn', // Disallow unnescessary fragments (fixable) 'react/jsx-no-useless-fragment': 'error', // Limit to one expression per line in JSX 'react/jsx-one-expression-per-line': 'off', // Enforce PascalCase for user-defined JSX components 'react/jsx-pascal-case': [ 'warn', { allowAllCaps: false, }, ], // Disallow multiple spaces between inline JSX props (fixable) 'react/jsx-props-no-multi-spaces': 'error', // Disallow JSX props spreading 'react/jsx-props-no-spreading': 'off', // Enforce default props alphabetical sorting 'react/jsx-sort-default-props': 'warn', // Enforce props alphabetical sorting (fixable) 'react/jsx-sort-props': [ 'warn', { ignoreCase: true, }, ], // Validate whitespace in and around the JSX opening and closing brackets (fixable) 'react/jsx-tag-spacing': [ 'warn', { afterOpening: 'never', beforeClosing: 'allow', beforeSelfClosing: 'always', closingSlash: 'never', }, ], // Prevent React to be incorrectly marked as unused 'react/jsx-uses-react': 'warn', // Prevent variables used in JSX to be incorrectly marked as unused 'react/jsx-uses-vars': 'warn', // Prevent missing parentheses around multilines JSX (fixable) 'react/jsx-wrap-multilines': [ 'warn', { arrow: 'parens-new-line', assignment: 'parens', condition: 'parens-new-line', declaration: 'parens-new-line', logical: 'parens-new-line', prop: 'parens-new-line', return: 'parens-new-line', }, ], // Prevent using this.state inside this.setState 'react/no-access-state-in-setstate': 'error', // Prevent adjacent inline elements not separated by whitespace. 'react/no-adjacent-inline-elements': 'warn', // Prevent using Array index in key props 'react/no-array-index-key': 'error', // Prevent passing children as props 'react/no-children-prop': 'error', // Prevent usage of dangerous JSX properties 'react/no-danger': 'error', // Prevent problem with children and props.dangerouslySetInnerHTML 'react/no-danger-with-children': 'error', // Prevent usage of deprecated methods, including component lifecycle methods 'react/no-deprecated': 'warn', // Prevent usage of setState in componentDidMount 'react/no-did-mount-set-state': ['error', 'disallow-in-func'], // Prevent usage of setState in componentDidUpdate 'react/no-did-update-set-state': ['error', 'disallow-in-func'], // Prevent direct mutation of this.state 'react/no-direct-mutation-state': 'error', // Prevent usage of findDOMNode 'react/no-find-dom-node': 'error', // Prevent usage of isMounted 'react/no-is-mounted': 'error', // Prevent multiple component definition per file 'react/no-multi-comp': [ 'warn', { ignoreStateless: true, }, ], // Prevent usage of shouldComponentUpdate when extending React.PureComponent 'react/no-redundant-should-component-update': 'error', // Prevent usage of the return value of React.render 'react/no-render-return-value': 'warn', // Prevent usage of setState 'react/no-set-state': 'off', // Prevent using string references in ref attribute. 'react/no-string-refs': 'error', // Prevent using this in stateless functional components 'react/no-this-in-sfc': 'error', // Prevent common casing typos 'react/no-typos': 'error', // Prevent invalid characters from appearing in markup 'react/no-unescaped-entities': 'error', // Prevent usage of unknown DOM property (fixable) 'react/no-unknown-property': 'error', // Prevent usage of unsafe lifecycle methods 'react/no-unsafe': 'error', // Prevent creating unstable components inside components 'react/no-unstable-nested-components': [ 'error', { allowAsProps: true, }, ], // Prevent definitions of unused prop types 'react/no-unused-prop-types': 'warn', // Prevent definitions of unused state properties 'react/no-unused-state': 'warn', // Prevent usage of setState in componentWillUpdate 'react/no-will-update-set-state': ['error', 'disallow-in-func'], // Enforce ES5 or ES6 class for React Components 'react/prefer-es6-class': ['warn', 'always'], // Enforce that props are read-only 'react/prefer-read-only-props': 'off', // Enforce stateless React Components to be written as a pure function 'react/prefer-stateless-function': 'warn', // Prevent missing props validation in a React component definition 'react/prop-types': 'warn', // Prevent missing React when using JSX 'react/react-in-jsx-scope': 'warn', // Enforce a defaultProps definition for every prop that is not a required prop 'react/require-default-props': 'warn', // Enforce React components to have a shouldComponentUpdate method 'react/require-optimization': 'off', // Enforce ES5 or ES6 class for returning value in render function 'react/require-render-return': 'error', // Prevent extra closing tags for components without children (fixable) 'react/self-closing-comp': 'error', // Enforce component methods order (fixable) 'react/sort-comp': 'off', // Enforce propTypes declarations alphabetical sorting 'react/sort-prop-types': 'warn', // Enforce the state initialization style to be either in a constructor or with a class property 'react/state-in-constructor': ['error', 'never'], // Enforces where React component static properties should be positioned. 'react/static-property-placement': ['error', 'static public field'], // Enforce style prop value being an object 'react/style-prop-object': 'error', // Prevent void DOM elements (e.g. <img />, <br />) from receiving children 'react/void-dom-elements-no-children': 'error', }, overrides: [ { // gather all of our js files to turn off some ts rules files: ['*.js'], rules: { '@typescript-eslint/explicit-function-return-type': 'off', '@typescript-eslint/no-var-requires': 'off', }, }, { files: ['*.tsx'], rules: { // turn off explicit return types for tsx files (React components) '@typescript-eslint/explicit-member-accessibility': 'off', '@typescript-eslint/explicit-function-return-type': 'off', }, }, { // enable the rule specifically for TypeScript files files: ['*.ts', '*.tsx'], rules: { 'react/boolean-prop-naming': 'off', 'react/prop-types': 'off', 'react/jsx-filename-extension': ['warn', { extensions: ['.ts', '.tsx'] }], }, }, { files: ['rules/*.ts'], rules: { // Allows for easier readability in the rules sections. 'lines-around-comment': [ 'error', { allowArrayStart: true, allowObjectStart: true, beforeBlockComment: true, beforeLineComment: true, }, ], }, }, ], }; module.exports = config; //# sourceMappingURL=react.js.map