Skip to content

Commit

Permalink
feat: Implement define-flow-type for declare type (#274)
Browse files Browse the repository at this point in the history
Covers these two forms:

    declare type Foo = 'foo';
    declare interface Foo {};
  • Loading branch information
jez authored and gajus committed Dec 11, 2017
1 parent d772c03 commit 32d56fd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Run with `npm run lint`.

### Adding Documentation

1. Create new file in `./README/rules/[rule-name].md`.
1. Create new file in `./.README/rules/[rule-name].md`.
* Use [./.README/rules/require-valid-file-annotation.md](./.README/rules/require-valid-file-annotation.md) as a template.
* Ensure that rule documentation document includes `<!-- assertions spaceAfterTypeColon -->` declaration.
1. Update [./.README/README.md](/.README/README.md) to include the new rule.
Expand Down
6 changes: 6 additions & 0 deletions src/rules/defineFlowType.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ const create = (context) => {
ClassImplements (node) {
makeDefined(node.id);
},
DeclareInterface (node) {
makeDefined(node.id);
},
DeclareTypeAlias (node) {
makeDefined(node.id);
},
GenericTypeAnnotation (node) {
if (node.id.type === 'Identifier') {
makeDefined(node.id);
Expand Down
12 changes: 12 additions & 0 deletions tests/rules/assertions/defineFlowType.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ const VALID_WITH_DEFINE_FLOW_TYPE = [
'\'AType\' is not defined.'
]
},
{
code: 'declare type A = number',
errors: [
'\'A\' is not defined.'
]
},
{
code: 'function f(a: AType) {}',
errors: [
Expand Down Expand Up @@ -97,6 +103,12 @@ const VALID_WITH_DEFINE_FLOW_TYPE = [
'\'AType\' is not defined.'
]
},
{
code: 'declare interface A {}',
errors: [
'\'A\' is not defined.'
]
},
{
code: '({ a: ({b() {}}: AType) })',
// `AType` appears twice in `globalScope.through` as distinct
Expand Down

0 comments on commit 32d56fd

Please sign in to comment.