I am using ESLint in a project and want to use Facebook flow as well, But I am getting warnings from ESLint on flow type annotations.
I have .flowconfig and .eslintrc in project root.
.eslintrc:
// When you write javascript you should follow these soft rules and best practices
// https://github.com/airbnb/javascript
// This is a link to best practices and enforcer settings for eslint
// https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb
// Use this file as a starting point for your project's .eslintrc.
{
"extends": "airbnb",
"plugins": [
"flow-vars"
],
"rules": {
"flow-vars/define-flow-type": 1,
"flow-vars/use-flow-type": 1
}
}
What should I do to make it work? Is there a way to run flow in watch task together using webpack?
Use npm install eslint --global to install ESLint globally. Go to your project in the terminal and run eslint --init to initiate and setup linting for your project. Install and automate your workflow in VSCode using ESLint extension.
ESLint plugins allow you to add custom rules according to the needs of your project. Plugins are published as npm modules with names in the format of eslint-plugin-<plugin-name> . To use the plugin, you need to first install it via npm, and then you can add it to your eslintrc configuration via the plugins key.
flow-vars
is deprecated!
This is the current proper way of getting Flow running with Airbnb's (with eslint-plugin-flowtype
):
This assumes you already have flow installed.
npm install --save-dev eslint babel-eslint eslint-plugin-flowtype
.eslintrc
{
"extends": [
"airbnb",
"plugin:flowtype/recommended"
],
"parser": "babel-eslint",
"plugins": [
"flowtype"
]
}
Want custom configuration instead?
For me, the problem was solved by adding "parser": "babel-eslint"
to my .eslintrc
.
(I had to run npm install babel-eslint --save-dev
first though).
{
"extends": "airbnb",
"parser": "babel-eslint", // <--
"plugins": [
"flow-vars"
],
"rules": {
"flow-vars/define-flow-type": 1,
"flow-vars/use-flow-type": 1
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With