bkoelman / csharpguidelinesanalyzer Goto Github PK
View Code? Open in Web Editor NEWReports diagnostics for C# coding guidelines that are not already covered by Resharper.
License: Apache License 2.0
Reports diagnostics for C# coding guidelines that are not already covered by Resharper.
License: Apache License 2.0
This analyzer should report on static classes whose name does not end in Extensions -or- contain public/internal methods that do not have this
as first parameter.
Consider merge with AV1008.
This analyzer should report in case the dataflow API reports one or more writes in the loop body for variables that are declared in the loop statement.
This analyzer should report when the AssemblyTitle
, AssemblyDescription
, AssemblyConfiguration
, AssemblyCompany
, AssemblyProduct
, AssemblyCopyright
, AssemblyTrademark
, AssemblyCulture
, AssemblyVersion
or AssemblyFileVersion
is missing or invoked with an empty string as first constructor parameter.
Note there may not be a location to report on.
This analyzer should report at event add/remove assignments, in case the assigned method name is not suffixed with "On" followed by the event name.
Enabling XML generation by the compiler already performs these checks for public and protected types and members.
This analyzer should perform the same checks, but for internal types and members.
This analyzer should first identify the overload with the most parameters. If the method (or constructor) being analyzed is a different one, report if it does not call one of the other overloads in its method body.
UseUnderscoresForUnusedLambdaParametersAnalyzer
public class Class1
{
public event PropertyChangedEventHandler PropertyChanged = delegate { };
}
no exceptions
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at CSharpGuidelinesAnalyzer.Rules.Naming.UseUnderscoresForUnusedLambdaParametersAnalyzer.AnalyzeParameterUsage(IParameterSymbol parameter, IMethodSymbol method, OperationAnalysisContext context)
at CSharpGuidelinesAnalyzer.Rules.Naming.UseUnderscoresForUnusedLambdaParametersAnalyzer.AnalyzeLambdaExpression(OperationAnalysisContext context)
at CSharpGuidelinesAnalyzer.Extensions.AnalysisContextExtensions.SkipInvalid(OperationAnalysisContext context, Action`1 action)
at CSharpGuidelinesAnalyzer.Rules.Naming.UseUnderscoresForUnusedLambdaParametersAnalyzer.<Initialize>b__8_0(OperationAnalysisContext c)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c.<ExecuteOperationAction>b__44_0(ValueTuple`2 data)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
This analyzer should check for the word "And" in type names.
This analyzer should report on nested variable assignment expressions, but also on field declarations with multiple declarators.
Update help links in analyzers to deeplink into their corresponding rule on GitHub.
For example (GitHub):
For example (website):
https://csharpcodingguidelines.com/class-design-guidelines/#av1011
This analyzer should report on single-character type parameters, except for T
. The rest is covered by CA1715 (FxCop) and R# formatting settings.
This analyzer should report single-line and multi-line comment trivia inside method bodies.
This analyzer should report on members whose name ends with the name of their containing type.
This analyzer should report on overriden members that have the new
keyword in their signature.
This analyzer should report on non-protected / non-virtual methods that invoke an event. Also should report when method name does match event name prefixed with "On".
AV1522: AssignVariablesInSeparateStatementsAnalyzer
Action act = () =>
{
int iii = 5;
int jjj = 4;
Console.WriteLine(iii);
Console.WriteLine(jjj);
};
No report of AV1522.
AV1522 is reported:
'act', 'iii' and 'jjj' are assigned in a single statement.
This analyzer should report when a type name contains (or equals) a blacklisted word. Blacklisted words: Utility, Utilities, Facility, Facilities, Helper, Helpers, Common, Shared.
This analyzer should report when CompilationStartAnalysisContext.Compilation.Options.WarningLevel indicates a value lower than 4.
This analyzer should report on various variations of "TODO" in comment trivia.
AV1568: DoNotAssignToParametersAnalyzer
This analyzer uses the SemanticModel.AnalyzeDataFlow API to determine whether parameters are written to in the method body. This works great for reference types. But for parameters of type struct
, it reports a write on invocation of the struct
member. As explained, this is by design.
For the moment, reporting on parameters of type struct
is disabled to prevent false reports. To fix this, we should write an IOperation
-based walker to analyze assignments and expressions within the method body.
See unittest When_struct_parameter_is_written_to_in_method_body_it_must_be_reported
, which is currently disabled.
This analyzer should report on for/foreach/while/do loops that are nested within another loop.
This analyzer should report on boolean variables, parameters and fields whose names do not start with the word "Is", "Has", "Allows", "Can", "Should", "Will", "Do" or "Supports".
This analyzer should report if the name of a variable or parameter is on the next blacklist: b001, lo, I1, lOl.
This analyzer should report when a syntax tree contains multiple non-nested type declarations. Note that multiple namespace scopes may be declared.
This rule was removed from the set of guidelines.
This analyzer should report when null is passed for the "sender" parameter at invocation and the event is declared as non-static. Also report when null is passed for the "args" parameter at invocation.
This analyzer should report on members whose signature returns a class/struct that implements IEnumerable
.
All
Roslyn analyzers are run and evaluate code correctly.
Roslyn analyzers are run and evaluate code correctly.
Errors similar to the following for are generated for each analyzer and the analyzers are not run
CSC : error CS8032: An instance of analyzer CSharpGuidelinesAnalyzer.Rules.Naming.AvoidMisleadingNamesAnalyzer cannot be created from /Users/kevinford/Documents/Projects/VSLiveCICDDemo/Code/BuildTest/packages/CSharpGuidelinesAnalyzer.1.0.1/analyzers/dotnet/cs/CSharpGuidelinesAnalyzer.dll : Exception has been thrown by the target of an invocation.. [/Users/kevinford/Documents/Projects/VSLiveCICDDemo/Code/BuildTest/iOS/BuildTest.iOS.csproj]
Because of this no project with references to Roslyn analyzer DLLs compile in the newest Visual Studio for Mac.
See the following bug for more information.
This analyzer should report on types whose namespace does not start with the assembly name. But suppress when assembly name ends with ".Core".
This analyzer should report on single-letter variable names. But also if an identifier contains a blacklisted word. Words on the blacklist: "Btn", "Ctrl", "Frm".
This analyzer should report in case an if-else-if (-else-if etc.) block does not end with an unconditional else clause.
This analyzer should walk the statement tree of a method body and report when more than seven statements are found.
This analyzer should report if a default case is missing while the set of existing case labels does not cover the complete value range. Determining if the set of case labels is complete will only be done for switches of type bool, bool? and (nullable) non-flags enums.
The Deconstruct
method in the example below should not be reported on.
public class Point
{
public int X { get; }
public int Y { get; }
public Point(int x, int y)
{
X = x;
Y = y;
}
public void Deconstruct(out int x, out int y)
{
x = X;
y = Y;
}
}
public class Example
{
public void Test(Point point)
{
var (x, y) = point;
Console.WriteLine($"Coordinates: ({x}, {y})");
}
}
Deconstruct
(which may occur as instance method or extension method) should be considered an exception to AV1562, because the compiler recognizes this method to deconstruct an object into tuple elements.
This analyzer should report unused lambda parameters whose names contain any characters other than underscore.
This analyzer should report when a member, parameter or variable that is declared as dynamic
is assigned the result of an expression whose type is not object
or dynamic
.
This analyzer should report usage of named arguments of non-(nullable-)boolean types.
This analyzer should report on (nullable) boolean parameters.
This analyzer should report on usages of the logical not operator with an argument that contains the word "No" or "Not" in it.
This analyzer should report on write usage of parameters that are not declared as ref
or out
.
This analyzer should report on invocations of Task.ContinueWith()
.
AV1568: DoNotAssignToParametersAnalyzer
Results of running the analyzers on its own codebase:
1> Total analyzer execution time: 0.670 seconds. (TaskId:28)
1> NOTE: Elapsed time may be less than analyzer execution time because analyzers can run concurrently. (TaskId:28)
1> Time (s) % Analyzer (TaskId:28)
1> 0.498 74 CSharpGuidelinesAnalyzer, Version=0.2.0.0, Culture=neutral, PublicKeyToken=null (TaskId:28)
1> 0.121 18 CSharpGuidelinesAnalyzer.Maintainability.DoNotAssignToParametersAnalyzer (TaskId:28)
1> 0.051 7 CSharpGuidelinesAnalyzer.Documentation.AvoidInlineCommentsAnalyzer (TaskId:28)
1> 0.040 5 CSharpGuidelinesAnalyzer.Naming.UseUnderscoresForUnusedLambdaParametersAnalyzer (TaskId:28)
1> 0.028 4 CSharpGuidelinesAnalyzer.Documentation.AvoidToDoCommentsAnalyzer (TaskId:28)
1> 0.021 3 CSharpGuidelinesAnalyzer.Naming.DoNotUseAbbreviationsInIdentifierNamesAnalyzer (TaskId:28)
1> 0.021 3 CSharpGuidelinesAnalyzer.Maintainability.IfElseIfStatementsShouldFinishWithElseClauseAnalyzer (TaskId:28)
1> 0.014 2 CSharpGuidelinesAnalyzer.ClassDesign.DoNotHideInheritedMembersAnalyzer (TaskId:28)
1> 0.013 1 CSharpGuidelinesAnalyzer.Naming.NamePropertiesWithAnAffirmativePhraseAnalyzer (TaskId:28)
1> 0.013 1 CSharpGuidelinesAnalyzer.Maintainability.AvoidMultipleTypesPerFileAnalyzer (TaskId:28)
1> 0.012 1 CSharpGuidelinesAnalyzer.Maintainability.AvoidMembersWithMoreThanSevenStatementsAnalyzer (TaskId:28)
1> 0.012 1 CSharpGuidelinesAnalyzer.ClassDesign.MembersShouldDoASingleThingAnalyzer (TaskId:28)
1> 0.011 1 CSharpGuidelinesAnalyzer.Maintainability.NamespacesShouldMatchAssemblyNameAnalyzer (TaskId:28)
1> 0.011 1 CSharpGuidelinesAnalyzer.ClassDesign.AvoidStaticClassesAnalyzer (TaskId:28)
1> 0.010 1 CSharpGuidelinesAnalyzer.Maintainability.OverloadsShouldCallOtherOverloadsAnalyzer (TaskId:28)
1> 0.009 1 CSharpGuidelinesAnalyzer.Naming.DoNotUseNumbersInIdentifiersAnalyzer (TaskId:28)
1> 0.009 1 CSharpGuidelinesAnalyzer.Maintainability.DoNotChangeLoopVariablesAnalyzer (TaskId:28)
1> 0.009 1 CSharpGuidelinesAnalyzer.Framework.ProvideAssemblyInformationAnalyzer (TaskId:28)
1> 0.008 1 CSharpGuidelinesAnalyzer.MiscellaneousDesign.EvaluateQueriesBeforeReturningThemAnalyzer (TaskId:28)
1> 0.007 1 CSharpGuidelinesAnalyzer.MiscellaneousDesign.DoNotPassNullsOnEventInvocationAnalyzer (TaskId:28)
1> 0.006 <1 CSharpGuidelinesAnalyzer.Maintainability.AssignVariablesInSeparateStatementsAnalyzer (TaskId:28)
1> 0.006 <1 CSharpGuidelinesAnalyzer.Maintainability.AvoidBooleanParametersAnalyzer (TaskId:28)
1> 0.006 <1 CSharpGuidelinesAnalyzer.Documentation.DocumentAllInternalMembersAnalyzer (TaskId:28)
1> 0.006 <1 CSharpGuidelinesAnalyzer.Maintainability.AvoidConditionsWithDoubleNegativesAnalyzer (TaskId:28)
1> 0.005 <1 CSharpGuidelinesAnalyzer.Maintainability.AvoidExplicitBooleanComparisonsAnalyzer (TaskId:28)
1> 0.005 <1 CSharpGuidelinesAnalyzer.Framework.OnlyUseDynamicForUnknownTypesAnalyzer (TaskId:28)
1> 0.005 <1 CSharpGuidelinesAnalyzer.Naming.AvoidMisleadingNamesAnalyzer (TaskId:28)
1> 0.004 <1 CSharpGuidelinesAnalyzer.MemberDesign.ReturnInterfacesToCollectionsAnalyzer (TaskId:28)
1> 0.004 <1 CSharpGuidelinesAnalyzer.ClassDesign.TypesShouldHaveASinglePurposeAnalyzer (TaskId:28)
1> 0.004 <1 CSharpGuidelinesAnalyzer.Framework.FavorAsyncAwaitOverTaskContinueWithAnalyzer (TaskId:28)
1> 0.003 <1 CSharpGuidelinesAnalyzer.Naming.UseFrameworkTerminologyInMemberNamesAnalyzer (TaskId:28)
1> 0.003 <1 CSharpGuidelinesAnalyzer.Maintainability.SwitchStatementsShouldHaveADefaultCaseAnalyzer (TaskId:28)
1> 0.003 <1 CSharpGuidelinesAnalyzer.Maintainability.AvoidMembersWithMoreThanThreeParametersAnalyzer (TaskId:28)
1> 0.003 <1 CSharpGuidelinesAnalyzer.Naming.DoNotIncludeContainingTypeNameInMembersAnalyzer (TaskId:28)
1> 0.003 <1 CSharpGuidelinesAnalyzer.MiscellaneousDesign.RaiseEventsFromProtectedVirtualMethodsAnalyzer (TaskId:28)
1> 0.002 <1 CSharpGuidelinesAnalyzer.Maintainability.AvoidNestedLoopsAnalyzer (TaskId:28)
1> 0.002 <1 CSharpGuidelinesAnalyzer.Naming.StaticClassesShouldOnlyContainExtensionMethodsAnalyzer (TaskId:28)
1> 0.002 <1 CSharpGuidelinesAnalyzer.Naming.DoNotUseHelperMethodsAnalyzer (TaskId:28)
1> 0.002 <1 CSharpGuidelinesAnalyzer.Maintainability.AvoidUsingNamedArgumentsAnalyzer (TaskId:28)
1> 0.002 <1 CSharpGuidelinesAnalyzer.Framework.BuildWithTheHighestWarningLevelAnalyzer (TaskId:28)
1> 0.001 <1 CSharpGuidelinesAnalyzer.Maintainability.CaseClausesInSwitchStatementsShouldHaveBracesAnalyzer (TaskId:28)
1> 0.001 <1 CSharpGuidelinesAnalyzer.Naming.NameAsyncMethodsCorrectlyAnalyzer (TaskId:28)
1> <0.001 <1 CSharpGuidelinesAnalyzer.Naming.PrefixEventHandlersWithOnAnalyzer (TaskId:28)
1> 0.146 21 Microsoft.CodeAnalysis.CSharp.Analyzers, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (TaskId:28)
1> 0.093 13 Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpReportDiagnosticAnalyzer (TaskId:28)
1> 0.041 6 Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpRegisterActionAnalyzer (TaskId:28)
1> 0.008 1 Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpDiagnosticAnalyzerFieldsAnalyzer (TaskId:28)
1> 0.003 <1 Microsoft.CodeAnalysis.CSharp.Analyzers.CSharpImmutableObjectMethodAnalyzer (TaskId:28)
1> 0.001 <1 Microsoft.CodeAnalysis.CSharp.Analyzers.FixAnalyzers.CSharpFixerWithFixAllAnalyzer (TaskId:28)
1> <0.001 <1 Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpDiagnosticDescriptorCreationAnalyzer (TaskId:28)
1> 0.019 2 CodeContractNullability, Version=1.0.5.0, Culture=neutral, PublicKeyToken=null (TaskId:28)
1> 0.010 1 CodeContractNullability.CodeContractItemNullabilityAnalyzer (TaskId:28)
1> 0.008 1 CodeContractNullability.CodeContractNullabilityAnalyzer (TaskId:28)
1> 0.007 1 Microsoft.CodeAnalysis.Analyzers, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (TaskId:28)
1> 0.007 1 Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.DiagnosticAnalyzerAttributeAnalyzer (TaskId:28)
1> <0.001 <1 Microsoft.CodeAnalysis.Analyzers.InternalImplementationOnlyAnalyzer (TaskId:28)
The output above shows that DoNotAssignToParametersAnalyzer
takes a lot of time. It runs (expensive) dataflow analysis on the method body for each parameter individually. We should register on method instead, then run the analysis once and inspect results for each parameter.
All keywords are already covered by R#, except case blocks. This analyzer should report when a case statement does not have a block.
This analyzer should report when a digit occurs in a type/member/parameter/variable name.
This is already a little bit covered by CA1726 (FxCop).
This analyzer should report on members that contain one of these words: AddItem, Delete, NumberOfItems.
This analyzer should report on static property getters whose method body contains an execution path that returns a type that has non-static members.
This analyzer should report on static classes whose name does not end in Extensions -or- contain public methods that do not have this
as first parameter. Consider merging with AV1745.
This analyzer should check for the word "And" in member names. Similar to AV0001.
This analyzer should report on returning the result of calling a white-listed method. The white-list is the subset of members from System.Enumerable that use deferred execution.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.