diff --git a/pom.xml b/pom.xml
index 1e0d830fec1..3589919ee17 100644
--- a/pom.xml
+++ b/pom.xml
@@ -134,7 +134,7 @@
params
behavior. To ease readability, this modifier should be explicitly used in
+ the overriding method as well.
+
+class Base +{ + public virtual void Method(params int[] numbers) + { + ... + } +} +class Derived : Base +{ + public override void Method(int[] numbers) // Noncompliant, the params is missing. + { + ... + } +} ++ +
+class Base +{ + public virtual void Method(params int[] numbers) + { + ... + } +} +class Derived : Base +{ + public override void Method(params int[] numbers) + { + ... + } +} ++]]> +
expr is SomeType
operatortypeInstance.IsInstanceOfType(expr)
expr1.GetType().IsAssignableFrom(expr2.GetType())
+A expr1; +B expr2; +if (expr2.GetType().IsAssignableFrom(expr1.GetType())) { /* ... */ } // Noncompliant ++ +
+A expr; +if (expr is MyType) { /* ... */ } ++ +or, when the type is not known at compile time: + +
+A expr; +Type myType; +if (myType.IsInstanceOfType(expr)) { /* ... */ } +]]>
CallerFilePathAttribute
, CallerLineNumberAttribute
, and
+ CallerMemberNameAttribute
) provide a way to get information about the caller of a method through optional parameters.
+ But the arguments for these optional parameters are only generated if they are not explicitly defined in the call. Thus, specifying
+ the argument values defeats the purpose of the attributes.
+
+
++void TraceMessage(string message, + [CallerMemberName] string memberName = "", + [CallerFilePath] string filePath = "", + [CallerLineNumber] int lineNumber = 0) +{ + /* ... */ +} + +void MyMethod() +{ + TraceMessage("my message", "MyMethod"); // Noncompliant +} ++ +
+void TraceMessage(string message, + [CallerMemberName] string memberName = "", + [CallerFilePath] string filePath = "", + [CallerLineNumber] int lineNumber = 0) +{ + /* ... */ +} + +void MyMethod() +{ + TraceMessage("my message"); +} ++]]>
+public class Car +{ + private string _make; + public string Make // Noncompliant + { + get { return _make; } + set { _make = value; } + } +} ++ +
+public class Car +{ + public string Make { get; set; } +} ++]]>
+class X +{ + public X() + { + /* ... */ + } +} + +class Y : X +{ + public Y(int parameter) : base() // Noncompliant + { + /* does something with the parameter */ + } +} ++ +
+class X +{ + public X() + { + /* ... */ + } +} + +class Y : X +{ + public Y(int parameter) + { + /* does something with the parameter */ + } +} ++]]>
Object
- all classes extend Object
implicitly.int
for an enum
+public class MyClass : Object // Noncompliant + +enum MyEnum : int // Noncompliant ++ +
+public class MyClass + +enum MyEnum ++]]>
virtual
on members of classes that are never overriddenpartial
on type declarations that are completely defined in one placesealed
on members of sealed
classes+internal partial class MyClass // Noncompliant; +{ + public virtual void DoSomething() // Noncompliant; virtual is gratuitous + { + // ... + } +} ++ +
+internal class MyClass +{ + public void DoSomething() + { + // ... + } +} ++]]>
+const uint a = 0u; // Noncompliant +const long b = 0l; // Noncompliant +const ulong c = 0Ul; // Noncompliant +const ulong d = 0uL; // Noncompliant +const decimal e = 1.2m; // Noncompliant +const float f = 1.2f; // Noncompliant +const double g = 1.2d; // Noncompliant ++ +
+const uint a = 0U; +const long b = 0L; +const ulong c = 0UL; +const ulong d = 0UL; +const decimal e = 1.2M; +const float f = 1.2F; +const double g = 1.2D; ++ +
+var s1 = string.Format("{0} {1} {2}", 1, 2); // Noncompliant; too few arguments +var s2 = string.Format("{0}", 10, 11); // Noncompliant; too many arguments ++ +
+// Pass the expected number of arguments +var s1 = string.Format("{0} {1} {2}", 1, 2, 3); +var s2 = string.Format("{0}", 10); ++or +
+// Fix the format string +var s1 = string.Format("{0} {1}", 1, 2); +var s2 = string.Format("{0} {1}", 10, 11); ++]]>
+class MyClass +{ + public static int X = Y; // Noncompliant; Y at this time is still assigned default(int), i.e. 0 + public static int Y = 42; +} ++ +
+class MyClass +{ + public static int Y = 42; + public static int X = Y; +} ++or +
+class MyClass +{ + public static int X; + public static int Y = 42; + + static MyClass() + { + X = Y; + } +} +]]>
const
fields are ignored.
]]>
out
and in
modifiers when possible to make the interfaces and delegates covariant and contravariant,
+ respectively.
+
+
+ The out
keyword can be used when the type parameter is used only as a return type in the interface or delegate.
+ Doing so makes the parameter covariant, and allows interface and delegate instances created with a sub-type to be used as
+ instances created with a base type. The most notable example of this is IEnumerable<out T>
, which allows
+ the assignment of an IEnumerable<string>
instance to an IEnumerable<object>
variable,
+ for instance.
+
+ The in
keyword can be used when the type parameter is used only as a method parameter in the interface or a
+ parameter in the delegate. Doing so makes the parameter contravariant, and allows interface and delegate instances created
+ with a base type to be used as instances created with a sub-type. I.e. this is the inversion of covariance. The most notable
+ example of this is the Action<in T>
delegate, which allows the assignment of an
+ Action<object>
instance to a Action<string>
variable, for instance.
+
+interface IConsumer<T> // Noncompliant +{ + bool Eat(T fruit); +} ++ +
+interface IConsumer<in T> +{ + bool Eat(T fruit); +} ++]]>
MyDelegate chain23 = chain1234 - first - fourth; // Compliant - "1" is first removed, followed by "4" @@ -3025,14 +3471,11 @@ string s = File.ReadAllText(fileName);S2760 Sequential tests should not check the same condition -CRITICAL +MAJOR SINGLE - When the same condition is checked twice in a row, it is either inefficient - why not combine the checks? - or an error - - some other condition should have been checked in the second test. - - -- This rule raises an issue when sequential
if
s orswitch
es test the same condition. + When the same condition is checked twice in a row, it is either confusing - why have separate checks? - or an error - some other condition + should have been checked in the second test.Noncompliant Code Example
@@ -3070,10 +3513,10 @@ if (b == c)Exceptions
- This rule ignores sequential
]]>if
statements when any symbols checked in the condition is modified within - the firstif
. + Since it is a common pattern to test a variable, reassign it if it fails the test, then re-test it, that pattern is ignored.bug +clumsy +suspicious S1862 diff --git a/src/main/resources/org/sonar/plugins/csharp/sqale.xml b/src/main/resources/org/sonar/plugins/csharp/sqale.xml index bf2fb37e43f..e60deb93fdf 100644 --- a/src/main/resources/org/sonar/plugins/csharp/sqale.xml +++ b/src/main/resources/org/sonar/plugins/csharp/sqale.xml @@ -1,6 +1,141 @@ + + +UNDERSTANDABILITY ++ +S3262 ++ +remediationFunction +CONSTANT_ISSUE ++ +offset ++ 2min ++ +UNDERSTANDABILITY ++ +S2219 ++ +remediationFunction +CONSTANT_ISSUE ++ +offset ++ 5min ++ +DATA_RELIABILITY ++ +S3236 ++ +remediationFunction +CONSTANT_ISSUE ++ +offset ++ 2min ++ +READABILITY ++ +S2292 ++ +remediationFunction +CONSTANT_ISSUE ++ +offset ++ 5min ++ +READABILITY ++ +S3253 ++ +remediationFunction +CONSTANT_ISSUE ++ +offset ++ 2min ++ +UNDERSTANDABILITY ++ +S1939 ++ +remediationFunction +CONSTANT_ISSUE ++ +offset ++ 1min ++ +UNDERSTANDABILITY ++ +S2333 ++ +remediationFunction +CONSTANT_ISSUE ++ +offset ++ 2min ++ +UNDERSTANDABILITY ++ +S818 ++ +remediationFunction +CONSTANT_ISSUE ++ +offset ++ 2min ++ INSTRUCTION_RELIABILITY ++ +S2275 ++ +remediationFunction +CONSTANT_ISSUE ++ +offset ++ 10min ++ READABILITY @@ -76,6 +211,21 @@ + INSTRUCTION_RELIABILITY ++ +S3263 ++ +remediationFunction +CONSTANT_ISSUE ++ +offset ++ 5min ++ UNDERSTANDABILITY @@ -106,6 +256,21 @@ + UNDERSTANDABILITY ++ +S3246 ++ +remediationFunction +CONSTANT_ISSUE ++ +offset ++ 5min +LOGIC_RELIABILITY @@ -992,7 +1157,7 @@ - LOGIC_RELIABILITY +UNDERSTANDABILITY S2760