public static ConditionalExpressionParenthesesStyle GetConditionalExpressionParenthesesStyle(this SyntaxNodeAnalysisContext context) { AnalyzerConfigOptions configOptions = context.GetConfigOptions(); if (ConfigOptions.TryGetValue(configOptions, ConfigOptions.ConditionalOperatorConditionParenthesesStyle, out string rawValue)) { if (string.Equals(rawValue, ConfigOptionValues.ConditionalOperatorConditionParenthesesStyle_Include, StringComparison.OrdinalIgnoreCase)) { return(ConditionalExpressionParenthesesStyle.Include); } else if (string.Equals(rawValue, ConfigOptionValues.ConditionalOperatorConditionParenthesesStyle_Omit, StringComparison.OrdinalIgnoreCase)) { return(ConditionalExpressionParenthesesStyle.Omit); } else if (string.Equals(rawValue, ConfigOptionValues.ConditionalOperatorConditionParenthesesStyle_OmitWhenConditionIsSingleToken, StringComparison.OrdinalIgnoreCase)) { return(ConditionalExpressionParenthesesStyle.OmitWhenConditionIsSingleToken); } } if (configOptions.IsEnabled(LegacyConfigOptions.RemoveParenthesesFromConditionOfConditionalExpressionWhenExpressionIsSingleToken)) { return(ConditionalExpressionParenthesesStyle.OmitWhenConditionIsSingleToken); } return(ConditionalExpressionParenthesesStyle.None); }
public static BodyStyle Create(SyntaxNodeAnalysisContext context) { AnalyzerConfigOptions configOptions = context.GetConfigOptions(); var option = BodyStyleOption.None; if (ConfigOptions.TryGetValue(configOptions, ConfigOptions.BodyStyle, out string rawValue)) { if (string.Equals(rawValue, ConfigOptionValues.BodyStyle_Block, StringComparison.OrdinalIgnoreCase)) { option = BodyStyleOption.Block; } else if (string.Equals(rawValue, ConfigOptionValues.BodyStyle_Expression, StringComparison.OrdinalIgnoreCase)) { option = BodyStyleOption.Expression; } } else if (configOptions.TryGetValueAsBool(LegacyConfigOptions.ConvertExpressionBodyToBlockBody, out bool useBlockBody)) { option = (useBlockBody) ? BodyStyleOption.Block : BodyStyleOption.Expression; } bool?useBlockBodyWhenDeclarationIsMultiLine = null; if (ConfigOptions.GetValueAsBool(configOptions, ConfigOptions.UseBlockBodyWhenDeclarationSpansOverMultipleLines) == true || configOptions.IsEnabled(LegacyConfigOptions.ConvertExpressionBodyToBlockBodyWhenDeclarationIsMultiLine)) { useBlockBodyWhenDeclarationIsMultiLine = true; } bool?useBlockBodyWhenExpressionIsMultiline = null; if (ConfigOptions.GetValueAsBool(configOptions, ConfigOptions.UseBlockBodyWhenExpressionSpansOverMultipleLines) == true || configOptions.IsEnabled(LegacyConfigOptions.ConvertExpressionBodyToBlockBodyWhenExpressionIsMultiLine)) { useBlockBodyWhenExpressionIsMultiline = true; } return(new BodyStyle(option, useBlockBodyWhenDeclarationIsMultiLine, useBlockBodyWhenExpressionIsMultiline)); }
public static NewLinePosition GetBinaryOperatorNewLinePosition(this AnalyzerConfigOptions configOptions) { if (TryGetNewLinePosition(configOptions, ConfigOptions.BinaryOperatorNewLine, out NewLinePosition newLinePosition)) { return(newLinePosition); } if (configOptions.IsEnabled(LegacyConfigOptions.AddNewLineAfterBinaryOperatorInsteadOfBeforeIt)) { return(NewLinePosition.After); } return(NewLinePosition.None); }
public static NewLinePosition GetEqualsTokenNewLinePosition(this AnalyzerConfigOptions configOptions) { if (TryGetNewLinePosition(configOptions, ConfigOptions.EqualsTokenNewLine, out NewLinePosition newLinePosition)) { return(newLinePosition); } if (configOptions.IsEnabled(LegacyConfigOptions.AddNewLineAfterEqualsSignInsteadOfBeforeIt)) { return(NewLinePosition.After); } return(NewLinePosition.None); }
public static ConfigureAwaitStyle GetConfigureAwaitStyle(this SyntaxNodeAnalysisContext context) { AnalyzerConfigOptions configOptions = context.GetConfigOptions(); if (ConfigOptions.TryGetValueAsBool(configOptions, ConfigOptions.ConfigureAwait, out bool value)) { return((value) ? ConfigureAwaitStyle.Include : ConfigureAwaitStyle.Omit); } if (configOptions.IsEnabled(LegacyConfigOptions.RemoveCallToConfigureAwait)) { return(ConfigureAwaitStyle.Omit); } return(ConfigureAwaitStyle.None); }
protected static bool TryReportObsoleteOption( SyntaxTreeAnalysisContext context, AnalyzerConfigOptions configOptions, LegacyConfigOptionDescriptor legacyOption, ConfigOptionDescriptor newOption, string newValue) { if (configOptions.IsEnabled(legacyOption)) { DiagnosticHelpers.ReportDiagnostic( context, CommonDiagnosticRules.AnalyzerOptionIsObsolete, Location.None, legacyOption.Key, $", use option '{newOption.Key} = {newValue}' instead"); return(true); } return(false); }
public static EnumFlagOperationStyle GetEnumHasFlagStyle(this SyntaxNodeAnalysisContext context) { AnalyzerConfigOptions configOptions = context.GetConfigOptions(); if (ConfigOptions.TryGetValue(configOptions, ConfigOptions.EnumHasFlagStyle, out string rawValue)) { if (string.Equals(rawValue, ConfigOptionValues.EnumHasFlagStyle_Method, StringComparison.OrdinalIgnoreCase)) { return(EnumFlagOperationStyle.HasFlagMethod); } else if (string.Equals(rawValue, ConfigOptionValues.EnumHasFlagStyle_Operator, StringComparison.OrdinalIgnoreCase)) { return(EnumFlagOperationStyle.BitwiseOperator); } } if (configOptions.IsEnabled(LegacyConfigOptions.ConvertBitwiseOperationToHasFlagCall)) { return(EnumFlagOperationStyle.HasFlagMethod); } return(EnumFlagOperationStyle.None); }
public static bool?PreferAnonymousFunctionOrMethodGroup(this SyntaxNodeAnalysisContext context) { AnalyzerConfigOptions configOptions = context.GetConfigOptions(); if (ConfigOptions.TryGetValue(configOptions, ConfigOptions.UseAnonymousFunctionOrMethodGroup, out string rawValue)) { if (string.Equals(rawValue, ConfigOptionValues.UseAnonymousFunctionOrMethodGroup_AnonymousFunction, StringComparison.OrdinalIgnoreCase)) { return(true); } else if (string.Equals(rawValue, ConfigOptionValues.UseAnonymousFunctionOrMethodGroup_MethodGroup, StringComparison.OrdinalIgnoreCase)) { return(false); } } if (configOptions.IsEnabled(LegacyConfigOptions.ConvertMethodGroupToAnonymousFunction)) { return(true); } return(null); }
public static NullCheckStyle GetNullCheckStyle(this SyntaxNodeAnalysisContext context) { AnalyzerConfigOptions configOptions = context.GetConfigOptions(); if (ConfigOptions.TryGetValue(configOptions, ConfigOptions.NullCheckStyle, out string rawValue)) { if (string.Equals(rawValue, ConfigOptionValues.NullCheckStyle_EqualityOperator, StringComparison.OrdinalIgnoreCase)) { return(NullCheckStyle.EqualityOperator); } if (string.Equals(rawValue, ConfigOptionValues.NullCheckStyle_PatternMatching, StringComparison.OrdinalIgnoreCase)) { return(NullCheckStyle.PatternMatching); } } if (configOptions.IsEnabled(LegacyConfigOptions.UseComparisonInsteadPatternMatchingToCheckForNull)) { return(NullCheckStyle.EqualityOperator); } return(NullCheckStyle.None); }
public static EmptyStringStyle GetEmptyStringStyle(this SyntaxNodeAnalysisContext context) { AnalyzerConfigOptions configOptions = context.GetConfigOptions(); if (ConfigOptions.TryGetValue(configOptions, ConfigOptions.EmptyStringStyle, out string rawValue)) { if (string.Equals(rawValue, ConfigOptionValues.EmptyStringStyle_Field, StringComparison.OrdinalIgnoreCase)) { return(EmptyStringStyle.Field); } if (string.Equals(rawValue, ConfigOptionValues.EmptyStringStyle_Literal, StringComparison.OrdinalIgnoreCase)) { return(EmptyStringStyle.Literal); } } if (configOptions.IsEnabled(LegacyConfigOptions.UseStringEmptyInsteadOfEmptyStringLiteral)) { return(EmptyStringStyle.Field); } return(EmptyStringStyle.None); }