-
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix-interface-delimiters
- Loading branch information
Showing
107 changed files
with
4,237 additions
and
9,748 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
### `arrow-parens` | ||
|
||
_The `--fix` option on the command line automatically fixes problems reported by this rule._ | ||
|
||
Enforces the consistent use of parentheses in arrow functions. | ||
|
||
This rule has a string option and an object one. | ||
|
||
String options are: | ||
|
||
- `"always"` (default) requires parens around arguments in all cases. | ||
- `"as-needed"` enforces no braces where they can be omitted. | ||
|
||
Object properties for variants of the `"as-needed"` option: | ||
|
||
- `"requireForBlockBody": true` modifies the as-needed rule in order to require parens if the function body is in an instructions block (surrounded by braces). | ||
|
||
<!-- assertions arrowParens --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
### `require-readonly-react-props` | ||
|
||
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. | ||
|
||
For example, this will NOT be checked: | ||
|
||
```js | ||
import MyReact from 'react'; | ||
class Foo extends MyReact.Component { } | ||
``` | ||
|
||
As a result, you can safely use other classes without getting warnings from this rule: | ||
|
||
```js | ||
class MyClass extends MySuperClass { } | ||
``` | ||
|
||
React's functional components are hard to detect statically. The way it's done here is by searching for JSX within a function. When present, a function is considered a React component: | ||
|
||
```js | ||
// this gets checked | ||
type Props = { }; | ||
function MyComponent(props: Props) { | ||
return <p />; | ||
} | ||
|
||
// this doesn't get checked since no JSX is present in a function | ||
type Options = { }; | ||
function SomeHelper(options: Options) { | ||
// ... | ||
} | ||
|
||
// this doesn't get checked since no JSX is present directly in a function | ||
function helper() { return <p /> } | ||
function MyComponent(props: Props) { | ||
return helper(); | ||
} | ||
``` | ||
|
||
The rule only works for locally defined props that are marked with a `$ReadOnly` or using covariant notation. It doesn't work with imported props: | ||
|
||
```js | ||
// the rule has no way of knowing whether ImportedProps are read-only | ||
import { type ImportedProps } from './somewhere'; | ||
class Foo extends React.Component<ImportedProps> { } | ||
|
||
|
||
// the rule also checks for covariant properties | ||
type Props = {| | ||
+foo: string | ||
|}; | ||
class Bar extends React.Component<Props> { } | ||
|
||
// this fails because the object is not fully read-only | ||
type Props = {| | ||
+foo: string, | ||
bar: number, | ||
|}; | ||
class Bar extends React.Component<Props> { } | ||
|
||
// this fails because spreading makes object mutable (as of Flow 0.98) | ||
// https://github.com/gajus/eslint-plugin-flowtype/pull/400#issuecomment-489813899 | ||
type Props = {| | ||
+foo: string, | ||
...bar, | ||
|}; | ||
class Bar extends React.Component<Props> { } | ||
``` | ||
|
||
|
||
```js | ||
{ | ||
"rules": { | ||
"flowtype/require-readonly-react-props": 2 | ||
} | ||
} | ||
``` | ||
|
||
|
||
<!-- assertions requireReadonlyReactProps --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"extends": "canonical" | ||
"extends": "canonical", | ||
"rules": { | ||
"unicorn/prevent-abbreviations": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github: gajus | ||
patreon: gajus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ dist | |
!.README | ||
!.travis.yml | ||
/package-lock.json | ||
/yack.lock |
Oops, something went wrong.