diff --git a/src/rules/typeColonSpacing/reporter.js b/src/rules/typeColonSpacing/reporter.js index e1c92870..bfa80bb6 100644 --- a/src/rules/typeColonSpacing/reporter.js +++ b/src/rules/typeColonSpacing/reporter.js @@ -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, diff --git a/tests/rules/assertions/spaceAfterTypeColon.js b/tests/rules/assertions/spaceAfterTypeColon.js index a354cc95..4733a60c 100644 --- a/tests/rules/assertions/spaceAfterTypeColon.js +++ b/tests/rules/assertions/spaceAfterTypeColon.js @@ -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'] } ] }; @@ -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'] } ] }; diff --git a/tests/rules/assertions/spaceBeforeTypeColon.js b/tests/rules/assertions/spaceBeforeTypeColon.js index aa1fe022..80fe4460 100644 --- a/tests/rules/assertions/spaceBeforeTypeColon.js +++ b/tests/rules/assertions/spaceBeforeTypeColon.js @@ -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'] } ] }; @@ -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']