From a94334203c671cd1146df752bfe465ad1488b72f Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Mon, 31 Aug 2015 23:11:17 -0500 Subject: [PATCH] Cache the properties reported with diagnostics for OpenCloseSpacingCodeFixProvider --- ...eningParenthesisMustBeOnDeclarationLine.cs | 9 +--- ...gParenthesisMustBeOnLineOfLastParameter.cs | 9 +--- ...nthesisMustBeOnLineOfOpeningParenthesis.cs | 9 +--- ...ommaMustBeOnSameLineAsPreviousParameter.cs | 9 +--- .../OpenCloseSpacingCodeFixProvider.cs | 45 +++++++++++++++---- ...ClosingParenthesisMustBeSpacedCorrectly.cs | 24 +++------- ...singSquareBracketsMustBeSpacedCorrectly.cs | 24 +++------- ...eningCurlyBracketsMustBeSpacedCorrectly.cs | 24 +++------- ...osingCurlyBracketsMustBeSpacedCorrectly.cs | 24 +++------- ...ingGenericBracketsMustBeSpacedCorrectly.cs | 16 ++----- ...ingGenericBracketsMustBeSpacedCorrectly.cs | 24 +++------- ...emberAccessSymbolsMustBeSpacedCorrectly.cs | 16 ++----- ...ntDecrementSymbolsMustBeSpacedCorrectly.cs | 16 ++----- ...AndAccessOfSymbolsMustBeSpacedCorrectly.cs | 40 +++++------------ 14 files changed, 96 insertions(+), 193 deletions(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1110OpeningParenthesisMustBeOnDeclarationLine.cs b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1110OpeningParenthesisMustBeOnDeclarationLine.cs index cf658eb2c..5acec0110 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1110OpeningParenthesisMustBeOnDeclarationLine.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1110OpeningParenthesisMustBeOnDeclarationLine.cs @@ -321,13 +321,8 @@ private static void CheckIfLocationOfPreviousTokenAndOpenTokenAreTheSame(SyntaxN openParenLine.IsValid && openParenLine.StartLinePosition.Line != prevTokenLine.StartLinePosition.Line) { - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationPreceding, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove, - [OpenCloseSpacingCodeFixProvider.LayoutKey] = preserveLayout ? OpenCloseSpacingCodeFixProvider.LayoutPreserve : OpenCloseSpacingCodeFixProvider.LayoutPack - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, openToken.GetLocation(), properties.ToImmutableDictionary())); + var properties = preserveLayout ? OpenCloseSpacingCodeFixProvider.RemovePrecedingPreserveLayout : OpenCloseSpacingCodeFixProvider.RemovePreceding; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, openToken.GetLocation(), properties)); } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1111ClosingParenthesisMustBeOnLineOfLastParameter.cs b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1111ClosingParenthesisMustBeOnLineOfLastParameter.cs index 70c95b975..2f9b1bfb4 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1111ClosingParenthesisMustBeOnLineOfLastParameter.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1111ClosingParenthesisMustBeOnLineOfLastParameter.cs @@ -347,13 +347,8 @@ private static void CheckIfLocationOfLastArgumentOrParameterAndCloseTokenAreTheS closeParenLine.IsValid && closeParenLine.StartLinePosition.Line != lastParameterLine.EndLinePosition.Line) { - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationPreceding, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove, - [OpenCloseSpacingCodeFixProvider.LayoutKey] = OpenCloseSpacingCodeFixProvider.LayoutPack - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, closeToken.GetLocation(), properties.ToImmutableDictionary())); + var properties = OpenCloseSpacingCodeFixProvider.RemovePreceding; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, closeToken.GetLocation(), properties)); } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1112ClosingParenthesisMustBeOnLineOfOpeningParenthesis.cs b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1112ClosingParenthesisMustBeOnLineOfOpeningParenthesis.cs index ebac319ad..9e99da714 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1112ClosingParenthesisMustBeOnLineOfOpeningParenthesis.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1112ClosingParenthesisMustBeOnLineOfOpeningParenthesis.cs @@ -143,13 +143,8 @@ private static void CheckIfLocationOfOpenAndCloseTokensAreTheSame( openParenLine.IsValid && openParenLine.StartLinePosition.Line != closeParenLine.StartLinePosition.Line) { - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationPreceding, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove, - [OpenCloseSpacingCodeFixProvider.LayoutKey] = OpenCloseSpacingCodeFixProvider.LayoutPack - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, closeToken.GetLocation(), properties.ToImmutableDictionary())); + var properties = OpenCloseSpacingCodeFixProvider.RemovePreceding; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, closeToken.GetLocation(), properties)); } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1113CommaMustBeOnSameLineAsPreviousParameter.cs b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1113CommaMustBeOnSameLineAsPreviousParameter.cs index 3b0000a39..7e06e1201 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1113CommaMustBeOnSameLineAsPreviousParameter.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1113CommaMustBeOnSameLineAsPreviousParameter.cs @@ -247,13 +247,8 @@ private static void CheckIfCommasAreAtTheSameLineAsThePreviousParameter(SyntaxNo if (previousNode.GetEndLine() < nodeOrToken.GetLineSpan().StartLinePosition.Line) { - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationPreceding, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove, - [OpenCloseSpacingCodeFixProvider.LayoutKey] = OpenCloseSpacingCodeFixProvider.LayoutPreserve - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, nodeOrToken.GetLocation(), properties.ToImmutableDictionary())); + var properties = OpenCloseSpacingCodeFixProvider.RemovePrecedingPreserveLayout; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, nodeOrToken.GetLocation(), properties)); } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/OpenCloseSpacingCodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/OpenCloseSpacingCodeFixProvider.cs index 4fc8b3e6d..cd0351177 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/OpenCloseSpacingCodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/OpenCloseSpacingCodeFixProvider.cs @@ -20,15 +20,15 @@ [Shared] public class OpenCloseSpacingCodeFixProvider : CodeFixProvider { - internal const string LocationKey = "location"; - internal const string ActionKey = "action"; - internal const string LayoutKey = "layout"; - internal const string LocationPreceding = "preceding"; - internal const string LocationFollowing = "following"; - internal const string ActionInsert = "insert"; - internal const string ActionRemove = "remove"; - internal const string LayoutPack = "pack"; - internal const string LayoutPreserve = "preserve"; + private const string LocationKey = "location"; + private const string ActionKey = "action"; + private const string LayoutKey = "layout"; + private const string LocationPreceding = "preceding"; + private const string LocationFollowing = "following"; + private const string ActionInsert = "insert"; + private const string ActionRemove = "remove"; + private const string LayoutPack = "pack"; + private const string LayoutPreserve = "preserve"; private static readonly ImmutableArray FixableDiagnostics = ImmutableArray.Create( @@ -49,6 +49,33 @@ public class OpenCloseSpacingCodeFixProvider : CodeFixProvider /// public override ImmutableArray FixableDiagnosticIds => FixableDiagnostics; + internal static ImmutableDictionary InsertPreceding { get; } = + ImmutableDictionary.Empty + .SetItem(LocationKey, LocationPreceding) + .SetItem(ActionKey, ActionInsert); + + internal static ImmutableDictionary RemovePreceding { get; } = + ImmutableDictionary.Empty + .SetItem(LocationKey, LocationPreceding) + .SetItem(ActionKey, ActionRemove) + .SetItem(LayoutKey, LayoutPack); + + internal static ImmutableDictionary RemovePrecedingPreserveLayout { get; } = + ImmutableDictionary.Empty + .SetItem(LocationKey, LocationPreceding) + .SetItem(ActionKey, ActionRemove) + .SetItem(LayoutKey, LayoutPreserve); + + internal static ImmutableDictionary InsertFollowing { get; } = + ImmutableDictionary.Empty + .SetItem(LocationKey, LocationFollowing) + .SetItem(ActionKey, ActionInsert); + + internal static ImmutableDictionary RemoveFollowing { get; } = + ImmutableDictionary.Empty + .SetItem(LocationKey, LocationFollowing) + .SetItem(ActionKey, ActionRemove); + /// public override FixAllProvider GetFixAllProvider() { diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1009ClosingParenthesisMustBeSpacedCorrectly.cs b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1009ClosingParenthesisMustBeSpacedCorrectly.cs index 8be83c7a3..099267fb0 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1009ClosingParenthesisMustBeSpacedCorrectly.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1009ClosingParenthesisMustBeSpacedCorrectly.cs @@ -185,12 +185,8 @@ private static void HandleCloseParenToken(SyntaxTreeAnalysisContext context, Syn if (precededBySpace) { // Closing parenthesis must{ not} be {preceded} by a space. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationPreceding, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), " not", "preceded")); + var properties = OpenCloseSpacingCodeFixProvider.RemovePreceding; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, " not", "preceded")); } if (!suppressFollowingSpaceError) @@ -198,22 +194,14 @@ private static void HandleCloseParenToken(SyntaxTreeAnalysisContext context, Syn if (!precedesStickyCharacter && !followedBySpace && !lastInLine) { // Closing parenthesis must{} be {followed} by a space. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationFollowing, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionInsert - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), string.Empty, "followed")); + var properties = OpenCloseSpacingCodeFixProvider.InsertFollowing; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, string.Empty, "followed")); } else if (precedesStickyCharacter && followedBySpace && (!lastInLine || !allowEndOfLine)) { // Closing parenthesis must{ not} be {followed} by a space. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationFollowing, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), " not", "followed")); + var properties = OpenCloseSpacingCodeFixProvider.RemoveFollowing; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, " not", "followed")); } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1011ClosingSquareBracketsMustBeSpacedCorrectly.cs b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1011ClosingSquareBracketsMustBeSpacedCorrectly.cs index 71e398c5c..3e48626cf 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1011ClosingSquareBracketsMustBeSpacedCorrectly.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1011ClosingSquareBracketsMustBeSpacedCorrectly.cs @@ -140,12 +140,8 @@ private static void HandleCloseBracketToken(SyntaxTreeAnalysisContext context, S if (!firstInLine && precededBySpace) { // Closing square bracket must{ not} be {preceded} by a space. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationPreceding, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), " not", "preceded")); + var properties = OpenCloseSpacingCodeFixProvider.RemovePreceding; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, " not", "preceded")); } if (!lastInLine) @@ -153,22 +149,14 @@ private static void HandleCloseBracketToken(SyntaxTreeAnalysisContext context, S if (!precedesSpecialCharacter && !followedBySpace) { // Closing square bracket must{} be {followed} by a space. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationFollowing, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionInsert - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), string.Empty, "followed")); + var properties = OpenCloseSpacingCodeFixProvider.InsertFollowing; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, string.Empty, "followed")); } else if (precedesSpecialCharacter && followedBySpace && !suppressFollowingSpaceError) { // Closing square brackets must {not} be {followed} by a space - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationFollowing, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), " not", "followed")); + var properties = OpenCloseSpacingCodeFixProvider.RemoveFollowing; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, " not", "followed")); } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1012OpeningCurlyBracketsMustBeSpacedCorrectly.cs b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1012OpeningCurlyBracketsMustBeSpacedCorrectly.cs index e19b0be93..2b6afe2d9 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1012OpeningCurlyBracketsMustBeSpacedCorrectly.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1012OpeningCurlyBracketsMustBeSpacedCorrectly.cs @@ -86,12 +86,8 @@ private static void HandleOpenBraceToken(SyntaxTreeAnalysisContext context, Synt if (followedBySpace) { // Opening curly bracket must{} be {followed} by a space. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationFollowing, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), " not", "followed")); + var properties = OpenCloseSpacingCodeFixProvider.RemoveFollowing; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, " not", "followed")); } return; @@ -102,23 +98,15 @@ private static void HandleOpenBraceToken(SyntaxTreeAnalysisContext context, Synt if (!precededBySpace) { // Opening curly bracket must{} be {preceded} by a space. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationPreceding, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionInsert - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), string.Empty, "preceded")); + var properties = OpenCloseSpacingCodeFixProvider.InsertPreceding; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, string.Empty, "preceded")); } if (!token.IsLastInLine() && !followedBySpace) { // Opening curly bracket must{} be {followed} by a space. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationFollowing, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionInsert - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), string.Empty, "followed")); + var properties = OpenCloseSpacingCodeFixProvider.InsertFollowing; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, string.Empty, "followed")); } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1013ClosingCurlyBracketsMustBeSpacedCorrectly.cs b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1013ClosingCurlyBracketsMustBeSpacedCorrectly.cs index 5ecf4afc9..ab4a69039 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1013ClosingCurlyBracketsMustBeSpacedCorrectly.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1013ClosingCurlyBracketsMustBeSpacedCorrectly.cs @@ -86,12 +86,8 @@ private static void HandleCloseBraceToken(SyntaxTreeAnalysisContext context, Syn if (precededBySpace) { // Closing curly bracket must{ not} be {preceded} by a space. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationPreceding, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), " not", "preceded")); + var properties = OpenCloseSpacingCodeFixProvider.RemovePreceding; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, " not", "preceded")); } return; @@ -120,23 +116,15 @@ private static void HandleCloseBraceToken(SyntaxTreeAnalysisContext context, Syn if (!precededBySpace) { // Closing curly bracket must{} be {preceded} by a space. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationPreceding, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionInsert - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), string.Empty, "preceded")); + var properties = OpenCloseSpacingCodeFixProvider.InsertPreceding; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, string.Empty, "preceded")); } if (!lastInLine && !precedesSpecialCharacter && !followedBySpace) { // Closing curly bracket must{} be {followed} by a space. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationFollowing, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionInsert - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), string.Empty, "followed")); + var properties = OpenCloseSpacingCodeFixProvider.InsertFollowing; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, string.Empty, "followed")); } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1014OpeningGenericBracketsMustBeSpacedCorrectly.cs b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1014OpeningGenericBracketsMustBeSpacedCorrectly.cs index e9237fe08..f10ae6ee9 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1014OpeningGenericBracketsMustBeSpacedCorrectly.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1014OpeningGenericBracketsMustBeSpacedCorrectly.cs @@ -92,23 +92,15 @@ private static void HandleLessThanToken(SyntaxTreeAnalysisContext context, Synta if (!firstInLine && precededBySpace) { // Opening generic brackets must not be {preceded} by a space. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationPreceding, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), "preceded")); + var properties = OpenCloseSpacingCodeFixProvider.RemovePreceding; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, "preceded")); } if (followedBySpace) { // Opening generic brackets must not be {followed} by a space. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationFollowing, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), "followed")); + var properties = OpenCloseSpacingCodeFixProvider.RemoveFollowing; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, "followed")); } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1015ClosingGenericBracketsMustBeSpacedCorrectly.cs b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1015ClosingGenericBracketsMustBeSpacedCorrectly.cs index 5ff870fd6..8bd92887c 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1015ClosingGenericBracketsMustBeSpacedCorrectly.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1015ClosingGenericBracketsMustBeSpacedCorrectly.cs @@ -138,12 +138,8 @@ private static void HandleGreaterThanToken(SyntaxTreeAnalysisContext context, Sy if (!firstInLine && precededBySpace) { // Closing generic bracket must{ not} be {preceded} by a space. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationPreceding, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), " not", "preceded")); + var properties = OpenCloseSpacingCodeFixProvider.RemovePreceding; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, " not", "preceded")); } if (!lastInLine) @@ -151,22 +147,14 @@ private static void HandleGreaterThanToken(SyntaxTreeAnalysisContext context, Sy if (!allowTrailingNoSpace && !followedBySpace) { // Closing generic bracket must{} be {followed} by a space. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationFollowing, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionInsert - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), string.Empty, "followed")); + var properties = OpenCloseSpacingCodeFixProvider.InsertFollowing; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, string.Empty, "followed")); } else if (!allowTrailingSpace && followedBySpace) { // Closing generic bracket must{ not} be {followed} by a space. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationFollowing, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), " not", "followed")); + var properties = OpenCloseSpacingCodeFixProvider.RemoveFollowing; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, " not", "followed")); } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1019MemberAccessSymbolsMustBeSpacedCorrectly.cs b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1019MemberAccessSymbolsMustBeSpacedCorrectly.cs index 85ae93615..4264ec786 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1019MemberAccessSymbolsMustBeSpacedCorrectly.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1019MemberAccessSymbolsMustBeSpacedCorrectly.cs @@ -109,23 +109,15 @@ private static void HandleMemberAccessSymbol(SyntaxTreeAnalysisContext context, if (!firstInLine && precededBySpace) { // Member access symbol '{.}' must not be {preceded} by a space. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationPreceding, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove, - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), token.Text, "preceded")); + var properties = OpenCloseSpacingCodeFixProvider.RemovePreceding; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, token.Text, "preceded")); } if (followedBySpace) { // Member access symbol '{.}' must not be {followed} by a space. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationFollowing, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove, - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), token.Text, "followed")); + var properties = OpenCloseSpacingCodeFixProvider.RemoveFollowing; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, token.Text, "followed")); } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1020IncrementDecrementSymbolsMustBeSpacedCorrectly.cs b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1020IncrementDecrementSymbolsMustBeSpacedCorrectly.cs index 10cb55116..974123b34 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1020IncrementDecrementSymbolsMustBeSpacedCorrectly.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1020IncrementDecrementSymbolsMustBeSpacedCorrectly.cs @@ -97,12 +97,8 @@ private static void HandleIncrementDecrementToken(SyntaxTreeAnalysisContext cont } // {Increment|Decrement} symbol '{++|--}' must not be {followed} by a space. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationFollowing, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove, - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), symbolName, token.Text, "followed")); + var properties = OpenCloseSpacingCodeFixProvider.RemoveFollowing; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, symbolName, token.Text, "followed")); } break; @@ -123,12 +119,8 @@ private static void HandleIncrementDecrementToken(SyntaxTreeAnalysisContext cont } // {Increment|Decrement} symbol '{++|--}' must not be {preceded} by a space. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationPreceding, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove, - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), symbolName, token.Text, "preceded")); + var properties = OpenCloseSpacingCodeFixProvider.RemovePreceding; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, symbolName, token.Text, "preceded")); } break; diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1023DereferenceAndAccessOfSymbolsMustBeSpacedCorrectly.cs b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1023DereferenceAndAccessOfSymbolsMustBeSpacedCorrectly.cs index 26e998169..2f711edc0 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1023DereferenceAndAccessOfSymbolsMustBeSpacedCorrectly.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1023DereferenceAndAccessOfSymbolsMustBeSpacedCorrectly.cs @@ -147,54 +147,34 @@ private static void HandleAsteriskToken(SyntaxTreeAnalysisContext context, Synta if (!allowAtLineStart && firstInLine) { // Dereference symbol '*' must {not appear at the beginning of a line}. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationPreceding, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), "not appear at the beginning of a line")); + var properties = OpenCloseSpacingCodeFixProvider.RemovePreceding; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, "not appear at the beginning of a line")); } else if (!allowPrecedingSpace && precededBySpace) { // Dereference symbol '*' must {not be preceded by a space}. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationPreceding, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), "not be preceded by a space")); + var properties = OpenCloseSpacingCodeFixProvider.RemovePreceding; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, "not be preceded by a space")); } if (!allowAtLineEnd && lastInLine) { // Dereference symbol '*' must {not appear at the end of a line}. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationFollowing, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), "not appear at the end of a line")); + var properties = OpenCloseSpacingCodeFixProvider.RemoveFollowing; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, "not appear at the end of a line")); } else if (!allowTrailingSpace && followedBySpace) { // Dereference symbol '*' must {not be followed by a space}. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationFollowing, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), "not be followed by a space")); + var properties = OpenCloseSpacingCodeFixProvider.RemoveFollowing; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, "not be followed by a space")); } if (!followedBySpace && allowTrailingSpace) { // Dereference symbol '*' must {be followed by a space}. - var properties = new Dictionary - { - [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationFollowing, - [OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionInsert - }; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), "be followed by a space")); + var properties = OpenCloseSpacingCodeFixProvider.InsertFollowing; + context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, "be followed by a space")); } } }