Skip to content

Commit a916617

Browse files
authored
Merge branch 'master' into feat/array-style
2 parents 6320bee + 8f86c4b commit a916617

35 files changed

+9190
-10
lines changed

.README/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ To enable this configuration use the extends property in your `.eslintrc` config
122122

123123
See [ESLint documentation](http://eslint.org/docs/user-guide/configuring#extending-configuration-files) for more information about extending configuration files.
124124

125+
### Community maintained configurations
126+
127+
The following are third-party submitted/ maintained configurations of `eslint-plugin-flowtype`:
128+
129+
* https://github.com/wemake-services/eslint-config-flowtype-essential
130+
125131
## Settings
126132

127133
### `onlyFilesWithFlowAnnotation`
@@ -148,14 +154,20 @@ When `true`, only checks files with a [`@flow` annotation](http://flowtype.org/d
148154
{"gitdown": "include", "file": "./rules/define-flow-type.md"}
149155
{"gitdown": "include", "file": "./rules/delimiter-dangle.md"}
150156
{"gitdown": "include", "file": "./rules/generic-spacing.md"}
157+
{"gitdown": "include", "file": "./rules/newline-after-flow-annotation"}
151158
{"gitdown": "include", "file": "./rules/no-dupe-keys.md"}
159+
{"gitdown": "include", "file": "./rules/no-existential-type.md"}
160+
{"gitdown": "include", "file": "./rules/no-flow-fix-me-comments.md"}
161+
{"gitdown": "include", "file": "./rules/no-mutable-array.md"}
152162
{"gitdown": "include", "file": "./rules/no-primitive-constructor-types.md"}
153163
{"gitdown": "include", "file": "./rules/no-types-missing-file-annotation.md"}
154164
{"gitdown": "include", "file": "./rules/no-unused-expressions.md"}
155165
{"gitdown": "include", "file": "./rules/no-weak-types.md"}
156166
{"gitdown": "include", "file": "./rules/object-type-delimiter.md"}
167+
{"gitdown": "include", "file": "./rules/require-exact-type.md"}
157168
{"gitdown": "include", "file": "./rules/require-parameter-type.md"}
158169
{"gitdown": "include", "file": "./rules/require-return-type.md"}
170+
{"gitdown": "include", "file": "./rules/require-types-at-top.md"}
159171
{"gitdown": "include", "file": "./rules/require-valid-file-annotation.md"}
160172
{"gitdown": "include", "file": "./rules/require-variable-type.md"}
161173
{"gitdown": "include", "file": "./rules/semi.md"}
@@ -164,6 +176,7 @@ When `true`, only checks files with a [`@flow` annotation](http://flowtype.org/d
164176
{"gitdown": "include", "file": "./rules/space-before-generic-bracket.md"}
165177
{"gitdown": "include", "file": "./rules/space-before-type-colon.md"}
166178
{"gitdown": "include", "file": "./rules/type-id-match.md"}
179+
{"gitdown": "include", "file": "./rules/type-import-style.md"}
167180
{"gitdown": "include", "file": "./rules/union-intersection-spacing.md"}
168181
{"gitdown": "include", "file": "./rules/use-flow-type.md"}
169182
{"gitdown": "include", "file": "./rules/valid-syntax.md"}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
### `newline-after-flow-annotation`
2+
3+
This rule requires an empty line after the Flow annotation.
4+
5+
#### Options
6+
7+
The rule has a string option:
8+
9+
* `"always"` (default): Enforces that `@flow` annotations be followed by an empty line, separated by newline (LF)
10+
* `"always-windows"`: Identical to "always", but will use a CRLF when autofixing
11+
* `"never"`: Enforces that `@flow` annotations are not followed by empty lines
12+
13+
```js
14+
{
15+
"rules": {
16+
"flowtype/newline-after-flow-annotation": [
17+
2,
18+
"always"
19+
]
20+
}
21+
}
22+
```
23+
24+
25+
<!-- assertions newlineAfterFlowAnnotation -->
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
### `no-existential-type`
2+
3+
Disallows use of the existential type (*). [See more](https://flow.org/en/docs/types/utilities/#toc-existential-type)
4+
5+
```js
6+
{
7+
"rules": {
8+
"flowtype/no-existential-type": 2
9+
}
10+
}
11+
```
12+
13+
14+
<!-- assertions newlineAfterFlowAnnotation -->
15+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
### `no-flow-fix-me-comments`
2+
3+
Disallows `$FlowFixMe` comment suppressions.
4+
5+
This is especially useful as a warning to ensure instances of `$FlowFixMe` in your codebase get fixed over time.
6+
7+
#### Options
8+
9+
This rule takes an optional RegExp that comments a text RegExp that makes the supression valid.
10+
11+
```js
12+
{
13+
"rules": {
14+
"flowtype/no-flow-fix-me-comments": [
15+
1,
16+
"TODO\s+[0-9]+"
17+
]
18+
}
19+
}
20+
```
21+
22+
<!-- assertions no-flow-fix-me-comments -->

.README/rules/no-mutable-array.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
### `no-mutable-array`
2+
3+
_The `--fix` option on the command line automatically fixes problems reported by this rule._
4+
5+
Requires use of [`$ReadOnlyArray`](https://github.com/facebook/flow/blob/v0.46.0/lib/core.js#L185) instead of just `Array` or array [shorthand notation](https://flow.org/en/docs/types/arrays/#toc-array-type-shorthand-syntax). `$ReadOnlyArray` is immutable array collection type and the superclass of Array and tuple types in Flow. Use of `$ReadOnlyArray` instead of `Array` can solve some "problems" in typing with Flow (e.g., [1](https://github.com/facebook/flow/issues/3425), [2](https://github.com/facebook/flow/issues/4251)).
6+
7+
General reasons for using immutable data structures:
8+
9+
* They are simpler to construct, test, and use
10+
* They help to avoid temporal coupling
11+
* Their usage is side-effect free (no defensive copies)
12+
* Identity mutability problem is avoided
13+
* They always have failure atomicity
14+
* They are much easier to cache
15+
16+
<!-- assertions noMutableArray -->
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
### `require-exact-type`
2+
3+
This rule enforces [exact object types](https://flow.org/en/docs/types/objects/#toc-exact-object-types).
4+
5+
#### Options
6+
7+
The rule has one string option:
8+
9+
* `"always"` (default): Report all object type definitions that aren't exact.
10+
* `"never"`: Report all object type definitions that are exact.
11+
12+
```js
13+
{
14+
"rules": {
15+
"flowtype/require-exact-type": [
16+
2,
17+
"always"
18+
]
19+
}
20+
}
21+
22+
{
23+
"rules": {
24+
"flowtype/require-exact-type": [
25+
2,
26+
"never"
27+
]
28+
}
29+
}
30+
```
31+
32+
<!-- assertions requireExactType -->
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
### `require-types-at-top`
2+
3+
Requires all type declarations to be at the top of the file, after any import declarations.
4+
5+
#### Options
6+
7+
The rule has a string option:
8+
9+
* `"never"`
10+
* `"always"`
11+
12+
The default value is `"always"`.
13+
14+
<!-- assertions require-types-at-top -->

.README/rules/sort-keys.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
### `sort-keys`
22

3+
_The `--fix` option on the command line automatically fixes problems reported by this rule._
4+
35
Enforces sorting of Object annotations.
46

57
This rule mirrors ESlint's [sort-keys](http://eslint.org/docs/rules/sort-keys) rule.

.README/rules/type-import-style.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
### `type-import-style`
2+
3+
_The `--fix` option on the command line automatically fixes problems reported by this rule._
4+
5+
Enforces a particular style for type imports:
6+
7+
```
8+
// 'identifier' style
9+
import {type T, type U, type V} from '...';
10+
11+
// 'declaration' style
12+
import type {T, U, V} from '...';
13+
```
14+
15+
The rule has a string option:
16+
17+
* `"identifier"` (default): Enforces that type imports are all in the
18+
'identifier' style.
19+
* `"declaration"`: Enforces that type imports are all in the 'declaration'
20+
style.
21+
22+
<!-- assertions typeImportStyle -->

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ Run with `npm run lint`.
3636

3737
1. Create a file in `tests/rules/assertions` named the `camelCase` version of your rule name with the following template:
3838
* `export default { invalid: [], valid: [] }`
39-
2. Add your test file to `tests/index.js`
39+
2. Add your test file to `tests/rules/index.js`
4040
3. Create a file in `src/rules` named the `camelCase` version of your rule name
4141
4. Add your rule file to `src/index.js`
4242

4343
### Adding Documentation
4444

45-
1. Create new file in `./README/rules/[rule-name].md`.
45+
1. Create new file in `./.README/rules/[rule-name].md`.
4646
* Use [./.README/rules/require-valid-file-annotation.md](./.README/rules/require-valid-file-annotation.md) as a template.
4747
* Ensure that rule documentation document includes `<!-- assertions spaceAfterTypeColon -->` declaration.
4848
1. Update [./.README/README.md](/.README/README.md) to include the new rule.

0 commit comments

Comments
 (0)