Skip to content

Commit

Permalink
Fixing extra indent in conditionals
Browse files Browse the repository at this point in the history
Closes #7
  • Loading branch information
belav committed Oct 11, 2021
1 parent 3f604f5 commit e7835b5
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,15 @@ class ClassName
this.WhenThereExists________________(
a.Website().WithDomainName("test-integration.insite.com")
);

return someCondition
? CallMethod(
someLongParameter____________________________,
someLongParameter____________________________
)
: Something.CallMethod(
someLongParameter____________________________,
someLongParameter____________________________
);
}
}
176 changes: 172 additions & 4 deletions Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InvocationExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,25 +127,193 @@ void Traverse(ExpressionSyntax expression)
return Doc.Group(groups.SelectMany(o => o).ToArray());
}

return Doc.Concat(Doc.Group(groups[0].ToArray()), PrintIndentedGroup(groups.Skip(1)));
return Doc.Concat(
Doc.Group(groups[0].ToArray()),
PrintIndentedGroup(node, groups.Skip(1))
);
}

private static bool IsMemberish(CSharpSyntaxNode node)
{
return node is MemberAccessExpressionSyntax;
}

private static Doc PrintIndentedGroup(IEnumerable<List<Doc>> groups)
{
private static Doc PrintIndentedGroup(
InvocationExpressionSyntax node,
IEnumerable<List<Doc>> groups
) {
if (!groups.Any())
{
return Doc.Null;
}

// TODO GH-7 softline here?
return Doc.Indent(
return Doc.IndentIf(
node.Parent is not ConditionalExpressionSyntax,
Doc.Group(Doc.Join(Doc.SoftLine, groups.Select(o => Doc.Group(o.ToArray()))))
);
}
}
}

/*
class ClassName
{
// this is better, but still looks weird
public AccessTokenNotAvailableException(
NavigationManager navigation,
AccessTokenResult tokenResult,
IEnumerable<string> scopes
) : base(
message: "Unable to provision an access token for the requested scopes: " + scopes != null
? $"'{string.Join(", ", scopes ?? Array.Empty<string>())}'"
: "(default scopes)"
) { }
void MethodName()
{
// this isn't how prettier does it, stretch goal
this.Address1 = addressFields_________________
.FirstOrDefault(field => field.FieldName == "Address1");
this.Address1 = addressFields_________________
.FirstOrDefault(field => field.FieldName == "Address1").ToList();
this.Address1 = addressFields
.Where(field => field.FieldName == "Address1__________________________")
.Where(field => yeah)
.Where(field => yeah);
roleNames
.ToList()
.ForEach(
(role) =>
this.adminContextMock.Setup((ctx) => ctx.IsUserInRole(role)).Returns(false)
);
var superLongMethodNameForceLine = someFactoryName__________
.SuperLongMethodNameForceLine()
.SomeOtherReallyLongMethodName();
// prettier does it this way, but ugly!
string signedRequest = htmlHelper.ViewContext.HttpContext.Request.Params[
"signed_request____________"
];
// prettier does it this way, but ugly!
result[i / ReferenceFrameSize] = RenderTreeFrame.ComponentReferenceCapture(
0,
null__________,
0
);
// not sure if anything here should change
Diagnostic.Create(
_descriptor,
symbolForDiagnostic.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax()
.GetLocation() ?? Location.None,
symbol.ToDisplayString(SymbolDisplayFormat.CSharpShortErrorMessageFormat)
);
// see below
FacebookGroupConnection<TStatus> statuses = await GetFacebookObjectAsync<
FacebookGroupConnection<TStatus>
>(client, "me/statuses");
/* should maybe be
FacebookGroupConnection<TStatus> statuses =
await GetFacebookObjectAsync<FacebookGroupConnection<TStatus>>(
client,
"me/statuses"
);
// this one seems fine?
var proxy1 = generator.CreateInterfaceProxyWithTargetInterface<IEventHandler<EventArgs1>>(
null,
new[] { lazyInterceptor1 }
);
// this is just gross, it used to break parameters instead of generic types
var count = (int)await _invoker.InvokeUnmarshalled<
string[],
object?,
object?,
Task<object>
>(GetSatelliteAssemblies, culturesToLoad.ToArray(), null, null);
// extra indent?
return value == null
? CallMethod(
value.ToString(),
"([a-z])([A-Z])",
"$1-$2",
RegexOptions.None,
TimeSpan.FromMilliseconds(100)
)
.ToLowerInvariant()
: Regex.Replace(
value.ToString(),
"([a-z])([A-Z])",
"$1-$2",
RegexOptions.None,
TimeSpan.FromMilliseconds(100)
)
.ToLowerInvariant();
var ex = Assert.Throws<ArgumentException>(
() =>
generator.CreateInterfaceProxyWithTargetInterface<IList<IList<PrivateInterface>>>(
new List<IList<PrivateInterface>>(),
new IInterceptor[0]
)
);
// these used to not break so weird
ref var parentFrame = ref diffContext.NewTree[
newFrame.ComponentReferenceCaptureParentFrameIndexField
];
var newComponentInstance = (CaptureSetParametersComponent)oldTree.GetFrames().Array[
0
].Component;
parent = (ContainerNode)parent.Children[
childIndexAtCurrentDepth__________ + siblingIndex__________
];
configuration.EncryptionAlgorithmKeySize = (int)encryptionElement.Attribute(
"keyLength__________________"
)!;
// used to break onto the next line
var cbTempSubkeys = checked(
_symmetricAlgorithmSubkeyLengthInBytes + _hmacAlgorithmSubkeyLengthInBytes
);
// but then this looks better with checked next to =
var cbEncryptedData = checked(
cbCiphertext
- (
KEY_MODIFIER_SIZE_IN_BYTES
+ _symmetricAlgorithmBlockSizeInBytes
+ _hmacAlgorithmDigestLengthInBytes
)
);
// used to be 2 lines
var cacheKey__________ = (
ModelType: fieldIdentifier.Model.GetType(),
fieldIdentifier.FieldName
);
// not sure what to do with this, nothing??
storedArguments_______[i] = localVariables[i] = Expression.Parameter(
parameters[i].ParameterType
);
}
}
*/

0 comments on commit e7835b5

Please sign in to comment.