Here's your 6 Pack for New Year's Eve... "NR6Pack for Visual Studio 2015"

Today's post comes to us via a post from Andreas Weizel, Installing and Using NR6Pack NuGet Package in Projects

Now our refactoring and analyzers extension NR6Pack is available on NuGet! It's a good alternative for all who want to include NR6Pack analyzers to a project without requiring every developer in team to install the extension as add-on in Visual Studio (2015). And it's really easy to integrate, as I'll show you here.

Let's start with a very simple console application project doing something very bad: It compares two float values using "==", a common mistake that might be hard to find later:

...

I know it's still a little early to highlight Visual Studio 2015 projects too often, but this year HAS been the Year of Roslyn, and this project shows off the capabilities and possibilities of the .NET Complier Platform and it seems like a cool way to wrap up 2014...

NR6Pack for Visual Studio 2015

NR6Pack is a collection of refactorings and analyzers from the NRefactory open-source project packaged specifically for VS 2015.

  • Refactorings - 71
  • Analyzers - 73
It is free!

Yes! And open source (MIT license) on top of it. Spread the word, let the community know that you are using NR6Pack!

Contributing

Feedback is contributing - let us know what to improve, rate us in the gallery! For code-centric contributions, please go to our GitHub page.

History

Given that the SharpDevelop team is building an IDE of their own, why are we supporting an IDE other than ours?

NRefactory is a library geared towards anyone that needs IDE services - think code completion, refactoring, code fixes and more. It started life a very long time ago in SharpDevelop, was at times developed in parallel in MonoDevelop, and roundabout 2010 the two teams joined forces to bring NRefactory5 to life as a full open source stack of IDE services (MonoDevelop 3 and SharpDevelop 5 ship(ped) with this version).

NR6 is leveraging Roslyn instead of our homegrown stack components to make development easier and faster. Thus we also re-architected our refactorings around the Roslyn way of doing things, making the new refactorings and analyzers reuseable for anyone that speaks Roslyn. After all, open source isn't about duplicating effort - at least in our book.

In effect NR6Pack is merely a repackaged variant of NRefactory 6 refactorings for Visual Studio 2015. It bundles a subset of the refactorings and code issue fixes. We arrived at this subset because you don't need a second rename refactoring when one is already in-box with VS. We cherry picked the things that make sense.

Refactorings

71 code actions available!

  • Make abstract member virtual/non-abstract and vice-versa (AbstractAndVirtualConversionAction)
  • Add another accessor (AddAnotherAccessorAction)
  • Add name for argument (AddArgumentNameAction)
  • Add braces (AddBracesAction)
  • Add type to general catch clause (AddCatchTypeAction)
  • Add one or more optional parameters to an invocation, using their default values (AddOptionalParameterToInvocationAction)
  • Check if parameter is null (CheckIfParameterIsNullAction)
  • Compute constant value (ComputeConstantValueAction)
  • Convert anonymous delegate to lambda (ConvertAnonymousDelegateToLambdaAction)
  • Convert assignment to 'if' (ConvertAssignmentToIfAction)
  • Convert 'as' to cast. (ConvertAsToCastAction)
  • Replace bitwise flag comparison with call to 'Enum.HasFlag' (ConvertBitwiseFlagComparisonToHasFlagsAction)
  • Convert cast to 'as'. (ConvertCastToAsAction)
  • Convert dec to hex. (ConvertDecToHexAction)
  • Convert do...while to while (ConvertDoWhileToWhileLoopAction)
  • Convert '==' to 'Equals' (ConvertEqualityOperatorToEqualsAction)
  • Convert 'Equals' to '==' (ConvertEqualsToEqualityOperatorAction)
  • Convert explicit to implict implementation (ConvertExplicitToImplicitImplementationAction)
  • Convert 'foreach' loop to 'for' (ConvertForeachToForAction)
  • Convert 'for' loop to 'while' (ConvertForToWhileAction)
  • Replace 'Enum.HasFlag' call with bitwise flag comparison (ConvertHasFlagsToBitwiseFlagComparisonAction)
  • Convert hex to dec. (ConvertHexToDecAction)
  • Convert 'if' to '?:' (ConvertIfStatementToConditionalTernaryExpressionAction)
  • Convert 'if' to '??' expression (ConvertIfStatementToNullCoalescingExpressionAction)
  • Convert 'if' to 'return' (ConvertIfStatementToReturnStatementAction)
  • Convert implict to explicit implementation (ConvertImplicitToExplicitImplementationAction)
  • Converts expression of lambda body to statement (ConvertLambdaBodyExpressionToStatementAction)
  • Converts statement of lambda body to expression (ConvertLambdaBodyStatementToExpressionAction)
  • Convert lambda to anonymous delegate (ConvertLambdaToAnonymousDelegateAction)
  • Convert method group to anoymous method (ConvertMethodGroupToAnonymousMethodAction)
  • Convert method group to lambda expression (ConvertMethodGroupToLambdaAction)
  • Convert '*'/'/' to '<<'/'>>' (ConvertMultiplyToShiftAction)
  • Convert '??' to '?:' (ConvertNullCoalescingToConditionalExpressionAction)
  • Convert 'return' to 'if' (ConvertReturnStatementToIfAction)
  • Convert '<<'/'>>' to '*'/'/' (ConvertShiftToMultiplyAction)
  • Convert 'switch' to 'if' (ConvertSwitchToIfAction)
  • Convert while loop to do...while (ConvertWhileToDoWhileLoopAction)
  • Create backing store for auto property (CreateBackingStoreAction)
  • Create changed event for property (CreateChangedEventAction)
  • Create custom event implementation (CreateCustomEventImplementationAction)
  • Extension methods must be declared static (CS1105ExtensionMethodMustBeDeclaredStaticAction)
  • Invoke using static method syntax (ExtensionMethodInvocationToStaticMethodInvocationAction)
  • Extract anonymous method (ExtractAnonymousMethodAction)
  • Extract field (ExtractWhileConditionToInternalIfStatementAction)
  • Swap 'Equals' target and argument (FlipEqualsTargetAndArgumentAction)
  • Swap left and right arguments (FlipOperatorArgumentsAction)
  • Generate switch labels (GenerateSwitchLabelsAction)
  • Create a backing field for a not implemented property (ImplementNotImplementedProperty)
  • Invert conditional operator (InvertConditionalOperatorAction)
  • Invert if (InvertIfAction)
  • Invert If and Simplify (InvertIfAndSimplify)
  • Invert logical expression (InvertLogicalExpressionAction)
  • Join local variable declaration and assignment (JoinDeclarationAndAssignmentAction)
  • Join string literal (JoinStringAction)
  • Negate 'is' expression (NegateIsExpressionAction)
  • Negate a relational expression (NegateRelationalExpressionAction)
  • Remove backing store for property (RemoveBackingStoreAction)
  • Remove braces (RemoveBracesAction)
  • Remove region (RemoveRegionAction)
  • Replace assignment with postfix expression (ReplaceAssignmentWithPostfixExpressionAction)
  • Use string.Empty (ReplaceEmptyStringAction)
  • Replace operator assignment with assignment (ReplaceOperatorAssignmentWithAssignmentAction)
  • Replace postfix expression with assignment (ReplacePostfixExpressionWithAssignmentAction)
  • Replace assignment with operator assignment (ReplaceWithOperatorAssignmentAction)
  • Simplify if flow (SimplifyIfFlowAction)
  • Simplify if flow in loops (SimplifyIfInLoopsFlowAction)
  • Split local variable declaration and assignment (SplitDeclarationAndAssignmentAction)
  • Split 'if' statement (SplitIfAction)
  • Use 'as' and null check (UseAsAndNullCheckAction)
  • Use explicit type (UseExplicitTypeAction)
  • Use 'var' keyword (UseVarKeywordAction)

Analyzers

73 code issues available!

  • Removes 'internal' modifiers that are not required (RedundantInternalIssue)
  • Removes 'private' modifiers that are not required (RedundantPrivateIssue)
  • Call to base member with implicit default parameters (BaseMethodCallWithDefaultParameterIssue)
  • Bitwise operation on enum which has no [Flags] attribute (BitwiseOperatorOnEnumWithoutFlagsIssue)
  • Possible compare of value type with 'null' (CompareNonConstrainedGenericWithNullIssue)
  • Comparison of floating point numbers with equality operator (CompareOfFloatsByEqualityOperatorIssue)
  • '?:' expression has identical true and false branches (ConditionalTernaryEqualBranchIssue)
  • Delegate subtraction has unpredictable result (DelegateSubtractionIssue)
  • Warns about calls to virtual member functions occuring in the constructor. (DoNotCallOverridableMethodsInConstructorIssue)
  • A catch clause that catches System.Exception and has an empty body (EmptyGeneralCatchClauseIssue)
  • Function does not reach its end or a 'return' statement by any of possible execution paths. (FunctionNeverReturnsIssue)
  • Lowercase 'l' is often confused with '1' (LongLiteralEndingLowerLIssue)
  • Non-readonly field referenced in 'GetHashCode()' (NonReadonlyReferencedInGetHashCodeIssue)
  • Possible unassigned object created by 'new' (ObjectCreationAsStatementIssue)
  • Operator Is can be used instead of comparing object GetType() and instances of System.Type object (OperatorIsCanBeUsedIssue)
  • C# doesn't support optional 'ref' or 'out' parameters (OptionalParameterRefOutIssue)
  • Non public methods are not found by NUnit (NonPublicMethodWithTestAttributeIssue)
  • Anonymous method or lambda expression can be simplified to method group (ConvertClosureToMethodGroupIssue)
  • '?:' expression can be converted to '??' expression. (ConvertConditionalTernaryToNullCoalescingIssue)
  • Convert 'Nullable<T>' to the short form 'T?' (ConvertNullableToShortFormIssue)
  • If all fields, properties and methods members are static, the class can be made static. (ConvertToStaticTypeIssue)
  • If an extension method is called as static method convert it to method syntax (InvokeAsExtensionMethodIssue)
  • Suggests using the class declaring a static function when calling it. (AccessToStaticMemberViaDerivedTypeIssue)
  • Base parameter has 'params' modifier, but missing in overrider (BaseMemberHasParamsIssue)
  • Convert 'if' to '||' expression (ConvertIfToOrExpressionIssue)
  • Empty control statement body (EmptyEmbeddedStatementIssue)
  • Possible mistaken call to 'object.GetType()' (PossibleMistakenCallToGetTypeIssue)
  • Replace with call to FirstOrDefault<T>() (ReplaceWithFirstOrDefaultIssue)
  • Replace with call to LastOrDefault<T>() (ReplaceWithLastOrDefaultIssue)
  • Replace with call to OfType<T>().Any() (ReplaceWithOfTypeAnyIssue)
  • Replace with call to OfType<T>().Count() (ReplaceWithOfTypeCountIssue)
  • Replace with call to OfType<T>().First() (ReplaceWithOfTypeFirstIssue)
  • Replace with call to OfType<T>().FirstOrDefault() (ReplaceWithOfTypeFirstOrDefaultIssue)
  • Replace with call to OfType<T>().Last() (ReplaceWithOfTypeLastIssue)
  • Replace with call to OfType<T>().LastOrDefault() (ReplaceWithOfTypeLastOrDefaultIssue)
  • Replace with call to OfType<T>().LongCount() (ReplaceWithOfTypeLongCountIssue)
  • Replace with call to OfType<T>().Single() (ReplaceWithOfTypeSingleIssue)
  • Replace with call to OfType<T>().SingleOrDefault() (ReplaceWithOfTypeSingleOrDefaultIssue)
  • Replace with call to OfType<T>().Where() (ReplaceWithOfTypeWhereIssue)
  • Replace with simple assignment (ReplaceWithSimpleAssignmentIssue)
  • Replace with single call to Any(...) (ReplaceWithSingleCallToAnyIssue)
  • Replace with single call to Count(...) (ReplaceWithSingleCallToCountIssue)
  • Replace with single call to First(...) (ReplaceWithSingleCallToFirstIssue)
  • Replace with single call to FirstOrDefault(...) (ReplaceWithSingleCallToFirstOrDefaultIssue)
  • Replace with single call to Last(...) (ReplaceWithSingleCallToLastIssue)
  • Replace with single call to LastOrDefault(...) (ReplaceWithSingleCallToLastOrDefaultIssue)
  • Replace with single call to LongCount(...) (ReplaceWithSingleCallToLongCountIssue)
  • Replace with single call to Single(...) (ReplaceWithSingleCallToSingleIssue)
  • Replace with single call to SingleOrDefault(...) (ReplaceWithSingleCallToSingleOrDefaultIssue)
  • Warns when a culture-aware 'EndsWith' call is used by default. (StringEndsWithIsCultureSpecificIssue)
  • Warns when a culture-aware 'IndexOf' call is used by default. (StringIndexOfIsCultureSpecificIssue)
  • Warns when a culture-aware 'LastIndexOf' call is used by default. (StringLastIndexOfIsCultureSpecificIssue)
  • Warns when a culture-aware 'StartsWith' call is used by default. (StringStartsWithIsCultureSpecificIssue)
  • When initializing explicitly typed local variable or array type, array creation expression can be replaced with array initializer. (ArrayCreationCanBeReplacedWithArrayInitializerIssue)
  • Condition is always true or false (ConditionIsAlwaysTrueOrFalseIssue)
  • Double negation is redundant (DoubleNegationOperatorIssue)
  • Empty statement is redundant (EmptyStatementIssue)
  • 'true' is redundant as for statement condition (ForStatementConditionIsTrueIssue)
  • Redundant explicit property name (RedundantAnonymousTypePropertyNameIssue)
  • Redundant explicit argument name specification (RedundantArgumentNameIssue)
  • Parentheses are redundant if attribute has no arguments. (RedundantAttributeParenthesesIssue)
  • 'base.' is redundant and can safely be removed. (RedundantBaseQualifierIssue)
  • Redundant case label (RedundantCaseLabelIssue)
  • Type cast is redundant (RedundantCastIssue)
  • Redundant empty 'default' switch branch (RedundantEmptyDefaultSwitchBranchIssue)
  • Removes namespace usages that are obsolete. (RedundantNameQualifierIssue)
  • Redundant conditional expression (RedundantTernaryExpressionIssue)
  • Remove redundant statement (RemoveRedundantOrStatementIssue)
  • An empty public constructor without paramaters is redundant. (EmptyConstructorIssue)
  • Empty destructor is redundant (EmptyDestructorIssue)
  • Empty namespace declaration is redundant (EmptyNamespaceIssue)
  • The default underlying type of enums is int, so defining it explicitly is redundant. (EnumUnderlyingTypeIsIntIssue)
  • 'sealed' modifier is redundant in sealed classes (SealedMemberInSealedClassIssue)

Here’s a few more links you might find interesting:



Tags:

Follow the discussion

  • Oops, something didn't work.

    Getting subscription
    Subscribe to this conversation
    Unsubscribing
    Subscribing

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.