From 519b0779f2878f0e8f02d09b65deac8e4656842f Mon Sep 17 00:00:00 2001 From: Antonio Aversa Date: Mon, 13 Feb 2023 13:50:28 +0100 Subject: [PATCH 1/4] Modify rule S4545: Add VB.NET specifics, Move C# specifics --- rules/S4545/csharp/rule-except-see.adoc | 35 +++++++++++++++++++++++ rules/S4545/csharp/rule.adoc | 2 +- rules/S4545/rule.adoc | 27 +----------------- rules/S4545/vbnet/rule-except-see.adoc | 37 +++++++++++++++++++++++++ rules/S4545/vbnet/rule.adoc | 2 +- 5 files changed, 75 insertions(+), 28 deletions(-) create mode 100644 rules/S4545/csharp/rule-except-see.adoc create mode 100644 rules/S4545/vbnet/rule-except-see.adoc diff --git a/rules/S4545/csharp/rule-except-see.adoc b/rules/S4545/csharp/rule-except-see.adoc new file mode 100644 index 00000000000..8b317ca2b8b --- /dev/null +++ b/rules/S4545/csharp/rule-except-see.adoc @@ -0,0 +1,35 @@ +The ``++DebuggerDisplayAttribute++`` is used to determine how an object is displayed in the debugger window. + + +The ``++DebuggerDisplayAttribute++`` constructor takes a single argument: the string to be displayed in the value column for instances of the type. Any text within curly braces is evaluated as the name of a field, property, or method. + + +Naming a non-existent field, property or method between curly braces will result in a CS0103 error in the debug window when debugging objects. Although there is no impact on the production code, providing a wrong value can lead to difficulties when debugging the application. + + +This rule raises an issue when text specified between curly braces refers to members that don't exist in the current context. + + +== Noncompliant Code Example + +[source,text] +---- +[DebuggerDisplay("Name: {Name}")] // Noncompliant - Name doesn't exist in this context +public class Person +{ + public string FullName { get; private set; } +} +---- + + +== Compliant Solution + +[source,text] +---- +[DebuggerDisplay("Name: {FullName}")] +public class Person +{ + public string FullName { get; private set; } +} +---- + diff --git a/rules/S4545/csharp/rule.adoc b/rules/S4545/csharp/rule.adoc index f5db9e87ac5..8901619c83d 100644 --- a/rules/S4545/csharp/rule.adoc +++ b/rules/S4545/csharp/rule.adoc @@ -1,4 +1,4 @@ -include::../rule.adoc[] +include::rule-except-see.adoc[] ifdef::env-github,rspecator-view[] diff --git a/rules/S4545/rule.adoc b/rules/S4545/rule.adoc index 8b317ca2b8b..be32fcbb45d 100644 --- a/rules/S4545/rule.adoc +++ b/rules/S4545/rule.adoc @@ -4,32 +4,7 @@ The ``++DebuggerDisplayAttribute++`` is used to determine how an object is displ The ``++DebuggerDisplayAttribute++`` constructor takes a single argument: the string to be displayed in the value column for instances of the type. Any text within curly braces is evaluated as the name of a field, property, or method. -Naming a non-existent field, property or method between curly braces will result in a CS0103 error in the debug window when debugging objects. Although there is no impact on the production code, providing a wrong value can lead to difficulties when debugging the application. +Naming a non-existent field, property or method between curly braces will result in an error in the debug window when debugging objects. Although there is no impact on the production code, providing a wrong value can lead to difficulties when debugging the application. This rule raises an issue when text specified between curly braces refers to members that don't exist in the current context. - - -== Noncompliant Code Example - -[source,text] ----- -[DebuggerDisplay("Name: {Name}")] // Noncompliant - Name doesn't exist in this context -public class Person -{ - public string FullName { get; private set; } -} ----- - - -== Compliant Solution - -[source,text] ----- -[DebuggerDisplay("Name: {FullName}")] -public class Person -{ - public string FullName { get; private set; } -} ----- - diff --git a/rules/S4545/vbnet/rule-except-see.adoc b/rules/S4545/vbnet/rule-except-see.adoc new file mode 100644 index 00000000000..85a2aef69c3 --- /dev/null +++ b/rules/S4545/vbnet/rule-except-see.adoc @@ -0,0 +1,37 @@ +The ``++DebuggerDisplayAttribute++`` is used to determine how an object is displayed in the debugger window. + + +The ``++DebuggerDisplayAttribute++`` constructor takes a single argument: the string to be displayed in the value column for instances of the type. Any text within curly braces is evaluated as the name of a field, property, or method. + + +Naming a non-existent field, property or method between curly braces will result in a BC30451 error in the debug window when debugging objects. Although there is no impact on the production code, providing a wrong value can lead to difficulties when debugging the application. + + +This rule raises an issue when text specified between curly braces refers to members that don't exist in the current context. + + +== Noncompliant Code Example + +[source,vbnet] +---- + ' Noncompliant - Name doesn't exist in this context +Public Class Person + + Public Property FullName As String + +End Class +---- + + +== Compliant Solution + +[source,vbnet] +---- + +Public Class Person + + Public Property FullName As String + +End Class +---- + diff --git a/rules/S4545/vbnet/rule.adoc b/rules/S4545/vbnet/rule.adoc index f5db9e87ac5..8901619c83d 100644 --- a/rules/S4545/vbnet/rule.adoc +++ b/rules/S4545/vbnet/rule.adoc @@ -1,4 +1,4 @@ -include::../rule.adoc[] +include::rule-except-see.adoc[] ifdef::env-github,rspecator-view[] From 5c5b76b7c269b36ccb21ab353f38b111699f3ea4 Mon Sep 17 00:00:00 2001 From: Antonio Aversa Date: Thu, 23 Feb 2023 10:37:55 +0100 Subject: [PATCH 2/4] Review --- rules/S4545/csharp/rule-except-see.adoc | 35 ----------------------- rules/S4545/csharp/rule.adoc | 35 ++++++++++++++++++++++- rules/S4545/highlighting.adoc | 2 +- rules/S4545/message.adoc | 2 +- rules/S4545/rule.adoc | 10 ------- rules/S4545/vbnet/rule-except-see.adoc | 37 ------------------------- rules/S4545/vbnet/rule.adoc | 37 ++++++++++++++++++++++++- 7 files changed, 72 insertions(+), 86 deletions(-) delete mode 100644 rules/S4545/csharp/rule-except-see.adoc delete mode 100644 rules/S4545/rule.adoc delete mode 100644 rules/S4545/vbnet/rule-except-see.adoc diff --git a/rules/S4545/csharp/rule-except-see.adoc b/rules/S4545/csharp/rule-except-see.adoc deleted file mode 100644 index 8b317ca2b8b..00000000000 --- a/rules/S4545/csharp/rule-except-see.adoc +++ /dev/null @@ -1,35 +0,0 @@ -The ``++DebuggerDisplayAttribute++`` is used to determine how an object is displayed in the debugger window. - - -The ``++DebuggerDisplayAttribute++`` constructor takes a single argument: the string to be displayed in the value column for instances of the type. Any text within curly braces is evaluated as the name of a field, property, or method. - - -Naming a non-existent field, property or method between curly braces will result in a CS0103 error in the debug window when debugging objects. Although there is no impact on the production code, providing a wrong value can lead to difficulties when debugging the application. - - -This rule raises an issue when text specified between curly braces refers to members that don't exist in the current context. - - -== Noncompliant Code Example - -[source,text] ----- -[DebuggerDisplay("Name: {Name}")] // Noncompliant - Name doesn't exist in this context -public class Person -{ - public string FullName { get; private set; } -} ----- - - -== Compliant Solution - -[source,text] ----- -[DebuggerDisplay("Name: {FullName}")] -public class Person -{ - public string FullName { get; private set; } -} ----- - diff --git a/rules/S4545/csharp/rule.adoc b/rules/S4545/csharp/rule.adoc index 8901619c83d..4ee3f535256 100644 --- a/rules/S4545/csharp/rule.adoc +++ b/rules/S4545/csharp/rule.adoc @@ -1,4 +1,37 @@ -include::rule-except-see.adoc[] +The ``DebuggerDisplayAttribute`` is used to determine how an object is displayed in the debugger window. + + +The ``DebuggerDisplayAttribute`` constructor takes a single mandatory argument: the string to be displayed in the value column for instances of the type. Any text within curly braces is evaluated as the name of a member, or any complex expression converted to a string value, containing method calls and operators. + + +Naming a non-existent member between curly braces will result in a CS0103 error in the debug window when debugging objects. Although there is no impact on the production code, providing a wrong value can lead to difficulties when debugging the application. + + +This rule raises an issue when text specified between curly braces refers to members that don't exist in the current context. + + +== Noncompliant Code Example + +[source,text] +---- +[DebuggerDisplay("Name: {Name}")] // Noncompliant - Name doesn't exist in this context +public class Person +{ + public string FullName { get; private set; } +} +---- + + +== Compliant Solution + +[source,text] +---- +[DebuggerDisplay("Name: {FullName}")] +public class Person +{ + public string FullName { get; private set; } +} +---- ifdef::env-github,rspecator-view[] diff --git a/rules/S4545/highlighting.adoc b/rules/S4545/highlighting.adoc index 4eb62825db9..a13e737601c 100644 --- a/rules/S4545/highlighting.adoc +++ b/rules/S4545/highlighting.adoc @@ -1,4 +1,4 @@ === Highlighting -text between curly braces +format string parameter of the ``DebuggerDisplayAttribute`` diff --git a/rules/S4545/message.adoc b/rules/S4545/message.adoc index 38d16d65e3b..6a8fa140f1f 100644 --- a/rules/S4545/message.adoc +++ b/rules/S4545/message.adoc @@ -1,4 +1,4 @@ === Message -Fix the name between the curly braces so that it matches a field, property or method of this object +Fix the name between the curly braces so that it matches a field or property of this object diff --git a/rules/S4545/rule.adoc b/rules/S4545/rule.adoc deleted file mode 100644 index be32fcbb45d..00000000000 --- a/rules/S4545/rule.adoc +++ /dev/null @@ -1,10 +0,0 @@ -The ``++DebuggerDisplayAttribute++`` is used to determine how an object is displayed in the debugger window. - - -The ``++DebuggerDisplayAttribute++`` constructor takes a single argument: the string to be displayed in the value column for instances of the type. Any text within curly braces is evaluated as the name of a field, property, or method. - - -Naming a non-existent field, property or method between curly braces will result in an error in the debug window when debugging objects. Although there is no impact on the production code, providing a wrong value can lead to difficulties when debugging the application. - - -This rule raises an issue when text specified between curly braces refers to members that don't exist in the current context. diff --git a/rules/S4545/vbnet/rule-except-see.adoc b/rules/S4545/vbnet/rule-except-see.adoc deleted file mode 100644 index 85a2aef69c3..00000000000 --- a/rules/S4545/vbnet/rule-except-see.adoc +++ /dev/null @@ -1,37 +0,0 @@ -The ``++DebuggerDisplayAttribute++`` is used to determine how an object is displayed in the debugger window. - - -The ``++DebuggerDisplayAttribute++`` constructor takes a single argument: the string to be displayed in the value column for instances of the type. Any text within curly braces is evaluated as the name of a field, property, or method. - - -Naming a non-existent field, property or method between curly braces will result in a BC30451 error in the debug window when debugging objects. Although there is no impact on the production code, providing a wrong value can lead to difficulties when debugging the application. - - -This rule raises an issue when text specified between curly braces refers to members that don't exist in the current context. - - -== Noncompliant Code Example - -[source,vbnet] ----- - ' Noncompliant - Name doesn't exist in this context -Public Class Person - - Public Property FullName As String - -End Class ----- - - -== Compliant Solution - -[source,vbnet] ----- - -Public Class Person - - Public Property FullName As String - -End Class ----- - diff --git a/rules/S4545/vbnet/rule.adoc b/rules/S4545/vbnet/rule.adoc index 8901619c83d..37c224a653b 100644 --- a/rules/S4545/vbnet/rule.adoc +++ b/rules/S4545/vbnet/rule.adoc @@ -1,4 +1,39 @@ -include::rule-except-see.adoc[] +The ``DebuggerDisplayAttribute`` is used to determine how an object is displayed in the debugger window. + + +The ``DebuggerDisplayAttribute`` constructor takes a single mandatory argument: the string to be displayed in the value column for instances of the type. Any text within curly braces is evaluated as the name of member, or any complex expression converted to a string value, containing method calls and operators. + + +Naming a non-existent member between curly braces will result in a BC30451 error in the debug window when debugging objects. Although there is no impact on the production code, providing a wrong value can lead to difficulties when debugging the application. + + +This rule raises an issue when text specified between curly braces refers to members that don't exist in the current context. + + +== Noncompliant Code Example + +[source,vbnet] +---- + ' Noncompliant - Name doesn't exist in this context +Public Class Person + + Public Property FullName As String + +End Class +---- + + +== Compliant Solution + +[source,vbnet] +---- + +Public Class Person + + Public Property FullName As String + +End Class +---- ifdef::env-github,rspecator-view[] From 1cf3bad1324f1a5abd5e42d5ccdb983ebd16a7fe Mon Sep 17 00:00:00 2001 From: Antonio Aversa Date: Mon, 27 Feb 2023 18:26:30 +0100 Subject: [PATCH 3/4] Review 2 --- rules/S4545/csharp/rule.adoc | 4 ++-- rules/S4545/highlighting.adoc | 2 +- rules/S4545/message.adoc | 2 +- rules/S4545/vbnet/rule.adoc | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rules/S4545/csharp/rule.adoc b/rules/S4545/csharp/rule.adoc index 4ee3f535256..1bda8518ee6 100644 --- a/rules/S4545/csharp/rule.adoc +++ b/rules/S4545/csharp/rule.adoc @@ -1,7 +1,7 @@ -The ``DebuggerDisplayAttribute`` is used to determine how an object is displayed in the debugger window. +The `DebuggerDisplayAttribute` is used to determine how an object is displayed in the debugger window. -The ``DebuggerDisplayAttribute`` constructor takes a single mandatory argument: the string to be displayed in the value column for instances of the type. Any text within curly braces is evaluated as the name of a member, or any complex expression converted to a string value, containing method calls and operators. +The `DebuggerDisplayAttribute` constructor takes a single mandatory argument: the string to be displayed in the value column for instances of the type. Any text within curly braces is evaluated as the name of a field, property, or method, or any complex expression containing method calls and operators. Naming a non-existent member between curly braces will result in a CS0103 error in the debug window when debugging objects. Although there is no impact on the production code, providing a wrong value can lead to difficulties when debugging the application. diff --git a/rules/S4545/highlighting.adoc b/rules/S4545/highlighting.adoc index a13e737601c..2ef73ed3b18 100644 --- a/rules/S4545/highlighting.adoc +++ b/rules/S4545/highlighting.adoc @@ -1,4 +1,4 @@ === Highlighting -format string parameter of the ``DebuggerDisplayAttribute`` +format string parameter of the `DebuggerDisplayAttribute` diff --git a/rules/S4545/message.adoc b/rules/S4545/message.adoc index 6a8fa140f1f..38d16d65e3b 100644 --- a/rules/S4545/message.adoc +++ b/rules/S4545/message.adoc @@ -1,4 +1,4 @@ === Message -Fix the name between the curly braces so that it matches a field or property of this object +Fix the name between the curly braces so that it matches a field, property or method of this object diff --git a/rules/S4545/vbnet/rule.adoc b/rules/S4545/vbnet/rule.adoc index 37c224a653b..385edcd9800 100644 --- a/rules/S4545/vbnet/rule.adoc +++ b/rules/S4545/vbnet/rule.adoc @@ -1,7 +1,7 @@ -The ``DebuggerDisplayAttribute`` is used to determine how an object is displayed in the debugger window. +The `DebuggerDisplayAttribute` is used to determine how an object is displayed in the debugger window. -The ``DebuggerDisplayAttribute`` constructor takes a single mandatory argument: the string to be displayed in the value column for instances of the type. Any text within curly braces is evaluated as the name of member, or any complex expression converted to a string value, containing method calls and operators. +The `DebuggerDisplayAttribute` constructor takes a single mandatory argument: the string to be displayed in the value column for instances of the type. Any text within curly braces is evaluated as the name of a field, property, or method, or any complex expression containing method calls and operators. Naming a non-existent member between curly braces will result in a BC30451 error in the debug window when debugging objects. Although there is no impact on the production code, providing a wrong value can lead to difficulties when debugging the application. From e0ca67e1e2b6456be9074815f0bd3d4ed815d0f1 Mon Sep 17 00:00:00 2001 From: Antonio Aversa Date: Mon, 27 Feb 2023 18:37:15 +0100 Subject: [PATCH 4/4] Remove method (again), since it breaks debugger evaluation of the format string --- rules/S4545/csharp/rule.adoc | 2 +- rules/S4545/message.adoc | 2 +- rules/S4545/vbnet/rule.adoc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rules/S4545/csharp/rule.adoc b/rules/S4545/csharp/rule.adoc index 1bda8518ee6..a5fabcdc209 100644 --- a/rules/S4545/csharp/rule.adoc +++ b/rules/S4545/csharp/rule.adoc @@ -1,7 +1,7 @@ The `DebuggerDisplayAttribute` is used to determine how an object is displayed in the debugger window. -The `DebuggerDisplayAttribute` constructor takes a single mandatory argument: the string to be displayed in the value column for instances of the type. Any text within curly braces is evaluated as the name of a field, property, or method, or any complex expression containing method calls and operators. +The `DebuggerDisplayAttribute` constructor takes a single mandatory argument: the string to be displayed in the value column for instances of the type. Any text within curly braces is evaluated as the name of a field or property, or any complex expression containing method calls and operators. Naming a non-existent member between curly braces will result in a CS0103 error in the debug window when debugging objects. Although there is no impact on the production code, providing a wrong value can lead to difficulties when debugging the application. diff --git a/rules/S4545/message.adoc b/rules/S4545/message.adoc index 38d16d65e3b..6a8fa140f1f 100644 --- a/rules/S4545/message.adoc +++ b/rules/S4545/message.adoc @@ -1,4 +1,4 @@ === Message -Fix the name between the curly braces so that it matches a field, property or method of this object +Fix the name between the curly braces so that it matches a field or property of this object diff --git a/rules/S4545/vbnet/rule.adoc b/rules/S4545/vbnet/rule.adoc index 385edcd9800..e8a46f4b2d9 100644 --- a/rules/S4545/vbnet/rule.adoc +++ b/rules/S4545/vbnet/rule.adoc @@ -1,7 +1,7 @@ The `DebuggerDisplayAttribute` is used to determine how an object is displayed in the debugger window. -The `DebuggerDisplayAttribute` constructor takes a single mandatory argument: the string to be displayed in the value column for instances of the type. Any text within curly braces is evaluated as the name of a field, property, or method, or any complex expression containing method calls and operators. +The `DebuggerDisplayAttribute` constructor takes a single mandatory argument: the string to be displayed in the value column for instances of the type. Any text within curly braces is evaluated as the name of a field or property, or any complex expression containing method calls and operators. Naming a non-existent member between curly braces will result in a BC30451 error in the debug window when debugging objects. Although there is no impact on the production code, providing a wrong value can lead to difficulties when debugging the application.