eslint-plugin-inferno
Note: This is a fork of the great eslint-plugin-react.
Inferno specific linting rules for ESLint. Linting logic has been optimized for InfernoJS library.
Some of the rules has been removed because they don't work in context of InfernoJS.
Please see [not supported rules] section.
This plugins support NodeJS v20+, eslint v8+ and Inferno v6+
Legacy versions of nodejs and eslint are not supported to reduce code complexity
Installation
Install eslint
either locally or globally. (Note that locally, per project, is strongly preferred)
$ npm install eslint@7 --save-dev
It is also possible to install ESLint globally rather than locally (using npm install -g eslint
). However, this is not recommended, and any plugins or shareable configs that you use must be installed locally in either case.
Configuration (Eslint v9)
Flat Configs
This plugin exports 3 flat configs:
flat.all
flat.recommended
The flat configs are available via the root plugin import. They will configure the plugin under the inferno/
namespace and enable JSX in languageOptions.parserOptions
.
const infernoPlugin = require('eslint-plugin-inferno');
module.exports = [
…
infernoPlugin.configs.flat.recommended,
…
];
You can of course add/override some properties.
Note: Our shareable configs does not preconfigure files
or languageOptions.globals
.
For most of the cases, you probably want to configure some properties by yourself.
const infernoPlugin = require('eslint-plugin-inferno');
const globals = require('globals');
module.exports = [
…
{
files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
...infernoPlugin.configs.flat.recommended,
languageOptions: {
...infernoPlugin.configs.flat.recommended.languageOptions,
globals: {
...globals.serviceworker,
...globals.browser,
},
},
},
…
];
The above example is same as the example below, as the new config system is based on chaining.
const infernoPlugin = require('eslint-plugin-inferno');
const globals = require('globals');
module.exports = [
…
{
files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
...infernoPlugin.configs.flat.recommended,
},
{
files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
languageOptions: {
globals: {
...globals.serviceworker,
...globals.browser,
},
},
},
…
];
Configuration (legacy: .eslintrc*
)
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. (More about eslint shared settings)
{
"settings": {
"inferno": {
"createClass": "createClass", // Regex for Component Factory to use, default to "createClass"
"pragma": "Inferno", // Pragma to use, default to "Inferno"
"fragment": "Fragment", // Fragment to use (may be a property of <pragma>), default to "Fragment"
},
"propWrapperFunctions": [
// The names of any function used to wrap propTypes, e.g. `forbidExtraProps`. If this isn't set, any propTypes wrapped in a function will be skipped.
"forbidExtraProps",
{"property": "freeze", "object": "Object"},
{"property": "myFavoriteWrapper"},
// for rules that check exact prop wrappers
{"property": "forbidExtraProps", "exact": true}
],
"componentWrapperFunctions": [
// The name of any function used to wrap components, e.g. Mobx `observer` function. If this isn't set, components wrapped by these functions will be skipped.
"observer", // `property`
{"property": "styled"}, // `object` is optional
{"property": "observer", "object": "Mobx"},
{"property": "observer", "object": "<pragma>"} // sets `object` to whatever value `settings.inferno.pragma` is set to
],
"formComponents": [
// Components used as alternatives to <form> for forms, eg. <Form endpoint={ url } />
"CustomForm",
{"name": "SimpleForm", "formAttribute": "endpoint"},
{"name": "Form", "formAttribute": ["registerEndpoint", "loginEndpoint"]}, // allows specifying multiple properties if necessary
],
"linkComponents": [
// Components used as alternatives to <a> for linking, eg. <Link to={ url } />
"Hyperlink",
{"name": "MyLink", "linkAttribute": "to"},
{"name": "Link", "linkAttribute": ["to", "href"]}, // allows specifying multiple properties if necessary
]
}
}
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-vars": "error",
}
Shareable configs
These rules have been removed because they don't make sense in context of InfernoJS.
InfernoJS does not have prop-types or UNSAFE_ -lifecycle methods.
- react/default-props-match-prop-types
- react/display-name
- react/forbid-foreign-prop-types
- react/forbid-prop-types
- react/no-deprecated
- react/no-unsafe
- react/no-unused-prop-types
- react/prop-types
- react/sort-prop-types
- react/require-default-props
- react/prefer-read-only-props
- react/style-prop-object
- react/hook-use-state
- react/prefer-read-only-props
- react/prefer-exact-props
Other useful plugins
Recommended
This plugin exports a recommended
configuration that enforces 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.
All
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.
Configuration (new: eslint.config.js
)
From v8.21.0
, eslint announced a new config system.
In the new system, .eslintrc*
is no longer used. eslint.config.js
would be the default config file name.
In eslint v8
, the legacy system (.eslintrc*
) would still be supported, while in eslint v9
, only the new system would be supported.
And from v8.23.0
, eslint CLI starts to look up eslint.config.js
.
So, if your eslint is >=8.23.0
, you're 100% ready to use the new config system.
You might want to check out the official blog posts,
and the official docs.
Plugin
The default export of eslint-plugin-inferno
is a plugin object.
const inferno = require('eslint-plugin-inferno');
const globals = require('globals');
module.exports = [
…
{
files: ['**/*.{js,jsx,mjs,cjs,ts,tsx}'],
plugins: {
inferno,
},
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
globals: {
...globals.browser,
},
},
rules: {
'inferno/jsx-uses-vars': 'error',
},
},
…
];
List of supported rules
💼 Configurations enabled in.
☑️ Set in the recommended
configuration.
🔧 Automatically fixable by the --fix
CLI option.
💡 Manually fixable by editor suggestions.
❌ Deprecated.
License
eslint-plugin-inferno
is licensed under the MIT License.