diff --git a/src/rules/spaceAfterTypeColon.js b/src/rules/spaceAfterTypeColon.js index d1d5b5d3..069a0aa9 100644 --- a/src/rules/spaceAfterTypeColon.js +++ b/src/rules/spaceAfterTypeColon.js @@ -24,5 +24,17 @@ export default iterateFunctionNodes((context) => { } } }); + + if (functionNode.returnType) { + const spaceAfter = functionNode.returnType.typeAnnotation.start - functionNode.returnType.start - 1; + + if (always && spaceAfter > 1) { + context.report(functionNode, 'There must be 1 space after return type colon.'); + } else if (always && spaceAfter === 0) { + context.report(functionNode, 'There must be a space after return type colon.'); + } else if (!always && spaceAfter > 0) { + context.report(functionNode, 'There must be no space after return type colon.'); + } + } }; }); diff --git a/tests/rules/assertions/spaceAfterTypeColon.js b/tests/rules/assertions/spaceAfterTypeColon.js index 79b727a4..100f015d 100644 --- a/tests/rules/assertions/spaceAfterTypeColon.js +++ b/tests/rules/assertions/spaceAfterTypeColon.js @@ -54,6 +54,37 @@ export default { options: [ 'always' ] + }, + { + code: '():Object => {}', + errors: [ + { + message: 'There must be a space after return type colon.' + } + ], + options: [ + 'always' + ] + }, { + code: '(): Object => {}', + errors: [ + { + message: 'There must be no space after return type colon.' + } + ], + options: [ + 'never' + ] + }, { + code: '(): Object => {}', + errors: [ + { + message: 'There must be 1 space after return type colon.' + } + ], + options: [ + 'always' + ] } ], valid: [ @@ -74,6 +105,17 @@ export default { options: [ 'always' ] + }, + { + code: '():Object => {}', + options: [ + 'never' + ] + }, { + code: '(): Object => {}', + options: [ + 'always' + ] } ] };