Skip to content

Commit

Permalink
feat: add require-inexact-type rule (#408)
Browse files Browse the repository at this point in the history
* feat: add require-inexact-type rule

* docs: generate docs
  • Loading branch information
goodmind authored and gajus committed Jun 10, 2019
1 parent 712d840 commit ab62a49
Show file tree
Hide file tree
Showing 8 changed files with 503 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .README/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ When `true`, only checks files with a [`@flow` annotation](http://flowtype.org/d
{"gitdown": "include", "file": "./rules/object-type-delimiter.md"}
{"gitdown": "include", "file": "./rules/require-compound-type-alias.md"}
{"gitdown": "include", "file": "./rules/require-exact-type.md"}
{"gitdown": "include", "file": "./rules/require-inexact-type.md"}
{"gitdown": "include", "file": "./rules/require-parameter-type.md"}
{"gitdown": "include", "file": "./rules/require-readonly-react-props.md"}
{"gitdown": "include", "file": "./rules/require-return-type.md"}
{"gitdown": "include", "file": "./rules/require-types-at-top.md"}
{"gitdown": "include", "file": "./rules/require-valid-file-annotation.md"}
Expand Down
32 changes: 32 additions & 0 deletions .README/rules/require-inexact-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
### `require-inexact-type`

This rule enforces explicit inexact object types.

#### Options

The rule has one string option:

- `"always"` (default): Report all object type definitions that aren't explicit inexact, but ignore exact objects.
- `"never"`: Report all object type definitions that are explicit inexact.

```js
{
"rules": {
"flowtype/require-inexact-type": [
2,
"always"
]
}
}

{
"rules": {
"flowtype/require-inexact-type": [
2,
"never"
]
}
}
```

<!-- assertions requireInexactType -->
4 changes: 2 additions & 2 deletions .README/rules/require-readonly-react-props.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This rule validates that React props are marked as $ReadOnly. React props are immutable and modifying them could lead to unexpected results. Marking prop shapes as $ReadOnly avoids these issues.

The rule tries its best to work with both class and functional components. For class components, it does a fuzzy check for one of "Component", "PureComponent", "React.Component" and "React.PureComponent". It doesn't actually infer that those identifiers resolve to a proper `React.Component` object.
The rule tries its best to work with both class and functional components. For class components, it does a fuzzy check for one of "Component", "PureComponent", "React.Component" and "React.PureComponent". It doesn't actually infer that those identifiers resolve to a proper `React.Component` object.

For example, this will NOT be checked:

Expand Down Expand Up @@ -79,4 +79,4 @@ class Bar extends React.Component<Props> { }
```


<!-- assertions requireReadOnlyReactProps -->
<!-- assertions requireReadonlyReactProps -->
Loading

0 comments on commit ab62a49

Please sign in to comment.