Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ESLint with Arbnb config and Facebook Flow together

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?

like image 578
Marcel Mandatory Avatar asked Mar 28 '16 07:03

Marcel Mandatory


People also ask

How do you use ESLint globally?

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.

What are ESLint plugins?

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.


2 Answers

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?

like image 137
zurfyx Avatar answered Nov 08 '22 11:11

zurfyx


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
  }
}
like image 8
Markus-ipse Avatar answered Nov 08 '22 11:11

Markus-ipse