in src/dotnet/ReSharperPlugin.QuirkyFormatting/Psi/CodeStyle/Formatting/QuirkyCSharpFormatterInfoProvider.cs [49:125]
private void QuirkyLineBreaks()
{
// This rule turns off the enforcement of linebreaks between statements.
// Its priority must be lower than any rule's that also modifies statements' line breaks behavior
DescribeWithExternalKey<QuirkyFormattingSettingsKey, FormattingRule>()
.Group(LineBreaksRuleGroup)
.Name("ENFORCE_LINE_BREAKS_BETWEEN_STATEMENTS")
.Where(
Left().In(ElementBitsets.C_SHARP_STATEMENT_BIT_SET),
Right().In(ElementBitsets.C_SHARP_STATEMENT_BIT_SET)
)
.SwitchOnExternalKey(
x => x.ENFORCE_LINE_BREAKS_BETWEEN_STATEMENTS,
When(false).Return(IntervalFormatType.OnlySpace)
)
.Priority(WeakQuirkyPriority)
.Build();
// Don't do linebreaks after braces to get the lisp-style effect
DescribeWithExternalKey<QuirkyFormattingSettingsKey, FormattingRule>()
.Group(LineBreaksRuleGroup)
.Name("NO_LINEBREAKS_AFTER_LBRACE")
.Where(
Left().HasType(CSharpTokenType.LBRACE),
Right().In(ElementBitsets.C_SHARP_STATEMENT_BIT_SET)
)
.SwitchOnExternalKey(
x => x.ENFORCE_LINE_BREAKS_AFTER_LEFT_BRACES,
When(false).Return(IntervalFormatType.OnlySpace)
)
.Priority(QuirkyPriority)
.Build();
// Indent last brace to get the banner-style effect
DescribeWithExternalKey<QuirkyFormattingSettingsKey, IndentingRule>()
.Group(LineBreaksRuleGroup)
.Name("INDENT_RBRACE")
.Where(
Left().HasType(CSharpTokenType.RBRACE),
Right().HasType(CSharpTokenType.RBRACE)
)
.SwitchOnExternalKey(
x => x.BANNER_STYLE_RIGHT_BRACE,
When(true).Switch(
x => x.CONTINUOUS_INDENT_MULTIPLIER,
ContinuousIndentRule.ContinuousIndentOptions(this, IndentType.External)
)
)
.Priority(QuirkyPriority)
.Build();
// The following rule demonstrates the use of custom predicates to detect the proper formatting context.
DescribeWithExternalKey<QuirkyFormattingSettingsKey, FormattingRule>()
.Group(LineBreaksRuleGroup)
.Name("LOCAL_FUNCTION_DECLARATION_AND_INVOCATION_LINEBREAKS")
.Where(
Left().Satisfies(
(node, _) =>
node is IExpressionStatement expressionStatement &&
expressionStatement.HasLocalFunctionInvocation()
),
Right().Satisfies(
(node, _) =>
node is IDeclarationStatement { LocalFunctionDeclaration: { } localFunctionDeclaration }
&& node.LeftSiblings().OfType<IExpressionStatement>().FirstOrDefault() is
{ } expressionStatement
&& expressionStatement.GetInvokedLocalFunctionDeclarations().Contains(localFunctionDeclaration)
)
)
.SwitchOnExternalKey(
x => x.ENFORCE_LOCAL_FUNCTION_DECLARATION_AND_INVOCATION_LINEBREAKS,
When(true).Return(IntervalFormatType.NewLine),
When(false).Return(IntervalFormatType.OnlySpace)
)
.Priority(QuirkyPriority)
.Build();
}