Skip to content

Commit a8e75f8

Browse files
authored
add recommended eslint config (#170)
* add recommended eslint config * fix exports bugs * update CHANGELOG * add demo to related links
1 parent edb7b1e commit a8e75f8

7 files changed

Lines changed: 827 additions & 589 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v4.1.0
2+
### Added
3+
- Recommended config 🎉
4+
15
## v4.0.0
26
### Fixed
37
- Fix Flow `>= v0.71` on Windows

README.md

Lines changed: 14 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -7,77 +7,36 @@ eslint-plugin-flowtype-errors
77
[![npm](https://img.shields.io/npm/dm/eslint-plugin-flowtype-errors.svg)](https://npm-stat.com/charts.html?package=eslint-plugin-flowtype-errors)
88

99
## Demo
10-
![ESLint Flow Demo](https://github.com/amilajack/eslint-plugin-flowtype-errors/blob/master/flow-demo.gif?raw=true)
1110

12-
*NOTE:* This demo is using Atom and the packages `linter`, `linter-eslint`, `language-babel`
11+
![ESLint Flow Demo](https://github.com/amilajack/eslint-plugin-flowtype-errors/blob/master/flow-demo.gif?raw=true)
1312

1413
## Why?
14+
1515
* **Lower barrier:** Any editor that has ESLint support now supports Flow 🎉
1616
* **Less editor configuration:** No need to change your entire workflow to incorporate flow. No multiple-linters-per-file nonsense.
1717
* **Simple:** Its literally just an ESLint rule! Just install the dependency, add a flowconfig, and you're good to go!
1818

1919
## Getting Started
20+
2021
This guide assumes that you have installed eslint, babel, babel-plugin-transform-flow-strip-types and configured flow. Check out the [from-scratch guide](https://github.com/amilajack/eslint-plugin-flowtype-errors/wiki/Getting-Started) for the full guide on getting started.
2122

22-
⚠️ Make sure the 64-bit version of your texteditor/IDE. For atom, [see this comment](https://github.com/amilajack/eslint-plugin-flowtype-errors/issues/40#issuecomment-275983387)
23+
⚠️ Make sure the 64-bit version of your text editor or IDE. For atom, [see this comment](https://github.com/amilajack/eslint-plugin-flowtype-errors/issues/40#issuecomment-275983387)
2324

24-
**Step 1. Install**
25+
### **1. Install**
2526

2627
```bash
2728
npm install --save-dev eslint-plugin-flowtype-errors
2829
```
2930

30-
**Step 2. Configure**
31-
32-
Add this line to the 'rules' section of your `.eslintrc` to report flow errors.
33-
```js
34-
"flowtype-errors/show-errors": "error"
35-
```
36-
37-
Add this line to the 'rules' section of your `.eslintrc` to report flow warnings.
38-
```js
39-
"flowtype-errors/show-warnings": "warn"
40-
```
41-
Note that flow won't report warnings unless you add this setting to your `.flowconfig`:
42-
```toml
43-
[options]
44-
include_warnings=true
45-
```
46-
47-
Add this line to the 'rules' section of your `.eslintrc` to enforce a minimum percentage of flow coverage per file (optional). Here's an example of enforcing a converage of at least 50%:
48-
```js
49-
"flowtype-errors/enforce-min-coverage": ["error", 50]
50-
```
31+
### **2. Configure**
5132

52-
Add this line to the 'plugins' section of your `.eslintrc`
53-
```js
54-
"flowtype-errors"
33+
Extend the recommended config:
34+
```jsonc
35+
{
36+
"extends": ["plugin:flowtype-errors/recommended"]
37+
}
5538
```
5639

57-
Add the `@flow` pragma to files that you want to lint
58-
Also make sure that your `.flowconfig` is in the root of your project directory
59-
```js
60-
/**
61-
* @flow
62-
*/
63-
```
64-
65-
**Step 3. Settings (optional)**
66-
67-
Add this line to the 'settings' section of your `.eslintrc` to force the Flow server to stop after it finishes checking types.
68-
69-
```js
70-
"settings": {
71-
"flowtype-errors": {
72-
"stopOnExit": true
73-
}
74-
},
75-
```
76-
77-
**Step 4. Lint**
78-
79-
Run `eslint` and you're all set!
80-
8140
## Support
8241

8342
If this project is saving you (or your team) time, please consider supporting it on Patreon 👍 thank you!
@@ -89,29 +48,11 @@ If this project is saving you (or your team) time, please consider supporting it
8948
</p>
9049

9150
## CI Configuration
92-
**Flow is supported on all OS's except Windows 32bit. Add [this line](https://github.com/amilajack/eslint-plugin-flowtype-errors/blob/master/appveyor.yml#L12) to appveyor to make tests run properly.**
93-
94-
## Editor Configuration
95-
### Atom
96-
```bash
97-
apm install linter linter-eslint language-babel
98-
```
99-
100-
### Sublime
101-
* https://github.com/SublimeLinter/SublimeLinter3
102-
* https://github.com/roadhump/SublimeLinter-eslint
103-
* https://github.com/babel/babel-sublime
10451

105-
### Others
106-
http://eslint.org/docs/user-guide/integrations#editors
52+
Flow is supported on all OS's except Windows 32bit. Add [this line](https://github.com/amilajack/eslint-plugin-flowtype-errors/blob/master/appveyor.yml#L12) to appveyor to make tests run properly.
10753

108-
## Planned Implementations
109-
* Add more extensive tests
110-
* Allow passing arguments to flow binary
111-
* Run flow minimal amount of times for faster linting
112-
* Custom formatting of flow error messages
113-
* Enable rules to allow and disallow specific flow errors
54+
## Related:
11455

115-
## Related flow tools:
11656
* [flow-runtime](https://github.com/codemix/flow-runtime)
11757
* [eslint-plugin-flowtype](https://github.com/gajus/eslint-plugin-flowtype)
58+
* [eslint-plugin-flowtype-errors-demo](https://github.com/amilajack/eslint-plugin-flowtype-errors-demo)

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,24 @@
3030
"dist"
3131
],
3232
"dependencies": {
33-
"@babel/runtime": "^7.3.4",
33+
"@babel/runtime": "^7.4.2",
3434
"find-up": "^3.0.0",
3535
"slash": "^2.0.0"
3636
},
3737
"devDependencies": {
3838
"@babel/cli": "^7.2.3",
39-
"@babel/core": "^7.3.4",
40-
"@babel/plugin-proposal-class-properties": "^7.3.4",
41-
"@babel/preset-env": "^7.3.4",
39+
"@babel/core": "^7.4.0",
40+
"@babel/plugin-proposal-class-properties": "^7.4.0",
41+
"@babel/preset-env": "^7.4.2",
4242
"@babel/preset-flow": "^7.0.0",
43-
"@babel/register": "^7.0.0",
43+
"@babel/register": "^7.4.0",
4444
"babel-core": "^7.0.0-bridge.0",
4545
"babel-eslint": "^10.0.1",
46-
"babel-jest": "^24.1.0",
46+
"babel-jest": "^24.5.0",
4747
"chai": "^4.2.0",
4848
"cross-env": "^5.2.0",
4949
"cross-spawn": "^6.0.5",
50-
"eslint": "5.14.1",
50+
"eslint": "5.15.3",
5151
"eslint-config-airbnb-base": "^13.1.0",
5252
"eslint-config-prettier": "^4.1.0",
5353
"eslint-formatter-pretty": "^2.1.1",
@@ -57,11 +57,11 @@
5757
"eslint-plugin-prettier": "^3.0.1",
5858
"eslint-plugin-vue": "^5.2.2",
5959
"execa": "^1.0.0",
60-
"flow-bin": "0.93.0",
60+
"flow-bin": "0.95.1",
6161
"husky": "^1.3.1",
62-
"jest-cli": "^24.1.0",
62+
"jest-cli": "^24.5.0",
6363
"prettier": "^1.16.4",
64-
"regenerator-runtime": "^0.13.1"
64+
"regenerator-runtime": "^0.13.2"
6565
},
6666
"peerDependencies": {
6767
"eslint": ">=4.0.0",

src/config/recommended.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
plugins: ['flowtype-errors'],
3+
rules: {
4+
'flowtype-errors/show-errors': 'error'
5+
}
6+
};

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import path from 'path';
44
import fs from 'fs';
55
// $FlowIgnore
66
import findUp from 'find-up';
7+
import recommended from './config/recommended';
78
import {
89
type CollectOutputElement,
910
FlowSeverity,
@@ -153,6 +154,9 @@ function createFilteredErrorRule(filter: CollectOutputElement => any) {
153154
}
154155

155156
export default {
157+
configs: {
158+
recommended
159+
},
156160
rules: {
157161
'enforce-min-coverage': function enforceMinCoverage(
158162
context: EslintContext

test/__snapshots__/format.spec.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ exports[`Check codebases project-1 - eslint should give expected output 1`] = `
130130
131131
./9.example.js
132132
8:18 error Cannot create \`Hello\` element because property \`name\` is missing in props but exists in object type (see ./9.example.import.js:6) flowtype-errors/show-errors
133-
8:28 error Cannot call \`ReactDOM.render\` with \`document.getElementById(...)\` bound to \`container\` because null (see https://github.com/facebook/flow/blob/v0.93.0/lib/dom.js#L783) is incompatible with \`Element\` (see https://github.com/facebook/flow/blob/v0.93.0/lib/react-dom.js#L18) flowtype-errors/show-errors
133+
8:28 error Cannot call \`ReactDOM.render\` with \`document.getElementById(...)\` bound to \`container\` because null (see https://github.com/facebook/flow/blob/v0.95.1/lib/dom.js#L785) is incompatible with \`Element\` (see https://github.com/facebook/flow/blob/v0.95.1/lib/react-dom.js#L18) flowtype-errors/show-errors
134134
135135
✖ 21 problems (21 errors, 0 warnings)
136136
@@ -600,7 +600,7 @@ Array [
600600
"offset": 170,
601601
},
602602
},
603-
"message": "Cannot call \`ReactDOM.render\` with \`document.getElementById(...)\` bound to \`container\` because null (see https://github.com/facebook/flow/blob/v0.93.0/lib/dom.js#L783) is incompatible with \`Element\` (see https://github.com/facebook/flow/blob/v0.93.0/lib/react-dom.js#L18).",
603+
"message": "Cannot call \`ReactDOM.render\` with \`document.getElementById(...)\` bound to \`container\` because null (see https://github.com/facebook/flow/blob/v0.95.1/lib/dom.js#L785) is incompatible with \`Element\` (see https://github.com/facebook/flow/blob/v0.95.1/lib/react-dom.js#L18).",
604604
"start": 9,
605605
"type": "default",
606606
},

0 commit comments

Comments
 (0)