|
| 1 | +<h1 id="eslint-plugin-flowtype">eslint-plugin-flowtype</h1> |
| 2 | + |
| 3 | +[](https://www.npmjs.org/package/eslint-plugin-flowtype) |
| 4 | +[](https://travis-ci.org/gajus/eslint-plugin-flowtype) |
| 5 | +[](https://github.com/gajus/canonical) |
| 6 | + |
| 7 | +[Flow type](http://flowtype.org/) linting rules for ESLint. |
| 8 | + |
| 9 | +* [eslint-plugin-flowtype](#eslint-plugin-flowtype) |
| 10 | + * [Installation](#eslint-plugin-flowtype-installation) |
| 11 | + * [Configuration](#eslint-plugin-flowtype-configuration) |
| 12 | + * [Rules](#eslint-plugin-flowtype-rules) |
| 13 | + * [`require-parameter-type`](#eslint-plugin-flowtype-rules-require-parameter-type) |
| 14 | + * [`require-return-type`](#eslint-plugin-flowtype-rules-require-return-type) |
| 15 | + * [`space-after-type-colon`](#eslint-plugin-flowtype-rules-space-after-type-colon) |
| 16 | + * [`space-before-type-colon`](#eslint-plugin-flowtype-rules-space-before-type-colon) |
| 17 | + * [`eslint-plugin-flowtype` v1](#eslint-plugin-flowtype-eslint-plugin-flowtype-v1) |
| 18 | + |
| 19 | + |
| 20 | +<h2 id="eslint-plugin-flowtype-installation">Installation</h2> |
| 21 | + |
| 22 | +1. Install [ESLint](https://www.github.com/eslint/eslint). |
| 23 | +1. Install [`babel-eslint`](https://github.com/babel/babel-eslint) parser (ESLint parser [does not support type annotations](https://github.com/eslint/eslint/issues/2157)). |
| 24 | +1. Install [`eslint-plugin-flowtype`](https://github.com/gajus/eslint-plugin-flowtype) plugin. |
| 25 | + |
| 26 | +<!-- --> |
| 27 | + |
| 28 | +```sh |
| 29 | +npm install eslint |
| 30 | +npm install babel-eslint |
| 31 | +npm install eslint-plugin-flowtype |
| 32 | +``` |
| 33 | + |
| 34 | +<h2 id="eslint-plugin-flowtype-configuration">Configuration</h2> |
| 35 | + |
| 36 | +1. Set `parser` property to `babel-eslint`. |
| 37 | +1. Add `plugins` section and specify `eslint-plugin-flowtype` as a plugin. |
| 38 | +1. Enable rules. |
| 39 | + |
| 40 | +<!-- --> |
| 41 | + |
| 42 | +```json |
| 43 | +{ |
| 44 | + "parser": "babel-eslint", |
| 45 | + "plugins": [ |
| 46 | + "flowtype" |
| 47 | + ], |
| 48 | + "rules": { |
| 49 | + "flowtype/require-parameter-type": 1, |
| 50 | + "flowtype/require-return-type": 1, |
| 51 | + "flowtype/space-after-type-colon": 1, |
| 52 | + "flowtype/space-before-type-colon": 1 |
| 53 | + } |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +<h2 id="eslint-plugin-flowtype-rules">Rules</h2> |
| 58 | + |
| 59 | +<h3 id="eslint-plugin-flowtype-rules-require-parameter-type"><code>require-parameter-type</code></h3> |
| 60 | + |
| 61 | +Requires that all function parameters have type annotations. |
| 62 | + |
| 63 | +The following patterns are considered problems: |
| 64 | + |
| 65 | +```js |
| 66 | +(foo) => {} |
| 67 | +// Message: Missing "foo" parameter type annotation. |
| 68 | + |
| 69 | +(foo = 'FOO') => {} |
| 70 | +// Message: Missing "foo" parameter type annotation. |
| 71 | + |
| 72 | +(...foo) => {} |
| 73 | +// Message: Missing "foo" parameter type annotation. |
| 74 | + |
| 75 | +({foo}) => {} |
| 76 | +// Message: Missing "{foo}" parameter type annotation. |
| 77 | +``` |
| 78 | + |
| 79 | +The following patterns are not considered problems: |
| 80 | + |
| 81 | +```js |
| 82 | +(foo: string) => {} |
| 83 | + |
| 84 | +(foo: string = 'FOO') => {} |
| 85 | + |
| 86 | +(...foo: string) => {} |
| 87 | + |
| 88 | +({foo}: {foo: string}) => {} |
| 89 | +``` |
| 90 | + |
| 91 | + |
| 92 | +<h3 id="eslint-plugin-flowtype-rules-require-return-type"><code>require-return-type</code></h3> |
| 93 | + |
| 94 | +Requires that functions have return type annotation. |
| 95 | + |
| 96 | +The following patterns are considered problems: |
| 97 | + |
| 98 | +```js |
| 99 | +(foo) => {} |
| 100 | +// Message: Missing return type annotation. |
| 101 | +``` |
| 102 | + |
| 103 | +The following patterns are not considered problems: |
| 104 | + |
| 105 | +```js |
| 106 | +(foo): string => {} |
| 107 | +``` |
| 108 | + |
| 109 | + |
| 110 | +<h3 id="eslint-plugin-flowtype-rules-space-after-type-colon"><code>space-after-type-colon</code></h3> |
| 111 | + |
| 112 | +Enforces consistent spacing after the type annotation colon. |
| 113 | + |
| 114 | +This rule takes one argument. If it is `'always'` then a problem is raised when there is no space after the type annotation colon. If it is `'never'` then a problem is raised when there is a space after the type annotation colon. The default value is `'always'`. |
| 115 | + |
| 116 | +The following patterns are considered problems: |
| 117 | + |
| 118 | +```js |
| 119 | +// Options: ["never"] |
| 120 | +(foo: string) => {} |
| 121 | +// Message: There must be no space after "foo" parameter type annotation colon. |
| 122 | + |
| 123 | +// Options: ["always"] |
| 124 | +(foo:string) => {} |
| 125 | +// Message: There must be a space after "foo" parameter type annotation colon. |
| 126 | + |
| 127 | +// Options: ["always"] |
| 128 | +(foo: string) => {} |
| 129 | +// Message: There must be 1 space after "foo" parameter type annotation colon. |
| 130 | +``` |
| 131 | + |
| 132 | +The following patterns are not considered problems: |
| 133 | + |
| 134 | +```js |
| 135 | +(foo) => {} |
| 136 | + |
| 137 | +(foo: string) => {} |
| 138 | + |
| 139 | +// Options: ["never"] |
| 140 | +(foo:string) => {} |
| 141 | + |
| 142 | +// Options: ["always"] |
| 143 | +(foo: string) => {} |
| 144 | +``` |
| 145 | + |
| 146 | + |
| 147 | +<h3 id="eslint-plugin-flowtype-rules-space-before-type-colon"><code>space-before-type-colon</code></h3> |
| 148 | + |
| 149 | +Enforces consistent spacing before the type annotation colon. |
| 150 | + |
| 151 | +This rule takes one argument. If it is `'always'` then a problem is raised when there is no space before the type annotation colon. If it is `'never'` then a problem is raised when there is a space before the type annotation colon. The default value is `'never'`. |
| 152 | + |
| 153 | +The following patterns are considered problems: |
| 154 | + |
| 155 | +```js |
| 156 | +// Options: ["never"] |
| 157 | +(foo : string) => {} |
| 158 | +// Message: There must be no space before "foo" parameter type annotation colon. |
| 159 | + |
| 160 | +// Options: ["always"] |
| 161 | +(foo: string) => {} |
| 162 | +// Message: There must be a space before "foo" parameter type annotation colon. |
| 163 | + |
| 164 | +// Options: ["always"] |
| 165 | +(foo : string) => {} |
| 166 | +// Message: There must be 1 space before "foo" parameter type annotation colon. |
| 167 | +``` |
| 168 | + |
| 169 | +The following patterns are not considered problems: |
| 170 | + |
| 171 | +```js |
| 172 | +(foo) => {} |
| 173 | + |
| 174 | +(foo: string) => {} |
| 175 | + |
| 176 | +// Options: ["never"] |
| 177 | +(foo: string) => {} |
| 178 | + |
| 179 | +// Options: ["always"] |
| 180 | +(foo : string) => {} |
| 181 | +``` |
| 182 | + |
| 183 | + |
| 184 | + |
| 185 | +<h2 id="eslint-plugin-flowtype-eslint-plugin-flowtype-v1"><code>eslint-plugin-flowtype</code> v1</h2> |
| 186 | + |
| 187 | +`eslint-plugin-flowtype` v1 served a different purpose: |
| 188 | + |
| 189 | +> A plugin for ESLint that strips FlowType type annonations before linting the files. |
| 190 | +
|
| 191 | +You can find the source code for v1 at: |
| 192 | + |
| 193 | +https://github.com/gcazaciuc/eslint-plugin-flowtype |
| 194 | + |
| 195 | +Reference to the original codebase included for historical reference purposes. |
0 commit comments