Skip to content

Commit

Permalink
fix: Mark opaque type identifiers as defined with define-flow-type (#283
Browse files Browse the repository at this point in the history
)

* fix: Mark opaque type identifiers as defined with define-flow-type

* docs: Regenerate documentation with npm run documentation

There was diff unrelated to opaque type fix, so I didn't commit them
  • Loading branch information
valscion authored and gajus committed Dec 11, 2017
1 parent 32d56fd commit 3bc8de7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ var a: AType<BType>
type A = AType
// Additional rules: {"no-undef":2}

opaque type A = AType
// Additional rules: {"no-undef":2}

function f(a: AType) {}
// Additional rules: {"no-undef":2}

Expand Down Expand Up @@ -306,6 +309,9 @@ var a: AType<BType>
type A = AType
// Additional rules: {"no-undef":2,"no-use-before-define":[2,"nofunc"]}

opaque type A = AType
// Additional rules: {"no-undef":2,"no-use-before-define":[2,"nofunc"]}

function f(a: AType) {}
// Additional rules: {"no-undef":2,"no-use-before-define":[2,"nofunc"]}

Expand Down
5 changes: 5 additions & 0 deletions src/rules/defineFlowType.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ const create = (context) => {
InterfaceDeclaration (node) {
makeDefined(node.id);
},
OpaqueType (node) {
if (node.id.type === 'Identifier') {
makeDefined(node.id);
}
},
Program () {
globalScope = context.getScope();
},
Expand Down
10 changes: 10 additions & 0 deletions tests/rules/assertions/defineFlowType.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ const VALID_WITH_DEFINE_FLOW_TYPE = [
'\'A\' is not defined.'
]
},
{
code: 'opaque type A = AType',
errors: [
// Complaining about 'A' not being defined might be an upstream bug
'\'A\' is not defined.',
'\'AType\' is not defined.'
]
},
{
code: 'function f(a: AType) {}',
errors: [
Expand Down Expand Up @@ -166,6 +174,8 @@ const ALWAYS_VALID = [
'var a: Array',
'var a: Array<string>',
'type A = Array',
// This complains about 'A' not being defined. It might be an upstream bug
// 'opaque type A = Array',
'function f(a: string) {}',
'function f(a): string {}',
'class C { a: string }',
Expand Down

0 comments on commit 3bc8de7

Please sign in to comment.