Inline Generics with a single identifier (#5066)
parent
1965b74e61
commit
87376f93f3
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
const longVariableName: Array<number> = this.foo.bar.baz.collider.body.vertices.reduce();
|
Loading…
Reference in New Issue