eslint-plugin-mithril
Mithril specific linting rules for ESLint
Installation
You'll first need to install ESLint:
$ npm i eslint --save-dev
Next, install eslint-plugin-mithril
:
$ npm install eslint-plugin-mithril --save-dev
Note: If you installed ESLint globally (using the -g
flag) then you must also install eslint-plugin-mithril
globally.
Usage
Use our preset to get reasonable defaults:
"extends": [
"eslint:recommended",
"plugin:mithril/recommended"
]
If you do not use a preset you will need to specify individual rules and add extra configuration.
Add mithril
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
{
"plugins": [
"mithril"
]
}
Then configure the rules you want to use under the rules section.
{
"rules": {
"mithril/jsx-uses-vars": 2
}
}
Supported Rules
JSX-common rules
- mithril/jsx-boolean-value: Enforce boolean attributes notation in JSX (fixable)
- mithril/jsx-child-element-spacing: Enforce or disallow spaces inside of curly braces in JSX attributes and expressions.
- mithril/jsx-closing-bracket-location: Validate closing bracket location in JSX (fixable)
- mithril/jsx-closing-tag-location: Validate closing tag location in JSX (fixable)
- mithril/jsx-curly-spacing: Enforce or disallow spaces inside of curly braces in JSX attributes and expressions (fixable)
- mithril/jsx-equals-spacing: Enforce or disallow spaces around equal signs in JSX attributes (fixable)
- mithril/jsx-first-prop-new-line: Enforce position of the first prop in JSX (fixable)
- mithril/jsx-indent: Validate JSX indentation (fixable)
- mithril/jsx-indent-props: Validate props indentation in JSX (fixable)
- mithril/jsx-key: Validate JSX has key prop when in array or iterator
- mithril/jsx-max-depth: Validate JSX maximum depth
- mithril/jsx-max-props-per-line: Limit maximum of props on a single line in JSX (fixable)
- mithril/jsx-no-comment-textnodes: Prevent comments from being inserted as text nodes
- mithril/jsx-no-duplicate-props: Prevent duplicate props in JSX
- mithril/jsx-no-literals: Prevent usage of unwrapped JSX strings
- mithril/jsx-no-target-blank: Prevent usage of unsafe
target='_blank'
- mithril/jsx-no-undef: Disallow undeclared variables in JSX
- mithril/jsx-one-expression-per-line: Limit to one expression per line in JSX
- mithril/jsx-curly-brace-presence: Enforce curly braces or disallow unnecessary curly braces in JSX
- mithril/jsx-pascal-case: Enforce PascalCase for user-defined JSX components
- mithril/jsx-props-no-multi-spaces: Disallow multiple spaces between inline JSX props (fixable)
- mithril/jsx-sort-default-props: Enforce default props alphabetical sorting
- mithril/jsx-sort-props: Enforce props alphabetical sorting (fixable)
- mithril/jsx-tag-spacing: Validate whitespace in and around the JSX opening and closing brackets (fixable)
- mithril/jsx-uses-mithril: Prevent Mithril to be incorrectly marked as unused
- mithril/jsx-uses-vars: Prevent variables used in JSX to be incorrectly marked as unused
- mithril/jsx-wrap-multilines: Prevent missing parentheses around multilines JSX (fixable)
Mithril specific rules
Comming soon
Shareable configurations
Recommended
This plugin exports a recommended
configuration that enforces Mithril good practices.
To enable this configuration use the extends
property in your .eslintrc
config file:
{
"extends": ["eslint:recommended", "plugin:mithril/recommended"]
}
See ESLint documentation for more information about extending configuration files.
The rules enabled in this configuration are:
- mithril/jsx-key: Validate JSX has key prop when in array or iterator
- mithril/jsx-no-comment-textnodes: Prevent comments from being inserted as text nodes
- mithril/jsx-no-duplicate-props: Prevent duplicate props in JSX
- mithril/jsx-no-target-blank: Prevent usage of unsafe
target='_blank'
- mithril/jsx-no-undef: Disallow undeclared variables in JSX
- mithril/jsx-uses-mithril: Prevent Mithril to be incorrectly marked as unused
- mithril/jsx-uses-vars: Prevent variables used in JSX to be incorrectly marked as unused
All
This plugin also exports an all
configuration that includes every available rule.
This pairs well with the eslint:all
rule.
{
"plugins": [
"mithril"
],
"extends": ["eslint:all", "plugin:mithril/all"]
}
Note: These configurations will import eslint-plugin-mithril
and enable JSX in parser options.
Note: This repo is forked from yannickcr/eslint-plugin-react
License
ESLint-plugin-Mithril is licensed under the MIT License.