Note: This is a fork of the great eslint-plugin-react.
Inferno specific linting rules for ESLint Rules are mostly same, but propType related rules have been removed.
Install ESLint either locally or globally.
$ npm install eslint --save-dev
If you installed ESLint
globally, you have to install Inferno plugin globally too. Otherwise, install it locally.
$ npm install eslint-plugin-inferno --save-dev
Use our preset to get reasonable defaults:
"extends": [
"eslint:recommended",
"plugin:inferno/recommended"
]
You should also specify settings that will be shared across all the plugin rules.
{
"settings": {
"inferno": {
"createClass": "createClass", // Regex for Component Factory to use, // default to "createClass"
"pragma": "Inferno", // Inferno to use, default to "Inferno"
},
"propWrapperFunctions": [ "forbidExtraProps" ] // The names of any functions used to wrap the
// propTypes object, e.g. `forbidExtraProps`.
// If this isn't set, any propTypes wrapped in
// a function will be skipped.
}
}
If you do not use a preset you will need to specify individual rules and add extra configuration.
Add "inferno" to the plugins section.
{
"plugins": [
"inferno"
]
}
Enable JSX support.
With ESLint 2+
{
"parserOptions": {
"ecmaFeatures": {
"jsx": true
}
}
}
Enable the rules that you would like to use.
"rules": {
"inferno/jsx-uses-inferno": "error",
"inferno/jsx-uses-vars": "error",
}
These rules have been removed, because they are invalid in Inferno
- inferno/boolean-prop-naming: Enforces consistent naming for boolean props
- inferno/button-has-type: Forbid "button" element without an explicit "type" attribute
- inferno/destructuring-assignment: Rule enforces consistent usage of destructuring assignment in component
- inferno/forbid-dom-props: Forbid certain props on DOM Nodes
- inferno/no-access-state-in-setstate: Prevent using this.state inside this.setState
- inferno/no-deprecated: Prevent usage of deprecated methods
- inferno/no-this-in-sfc: Prevent using
this
in stateless functional components - inferno/no-unused-state: Prevent definitions of unused state properties
- inferno/require-default-props: Enforce a defaultProps definition for every prop that is not a required prop
- inferno/forbid-component-props: Forbid certain props on Components
- inferno/forbid-elements: Forbid certain elements
- inferno/no-array-index-key: Prevent using Array index in
key
props - inferno/no-children-prop: Prevent passing children as props
- inferno/no-danger: Prevent usage of dangerous JSX properties
- inferno/no-danger-with-children: Prevent problem with children and props.dangerouslySetInnerHTML
- inferno/no-did-mount-set-state: Prevent usage of
setState
incomponentDidMount
- inferno/no-did-update-set-state: Prevent usage of
setState
incomponentDidUpdate
- inferno/no-direct-mutation-state: Prevent direct mutation of
this.state
- inferno/no-find-dom-node: Prevent usage of
findDOMNode
- inferno/no-is-mounted: Prevent usage of
isMounted
- inferno/no-multi-comp: Prevent multiple component definition per file
- inferno/no-redundant-should-component-update: Prevent usage of
shouldComponentUpdate
when extending Inferno.PureComponent - inferno/no-render-return-value: Prevent usage of the return value of
Inferno.render
- inferno/no-set-state: Prevent usage of
setState
- inferno/no-typos: Prevent common casing typos
- inferno/no-string-refs: Prevent using string references in
ref
attribute. - inferno/no-unescaped-entities: Prevent invalid characters from appearing in markup
- inferno/no-unknown-property: Prevent usage of unknown DOM property (fixable)
- inferno/no-will-update-set-state: Prevent usage of
setState
incomponentWillUpdate
- inferno/prefer-es6-class: Enforce ES5 or ES6 class for Inferno Components
- inferno/prefer-stateless-function: Enforce stateless Inferno Components to be written as a pure function
- inferno/inferno-in-jsx-scope: Prevent missing
Inferno
when using JSX - inferno/require-optimization: Enforce Inferno components to have a
shouldComponentUpdate
method - inferno/require-render-return: Enforce ES5 or ES6 class for returning value in render function
- inferno/self-closing-comp: Prevent extra closing tags for components without children (fixable)
- inferno/sort-comp: Enforce component methods order (fixable)
- inferno/style-prop-object: Enforce style prop value being an object
- inferno/void-dom-elements-no-children: Prevent void DOM elements (e.g.
<img />
,<br />
) from receiving children
- inferno/jsx-boolean-value: Enforce boolean attributes notation in JSX (fixable)
- inferno/jsx-child-element-spacing: Enforce or disallow spaces inside of curly braces in JSX attributes and expressions.
- inferno/jsx-closing-bracket-location: Validate closing bracket location in JSX (fixable)
- inferno/jsx-closing-tag-location: Validate closing tag location in JSX (fixable)
- inferno/jsx-curly-spacing: Enforce or disallow spaces inside of curly braces in JSX attributes and expressions (fixable)
- inferno/jsx-equals-spacing: Enforce or disallow spaces around equal signs in JSX attributes (fixable)
- inferno/jsx-filename-extension: Restrict file extensions that may contain JSX
- inferno/jsx-first-prop-new-line: Enforce position of the first prop in JSX (fixable)
- inferno/jsx-handler-names: Enforce event handler naming conventions in JSX
- inferno/jsx-indent: Validate JSX indentation (fixable)
- inferno/jsx-indent-props: Validate props indentation in JSX (fixable)
- inferno/jsx-key: Validate JSX has key prop when in array or iterator
- inferno/jsx-max-props-per-line: Limit maximum of props on a single line in JSX (fixable)
- inferno/jsx-max-depth: Validate JSX maximum depth
- inferno/jsx-no-comment-textnodes: Prevent comments from being inserted as text nodes
- inferno/jsx-no-duplicate-props: Prevent duplicate props in JSX
- inferno/jsx-no-literals: Prevent usage of unwrapped JSX strings
- inferno/jsx-no-target-blank: Prevent usage of unsafe
target='_blank'
- inferno/jsx-no-undef: Disallow undeclared variables in JSX
- inferno/jsx-one-expression-per-line: Limit to one expression per line in JSX
- inferno/jsx-pascal-case: Enforce PascalCase for user-defined JSX components
- inferno/jsx-sort-props: Enforce props alphabetical sorting (fixable)
- inferno/jsx-sort-default-props: Enforce default props alphabetical sorting
- inferno/jsx-tag-spacing: Validate whitespace in and around the JSX opening and closing brackets (fixable)
- inferno/jsx-uses-inferno: Prevent Inferno to be incorrectly marked as unused
- inferno/jsx-uses-vars: Prevent variables used in JSX to be incorrectly marked as unused
- inferno/jsx-wrap-multilines: Prevent missing parentheses around multilines JSX (fixable)
- JSX accessibility: eslint-plugin-jsx-a11y
This plugin exports a recommended
configuration that enforce Inferno good practices.
To enable this configuration use the extends
property in your .eslintrc
config file:
{
"extends": ["eslint:recommended", "plugin:inferno/recommended"]
}
See ESLint documentation for more information about extending configuration files.
The rules enabled in this configuration are:
- inferno/jsx-key
- inferno/jsx-no-comment-textnodes
- inferno/jsx-no-duplicate-props
- inferno/jsx-no-undef
- inferno/jsx-uses-inferno
- inferno/jsx-no-target-blank
- inferno/jsx-uses-vars
- inferno/no-direct-mutation-state
- inferno/no-find-dom-node
- inferno/no-children-prop
- inferno/no-danger-with-children
- inferno/no-render-return-value
- inferno/inferno-in-jsx-scope
- inferno/no-direct-mutation-state
- inferno/no-find-dom-node
- inferno/no-is-mounted
- inferno/no-string-refs
- inferno/no-unescaped-entities
- inferno/no-unknown-property
This plugin also exports an all
configuration that includes every available rule.
This pairs well with the eslint:all
rule.
{
"plugins": [
"inferno"
],
"extends": ["eslint:all", "plugin:inferno/all"]
}
Note: These configurations will import eslint-plugin-inferno
and enable JSX in parser options.
ESLint-plugin-Inferno is licensed under the MIT License.