Inline Generics with a single identifier (#5066)

master
Lucas Duailibe 2018-09-06 14:44:21 -03:00 committed by GitHub
parent 1965b74e61
commit 87376f93f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 21 deletions

View File

@ -3429,6 +3429,28 @@ function shouldGroupFirstArg(args) {
);
}
function isSimpleFlowType(node) {
const flowTypeAnnotations = [
"AnyTypeAnnotation",
"NullLiteralTypeAnnotation",
"GenericTypeAnnotation",
"ThisTypeAnnotation",
"NumberTypeAnnotation",
"VoidTypeAnnotation",
"EmptyTypeAnnotation",
"MixedTypeAnnotation",
"BooleanTypeAnnotation",
"BooleanLiteralTypeAnnotation",
"StringTypeAnnotation"
];
return (
node &&
flowTypeAnnotations.indexOf(node.type) !== -1 &&
!(node.type === "GenericTypeAnnotation" && node.typeParameters)
);
}
const functionCompositionFunctionNames = new Set([
"pipe", // RxJS, Ramda
"pipeP", // Ramda
@ -3718,20 +3740,6 @@ function printFunctionParams(path, print, options, expandArg, printTypeParams) {
return concat([typeParams, "(", join(", ", printed), ")"]);
}
const flowTypeAnnotations = [
"AnyTypeAnnotation",
"NullLiteralTypeAnnotation",
"GenericTypeAnnotation",
"ThisTypeAnnotation",
"NumberTypeAnnotation",
"VoidTypeAnnotation",
"EmptyTypeAnnotation",
"MixedTypeAnnotation",
"BooleanTypeAnnotation",
"BooleanLiteralTypeAnnotation",
"StringTypeAnnotation"
];
const isFlowShorthandWithOneArg =
(isObjectTypePropertyAFunction(parent, options) ||
isTypeAnnotationAFunction(parent, options) ||
@ -3745,12 +3753,7 @@ function printFunctionParams(path, print, options, expandArg, printTypeParams) {
fun[paramsField][0].name === null &&
fun[paramsField][0].typeAnnotation &&
fun.typeParameters === null &&
flowTypeAnnotations.indexOf(fun[paramsField][0].typeAnnotation.type) !==
-1 &&
!(
fun[paramsField][0].typeAnnotation.type === "GenericTypeAnnotation" &&
fun[paramsField][0].typeAnnotation.typeParameters
) &&
isSimpleFlowType(fun[paramsField][0].typeAnnotation) &&
!fun.rest;
if (isFlowShorthandWithOneArg) {
@ -5648,7 +5651,7 @@ function isNodeStartingWithDeclare(node, options) {
}
function shouldHugType(node) {
if (isObjectType(node)) {
if (isSimpleFlowType(node) || isObjectType(node)) {
return true;
}

View File

@ -136,6 +136,20 @@ function foo(): Promise<?boolean> {}
`;
exports[`single-identifier.js - flow-verify 1`] = `
const longVariableName: Array<number> = this.foo.bar.baz.collider.body.vertices.reduce();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const longVariableName: Array<number> = this.foo.bar.baz.collider.body.vertices.reduce();
`;
exports[`single-identifier.js - flow-verify 2`] = `
const longVariableName: Array<number> = this.foo.bar.baz.collider.body.vertices.reduce();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const longVariableName: Array<number> = this.foo.bar.baz.collider.body.vertices.reduce();
`;
exports[`trailing.js - flow-verify 1`] = `
type State = {
errors: Immutable.Map<

View File

@ -0,0 +1 @@
const longVariableName: Array<number> = this.foo.bar.baz.collider.body.vertices.reduce();