Skip to content

Commit

Permalink
Merge pull request #159 from gajus/optionalNames
Browse files Browse the repository at this point in the history
feat: support optional Flow names (closes #145)
  • Loading branch information
danharper committed Nov 30, 2016
2 parents 25e11f2 + c40ad7c commit 915a284
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/rules/typeColonSpacing/reporter.js
Expand Up @@ -14,6 +14,13 @@ export default (direction, context, {always, allowLineBreak}) => {
return ({colon, node, name = '', type = 'type annotation'}) => {
let spaces;

// Support optional names
// type X = { [string]: a }
// type X = string => string
if (colon.value !== ':') {
return;
}

const data = {
direction,
name,
Expand Down
43 changes: 43 additions & 0 deletions tests/rules/assertions/spaceAfterTypeColon.js
Expand Up @@ -453,6 +453,41 @@ const FUNCTION_TYPE_PARAMS = {
{
code: 'type TArrayPredicate = (el:T, i?:number) => boolean',
options: ['never']
},
{
code: 'type X = (number) => string;'
},
{
code: 'type X = (?number) => string;'
},
{
code: 'type X = number => string;'
},
{
code: 'type X = ?number => string;'
},
{
code: 'type X = ({ foo: bar }) => string;'
},
{
code: 'type X = (number) => string;',
options: ['always']
},
{
code: 'type X = (?number) => string;',
options: ['always']
},
{
code: 'type X = number => string;',
options: ['always']
},
{
code: 'type X = ?number => string;',
options: ['always']
},
{
code: 'type X = ({ foo: bar }) => string;',
options: ['always']
}
]
};
Expand Down Expand Up @@ -948,6 +983,14 @@ const OBJECT_TYPE_INDEXERS = {
{
code: 'type X = { +[a:b]:c }',
options: ['never']
},
{
code: 'type X = { [string]: c }',
options: ['always']
},
{
code: 'type X = { [string]:c }',
options: ['never']
}
]
};
Expand Down
43 changes: 43 additions & 0 deletions tests/rules/assertions/spaceBeforeTypeColon.js
Expand Up @@ -338,6 +338,41 @@ const FUNCTION_TYPE_PARAMS = {
{
code: 'type X = (foo? : ?string) => number',
options: ['always']
},
{
code: 'type X = (number) => string;'
},
{
code: 'type X = (?number) => string;'
},
{
code: 'type X = number => string;'
},
{
code: 'type X = ?number => string;'
},
{
code: 'type X = ({ foo: bar }) => string;'
},
{
code: 'type X = (number) => string;',
options: ['always']
},
{
code: 'type X = (?number) => string;',
options: ['always']
},
{
code: 'type X = number => string;',
options: ['always']
},
{
code: 'type X = ?number => string;',
options: ['always']
},
{
code: 'type X = ({ foo : bar }) => string;',
options: ['always']
}
]
};
Expand Down Expand Up @@ -749,6 +784,14 @@ const OBJECT_TYPE_INDEXERS = {
code: 'type X = { [a:b]:c }',
options: ['never']
},
{
code: 'type X = { [string] : c }',
options: ['always']
},
{
code: 'type X = { [string]:c }',
options: ['never']
},
{
code: 'type X = { +[a : b] : c }',
options: ['always']
Expand Down

0 comments on commit 915a284

Please sign in to comment.