Skip to content

Commit

Permalink
Add flow config and rules
Browse files Browse the repository at this point in the history
  • Loading branch information
wyze committed Nov 6, 2016
1 parent a69ce15 commit 9b11043
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 0 deletions.
10 changes: 10 additions & 0 deletions flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
extends: [
'plugin:flowtype/recommended',
'wyze/rules/flow',
],
parser: 'babel-eslint',
plugins: [
'flowtype',
],
}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,21 @@
}
},
"peerDependencies": {
"babel-eslint": "^7.1.0",
"eslint": "^3.9.0",
"eslint-config-airbnb": "^12.0.0",
"eslint-plugin-flowtype": "^2.25.0",
"eslint-plugin-import": "^2.0.0",
"eslint-plugin-jsx-a11y": "^2.2.0",
"eslint-plugin-react": "^6.4.0",
"eslint-plugin-wyze": "^2.0.0"
},
"devDependencies": {
"ava": "^0.16.0",
"babel-eslint": "^7.1.0",
"eslint": "^3.9.1",
"eslint-config-airbnb": "^12.0.0",
"eslint-plugin-flowtype": "^2.25.0",
"eslint-plugin-import": "^2.0.1",
"eslint-plugin-jsx-a11y": "^2.2.3",
"eslint-plugin-react": "^6.4.1",
Expand Down
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ Project without React:
$ npm i --save-dev eslint eslint-config-airbnb eslint-config-wyze eslint-plugin-import eslint-plugin-wyze
```

Project with Flow:

```sh
$ npm i --save-dev babel-eslint eslint eslint-config-wyze eslint-plugin-flowtype
```

## Usage

### package.json
Expand Down
31 changes: 31 additions & 0 deletions rules/flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
rules: {
// same as comma-dangle from ESLint
// https://github.com/gajus/eslint-plugin-flowtype#delimiter-dangle
'flowtype/delimiter-dangle': [ 2, 'always-multiline' ],
// disallow duplicate keys in types
// https://github.com/gajus/eslint-plugin-flowtype#no-dupe-keys
'flowtype/no-dupe-keys': 2,
// better to be specific, but only warn
// https://github.com/gajus/eslint-plugin-flowtype#no-weak-types
'flowtype/no-weak-types': 1,
// only use commas in object types
// https://github.com/gajus/eslint-plugin-flowtype#object-type-delimiter
'flowtype/object-type-delimiter': [ 2, 'comma' ],
// type all the functions!
// https://github.com/gajus/eslint-plugin-flowtype#require-parameter-type
'flowtype/require-parameter-type': 2,
// just warn about missing return types
// https://github.com/gajus/eslint-plugin-flowtype#require-return-type
'flowtype/require-return-type': 1,
// warn when a file isn't typed
// https://github.com/gajus/eslint-plugin-flowtype#require-valid-file-annotation
'flowtype/require-valid-file-annotation': 1,
// ew, semicolons
// https://github.com/gajus/eslint-plugin-flowtype#semi
'flowtype/semi': [ 2, 'never' ],
// enforce type names to begin with uppercase letter
// https://github.com/gajus/eslint-plugin-flowtype#type-id-match
'flowtype/type-id-match': [ 2, '^[A-Z].*$' ],
},
}
25 changes: 25 additions & 0 deletions test/flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import flow from '../flow'
import test from 'ava'

test('extends files', t => {
const expected = [
'plugin:flowtype/recommended',
'wyze/rules/flow',
]

t.deepEqual(flow.extends, expected, 'extending incorrect rules')
})

test('parser is set correctly', t => {
const expected = 'babel-eslint'

t.is(flow.parser, expected)
})

test('plugins are set correctly', t => {
const expected = [
'flowtype',
]

t.deepEqual(flow.plugins, expected)
})
8 changes: 8 additions & 0 deletions test/rules/flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { rules } from '../../rules/flow'
import test from 'ava'

test('only flowtype rules', t => {
Object.keys(rules).forEach(rule => {
t.truthy(~rule.indexOf('flowtype/'))
})
})

0 comments on commit 9b11043

Please sign in to comment.