From a117458bd2c0126292beb3aca4779605edd2c5a1 Mon Sep 17 00:00:00 2001 From: leonardo-pilastri-sonarsource <115481625+leonardo-pilastri-sonarsource@users.noreply.github.com> Date: Wed, 11 Oct 2023 11:41:24 +0200 Subject: [PATCH] Modify S1192: Migrate to LayC (#3234) --- rules/S1192/abap/rule.adoc | 18 +++------ rules/S1192/apex/rule.adoc | 25 +++++++------ rules/S1192/cobol/rule.adoc | 31 ++++++++-------- rules/S1192/comments-and-links.adoc | 11 ------ rules/S1192/csharp/rule.adoc | 40 +++++++++----------- rules/S1192/description.adoc | 4 +- rules/S1192/exceptions.adoc | 2 - rules/S1192/go/rule.adoc | 26 +++++++------ rules/S1192/howtofix.adoc | 2 + rules/S1192/java/rule.adoc | 23 ++++-------- rules/S1192/javascript/rule.adoc | 44 +++++++++++++++++++--- rules/S1192/kotlin/rule.adoc | 25 +++++++------ rules/S1192/php/rule.adoc | 37 +++++++++---------- rules/S1192/plsql/rule.adoc | 25 +++++-------- rules/S1192/python/rule.adoc | 57 +++++++++++++++-------------- rules/S1192/rpg/rule.adoc | 21 ++++------- rules/S1192/ruby/rule.adoc | 33 +++++++++-------- rules/S1192/rule.adoc | 6 +++ rules/S1192/scala/rule.adoc | 33 +++++++++-------- rules/S1192/swift/rule.adoc | 26 +++++++------ rules/S1192/tsql/rule.adoc | 18 +++------ rules/S1192/vbnet/rule.adoc | 34 +++++++++-------- 22 files changed, 277 insertions(+), 264 deletions(-) delete mode 100644 rules/S1192/comments-and-links.adoc create mode 100644 rules/S1192/howtofix.adoc diff --git a/rules/S1192/abap/rule.adoc b/rules/S1192/abap/rule.adoc index 1e282443746..e1512197622 100644 --- a/rules/S1192/abap/rule.adoc +++ b/rules/S1192/abap/rule.adoc @@ -1,12 +1,12 @@ -== Why is this an issue? +include::../rule.adoc[] -include::../description.adoc[] +=== Code examples -=== Noncompliant code example +==== Noncompliant code example With the default threshold of 3: -[source,abap] +[source,abap,diff-id=1,diff-type=noncompliant] ---- WRITE: / 'Firstname'. *... @@ -15,9 +15,9 @@ WRITE: / 'Firstname'. WRITE: / 'Firstname'. ---- -=== Compliant solution +==== Compliant solution -[source,abap] +[source,abap,diff-id=1,diff-type=compliant] ---- CONSTANTS: fname TYPE c LENGTH 9 VALUE 'Firstname', @@ -28,8 +28,6 @@ WRITE: / fname. WRITE: / fname. ---- -include::../exceptions.adoc[] - ifdef::env-github,rspecator-view[] ''' @@ -43,9 +41,5 @@ include::../parameters.adoc[] include::../highlighting.adoc[] ''' -== Comments And Links -(visible only on this page) - -include::../comments-and-links.adoc[] endif::env-github,rspecator-view[] diff --git a/rules/S1192/apex/rule.adoc b/rules/S1192/apex/rule.adoc index b5d09442032..9b23010784c 100644 --- a/rules/S1192/apex/rule.adoc +++ b/rules/S1192/apex/rule.adoc @@ -2,9 +2,19 @@ include::../description.adoc[] -=== Noncompliant code example +=== Exceptions + +To prevent generating some false-positives, literals having 5 or less characters are excluded as well as literals containing only letters, digits and '_'. + +== How to fix it + +include::../howtofix.adoc[] + +=== Code examples -[source,apex] +==== Noncompliant code example + +[source,apex,diff-id=1,diff-type=noncompliant] ---- class A { void doSomething(String msg) { @@ -21,9 +31,9 @@ class A { } ---- -=== Compliant solution +==== Compliant solution -[source,apex] +[source,apex,diff-id=1,diff-type=compliant] ---- class A { static final String STRING_CONST = 'string literal'; @@ -36,9 +46,6 @@ class A { } ---- -=== Exceptions - -To prevent generating some false-positives, literals having 5 or less characters are excluded as well as literals containing only letters, digits and '_'. ifdef::env-github,rspecator-view[] @@ -53,9 +60,5 @@ include::../parameters.adoc[] include::../highlighting.adoc[] ''' -== Comments And Links -(visible only on this page) - -include::../comments-and-links.adoc[] endif::env-github,rspecator-view[] diff --git a/rules/S1192/cobol/rule.adoc b/rules/S1192/cobol/rule.adoc index bae1eacbb17..ad96d6ad95f 100644 --- a/rules/S1192/cobol/rule.adoc +++ b/rules/S1192/cobol/rule.adoc @@ -2,11 +2,23 @@ include::../description.adoc[] -=== Noncompliant code example +=== Exceptions + +Literals with fewer than 7 characters are ignored. + +Only duplications located in a `PROCEDURE DIVISION`, not those contained in copybooks are reported. + +== How to fix it + +include::../howtofix.adoc[] + +=== Code examples + +==== Noncompliant code example With the default threshold of 3: -[source,cobol] +[source,cobol,diff-id=1,diff-type=noncompliant] ---- PROCEDURE DIVISION. @@ -17,9 +29,9 @@ With the default threshold of 3: DISPLAY "Firstname: ". ---- -=== Compliant solution +==== Compliant solution -[source,cobol] +[source,cobol,diff-id=1,diff-type=compliant] ---- WORKING-STORAGE SECTION. 01 FIRST-NAME-HEADER PIC X(42) VALUE "Firstname: ". @@ -32,13 +44,6 @@ With the default threshold of 3: DISPLAY FIRST-NAME-HEADER ---- -=== Exceptions - -Literals with fewer than 7 characters are ignored. - - -Only duplications located in a ``++PROCEDURE DIVISION++``, not those contained in copybooks are reported. - ifdef::env-github,rspecator-view[] ''' @@ -52,9 +57,5 @@ include::../parameters.adoc[] include::../highlighting.adoc[] ''' -== Comments And Links -(visible only on this page) - -include::../comments-and-links.adoc[] endif::env-github,rspecator-view[] diff --git a/rules/S1192/comments-and-links.adoc b/rules/S1192/comments-and-links.adoc deleted file mode 100644 index 2d2e16ad1a2..00000000000 --- a/rules/S1192/comments-and-links.adoc +++ /dev/null @@ -1,11 +0,0 @@ -=== on 16 Aug 2013, 08:13:35 Freddy Mallet wrote: -Is implemented by \http://jira.codehaus.org/browse/SONARJAVA-291 - -=== on 13 Jan 2014, 14:29:46 Dinesh Bolkensteyn wrote: -For COBOL, this rule should apply only to literals contained with tine PROCEDURE DIVISION. - -Moreover, occurences coming from copybooks should be excluded. - -=== on 12 Feb 2014, 21:06:34 Freddy Mallet wrote: -Is implemented by \http://jira.codehaus.org/browse/SONARPLUGINS-3460 for PHP - diff --git a/rules/S1192/csharp/rule.adoc b/rules/S1192/csharp/rule.adoc index df7ad62f85e..4fc631f1d49 100644 --- a/rules/S1192/csharp/rule.adoc +++ b/rules/S1192/csharp/rule.adoc @@ -2,9 +2,23 @@ include::../description.adoc[] -=== Noncompliant code example +=== Exceptions + +The following are ignored: + +* literals with fewer than 5 characters +* literals matching one of the parameter names +* literals used in attributes + +== How to fix it + +include::../howtofix.adoc[] -[source,csharp] +=== Code examples + +==== Noncompliant code example + +[source,csharp,diff-id=1,diff-type=noncompliant] ---- public class Foo { @@ -19,9 +33,9 @@ public class Foo } ---- -=== Compliant solution +==== Compliant solution -[source,csharp] +[source,csharp,diff-id=1,diff-type=compliant] ---- public class Foo { @@ -38,14 +52,6 @@ public class Foo } ---- -=== Exceptions - -The following are ignored: - -* literals with fewer than 5 characters -* literals matching one of the parameter names -* literals used in attributes - ifdef::env-github,rspecator-view[] ''' @@ -67,15 +73,5 @@ secondaries: all instances of the string literal ''' -== Comments And Links -(visible only on this page) - -=== on 21 Mar 2018, 15:11:26 Amaury Levé wrote: -Could you review this sub-task please? - -=== on 21 Mar 2018, 15:33:08 Ann Campbell wrote: -I think a brief code example would be helpful for the second item, [~amaury.leve]. - -include::../comments-and-links.adoc[] endif::env-github,rspecator-view[] diff --git a/rules/S1192/description.adoc b/rules/S1192/description.adoc index 0a22d7904d9..5a35ca07442 100644 --- a/rules/S1192/description.adoc +++ b/rules/S1192/description.adoc @@ -1,3 +1 @@ -Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences. - -On the other hand, constants can be referenced from many places, but only need to be updated in a single place. +Duplicated string literals make the process of refactoring complex and error-prone, as any change would need to be propagated on all occurrences. diff --git a/rules/S1192/exceptions.adoc b/rules/S1192/exceptions.adoc index af62d3ff312..28af36eb982 100644 --- a/rules/S1192/exceptions.adoc +++ b/rules/S1192/exceptions.adoc @@ -1,3 +1 @@ -=== Exceptions - To prevent generating some false-positives, literals having less than 5 characters are excluded. diff --git a/rules/S1192/go/rule.adoc b/rules/S1192/go/rule.adoc index 77366c44d7c..423d74d8bbf 100644 --- a/rules/S1192/go/rule.adoc +++ b/rules/S1192/go/rule.adoc @@ -2,11 +2,21 @@ include::../description.adoc[] -=== Noncompliant code example +=== Exceptions + +To prevent generating some false-positives, literals having 5 or less characters are excluded as well as literals containing only letters, digits and '_'. + +== How to fix it + +include::../howtofix.adoc[] + +=== Code examples + +==== Noncompliant code example With the default threshold of 3: -[source,go] +[source,go,diff-id=1,diff-type=noncompliant] ---- func run() { prepare("This should be a constant") // Noncompliant; 'This should ...' is duplicated 3 times @@ -15,9 +25,9 @@ func run() { } ---- -=== Compliant solution +==== Compliant solution -[source,go] +[source,go,diff-id=1,diff-type=compliant] ---- const ACTION = "This should be a constant" @@ -28,10 +38,6 @@ func run() { } ---- -=== Exceptions - -To prevent generating some false-positives, literals having 5 or less characters are excluded as well as literals containing only letters, digits and '_'. - ifdef::env-github,rspecator-view[] ''' @@ -45,9 +51,5 @@ include::../parameters.adoc[] include::../highlighting.adoc[] ''' -== Comments And Links -(visible only on this page) - -include::../comments-and-links.adoc[] endif::env-github,rspecator-view[] diff --git a/rules/S1192/howtofix.adoc b/rules/S1192/howtofix.adoc new file mode 100644 index 00000000000..e12dfc2ca33 --- /dev/null +++ b/rules/S1192/howtofix.adoc @@ -0,0 +1,2 @@ +Instead, use constants to replace the duplicated string literals. +Constants can be referenced from many places, but only need to be updated in a single place. \ No newline at end of file diff --git a/rules/S1192/java/rule.adoc b/rules/S1192/java/rule.adoc index 4b4a6c83990..69d0aca53c0 100644 --- a/rules/S1192/java/rule.adoc +++ b/rules/S1192/java/rule.adoc @@ -1,12 +1,12 @@ -== Why is this an issue? +include::../rule.adoc[] -include::../description.adoc[] +=== Code examples -=== Noncompliant code example +==== Noncompliant code example With the default threshold of 3: -[source,java] +[source,java,diff-id=1,diff-type=noncompliant] ---- public void run() { prepare("action1"); // Noncompliant - "action1" is duplicated 3 times @@ -19,15 +19,14 @@ private void method1() { /* ... */ } @SuppressWarning("all") private void method2() { /* ... */ } -public String method3(String a) { - System.out.println("'" + a + "'"); // Compliant - literal "'" has less than 5 characters and is excluded - return ""; // Compliant - literal "" has less than 5 characters and is excluded +public String printInQuotes(String a, String b) { + return "'" + a + "'" + b + "'"; // Compliant - literal "'" has less than 5 characters and is excluded } ---- -=== Compliant solution +==== Compliant solution -[source,java] +[source,java,diff-id=1,diff-type=compliant] ---- private static final String ACTION_1 = "action1"; // Compliant @@ -38,8 +37,6 @@ public void run() { } ---- -include::../exceptions.adoc[] - ifdef::env-github,rspecator-view[] ''' @@ -53,9 +50,5 @@ include::../parameters.adoc[] include::../highlighting.adoc[] ''' -== Comments And Links -(visible only on this page) - -include::../comments-and-links.adoc[] endif::env-github,rspecator-view[] diff --git a/rules/S1192/javascript/rule.adoc b/rules/S1192/javascript/rule.adoc index c431fdc7b31..d0991abdc7f 100644 --- a/rules/S1192/javascript/rule.adoc +++ b/rules/S1192/javascript/rule.adoc @@ -4,7 +4,45 @@ include::../description.adoc[] === Exceptions -To prevent generating some false-positives, literals having less than 10 characters are excluded as well as literals matching ``++/^\w*$/++``. String literals inside import/export statements and JSX attributes are also ignored. The same goes for statement-like string literals, e.g. ``++'use strict';++``. +To prevent generating some false-positives, literals having less than 10 characters are excluded as well as literals matching `/^\w*$/`. +String literals inside import/export statements and JSX attributes are also ignored. +The same goes for statement-like string literals, e.g. `'use strict';`. + +== How to fix it + +include::../howtofix.adoc[] + +=== Code examples + +==== Noncompliant code example + +With the default threshold of 3: + +[source,javascript,diff-id=1,diff-type=noncompliant] +---- +function run() { + prepare("action_to_launch"); // Noncompliant - "action_to_launch" is duplicated 3 times + execute("action_to_launch"); + release("action_to_launch"); +} + +function printInQuotes(a, b) { + console.log("'" + a + "'" + b + "'"); // Compliant - literal "'" has less than 10 characters and is excluded +} +---- + +==== Compliant solution + +[source,javascript,diff-id=1,diff-type=compliant] +---- +var ACTION_1 = "action_to_launch"; + +function run() { + prepare(ACTION_1); // Compliant + execute(ACTION_1); + release(ACTION_1); +} +---- ifdef::env-github,rspecator-view[] @@ -19,9 +57,5 @@ include::../parameters.adoc[] include::../highlighting.adoc[] ''' -== Comments And Links -(visible only on this page) - -include::../comments-and-links.adoc[] endif::env-github,rspecator-view[] diff --git a/rules/S1192/kotlin/rule.adoc b/rules/S1192/kotlin/rule.adoc index cda4c35384c..3b687c90e35 100644 --- a/rules/S1192/kotlin/rule.adoc +++ b/rules/S1192/kotlin/rule.adoc @@ -2,11 +2,21 @@ include::../description.adoc[] -=== Noncompliant code example +=== Exceptions + +To prevent generating some false-positives, literals having 5 or less characters are excluded as well as literals containing only letters, digits and '_'. + +== How to fix it + +include::../howtofix.adoc[] + +=== Code examples + +==== Noncompliant code example With the default threshold of 3: -[source,kotlin] +[source,kotlin,diff-id=1,diff-type=noncompliant] ---- class A { fun run() { @@ -23,9 +33,9 @@ class A { } ---- -=== Compliant solution +==== Compliant solution -[source,kotlin] +[source,kotlin,diff-id=1,diff-type=compliant] ---- class A { companion object { @@ -40,10 +50,6 @@ class A { } ---- -=== Exceptions - -To prevent generating some false-positives, literals having 5 or less characters are excluded as well as literals containing only letters, digits and '_'. - ifdef::env-github,rspecator-view[] ''' @@ -57,9 +63,6 @@ include::../parameters.adoc[] include::../highlighting.adoc[] ''' -== Comments And Links -(visible only on this page) -include::../comments-and-links.adoc[] endif::env-github,rspecator-view[] diff --git a/rules/S1192/php/rule.adoc b/rules/S1192/php/rule.adoc index 25e85b0cacd..8dd6296a735 100644 --- a/rules/S1192/php/rule.adoc +++ b/rules/S1192/php/rule.adoc @@ -2,11 +2,24 @@ include::../description.adoc[] -=== Noncompliant code example +=== Exceptions + +No issue will be raised on: + +* strings with less than 5 characters +* strings with only letters, numbers, underscores, hyphens and periods + +== How to fix it + +include::../howtofix.adoc[] + +=== Code examples + +==== Noncompliant code example With the default threshold of 3: -[source,php] +[source,php,diff-id=1,diff-type=noncompliant] ---- function run() { prepare('this is a duplicate'); // Noncompliant - 'this is a duplicate' is duplicated 3 times @@ -15,26 +28,19 @@ function run() { } ---- -=== Compliant solution +==== Compliant solution -[source,php] +[source,php,diff-id=1,diff-type=compliant] ---- MESSAGE = 'this is a duplicate'; function run() { - prepare(MESSAGE); + prepare(MESSAGE); // Compliant - the duplicated string literal is replaced by a constant and can be safely re-used execute(MESSAGE); release(MESSAGE); } ---- -=== Exceptions - -No issue will be raised on: - -* strings with less than 5 characters -* strings with only letters, numbers, underscores, hyphens and periods - [source,php] ---- $severity = $request->getParam('severity-score'); @@ -53,12 +59,5 @@ include::../parameters.adoc[] include::../highlighting.adoc[] ''' -== Comments And Links -(visible only on this page) - -=== on 30 Jun 2020, 16:03:21 Ann Campbell wrote: -\[~nils.werner] "strings must start with a letter" doesn't make sense to me as an exception. - -include::../comments-and-links.adoc[] endif::env-github,rspecator-view[] diff --git a/rules/S1192/plsql/rule.adoc b/rules/S1192/plsql/rule.adoc index 12de32eadf5..976ec2d16e6 100644 --- a/rules/S1192/plsql/rule.adoc +++ b/rules/S1192/plsql/rule.adoc @@ -1,12 +1,12 @@ -== Why is this an issue? +include::../rule.adoc[] -include::../description.adoc[] +=== Code examples -=== Noncompliant code example +==== Noncompliant code example With the default threshold of 3: -[source,sql] +[source,sql,diff-id=1,diff-type=noncompliant] ---- BEGIN prepare('action1'); @@ -16,22 +16,20 @@ END; / ---- -=== Compliant solution +==== Compliant solution -[source,sql] +[source,sql,diff-id=1,diff-type=compliant] ---- DECLARE - action CONSTANT VARCHAR2(7) := 'action1'; + co_action CONSTANT VARCHAR2(7) := 'action1'; BEGIN - prepare(action); - execute(action); - release(action); + prepare(co_action); + execute(co_action); + release(co_action); END; / ---- -include::../exceptions.adoc[] - ifdef::env-github,rspecator-view[] ''' @@ -45,9 +43,6 @@ include::../parameters.adoc[] include::../highlighting.adoc[] ''' -== Comments And Links -(visible only on this page) -include::../comments-and-links.adoc[] endif::env-github,rspecator-view[] diff --git a/rules/S1192/python/rule.adoc b/rules/S1192/python/rule.adoc index 77e5e5010b5..8938b38d5d3 100644 --- a/rules/S1192/python/rule.adoc +++ b/rules/S1192/python/rule.adoc @@ -2,49 +2,53 @@ include::../description.adoc[] -=== Noncompliant code example +=== Exceptions -With the default threshold of 3: +No issue will be raised on: -[source,python] ----- -def run(): - prepare("this is a duplicate") # Noncompliant - "this is a duplicate" is duplicated 3 times - execute("this is a duplicate") - release("this is a duplicate") ----- +* duplicated string in decorators +* strings with less than 5 characters +* strings with only letters, numbers and underscores -=== Compliant solution -[source,python] ----- -ACTION_1 = "action1" +== How to fix it -def run(): - prepare(ACTION_1) - execute(ACTION_1) - release(ACTION_1) ----- +include::../howtofix.adoc[] -=== Exceptions +=== Code examples -No issue will be raised on: +==== Noncompliant code example -* duplicated string in decorators -* strings with less than 5 characters -* strings with only letters, numbers and underscores +With the default threshold of 3: -[source,python] +[source,python,diff-id=1,diff-type=noncompliant] ---- +def run(): + prepare("action1") # Noncompliant - "action1" is duplicated 3 times + execute("action1") + release("action1") + @app.route("/api/users/", methods=['GET', 'POST', 'PUT']) def users(): pass -@app.route("/api/projects/", methods=['GET', 'POST', 'PUT']) # Compliant +@app.route("/api/projects/", methods=['GET', 'POST', 'PUT']) # Compliant - strings inside decorators are ignored def projects(): pass ---- +==== Compliant solution + +[source,python,diff-id=1,diff-type=compliant] +---- +ACTION_1 = "action1" + +def run(): + prepare(ACTION_1) + execute(ACTION_1) + release(ACTION_1) +---- + ifdef::env-github,rspecator-view[] ''' @@ -58,9 +62,6 @@ include::../parameters.adoc[] include::../highlighting.adoc[] ''' -== Comments And Links -(visible only on this page) -include::../comments-and-links.adoc[] endif::env-github,rspecator-view[] diff --git a/rules/S1192/rpg/rule.adoc b/rules/S1192/rpg/rule.adoc index c7e491d0b3a..143f9c238bf 100644 --- a/rules/S1192/rpg/rule.adoc +++ b/rules/S1192/rpg/rule.adoc @@ -1,12 +1,12 @@ -== Why is this an issue? +include::../rule.adoc[] -include::../description.adoc[] +=== Code examples -=== Noncompliant code example +==== Noncompliant code example With the default threshold of 3: -[source,rpg] +[source,rpg,diff-id=1,diff-type=noncompliant] ---- C MOVEL 'CLEAR' W1CLR Noncompliant C MOVEL '*DECOD' W1DCDE @@ -16,7 +16,7 @@ C MOVEL 'CLEAR' W1FIRT C MOVEL 'CLEAR' W1HELP ---- -[source,rpg] +[source,rpg,diff-id=2,diff-type=noncompliant] ---- /free W1CLR = 'CLEAR'; // Noncompliant @@ -25,9 +25,9 @@ C MOVEL 'CLEAR' W1HELP /end-free ---- -=== Compliant solution +==== Compliant solution -[source,rpg] +[source,rpg,diff-id=1,diff-type=compliant] ---- D W0Clr C CONST('CLEAR') C MOVEL W0Clr W1CLR @@ -38,7 +38,7 @@ C MOVEL W0Clr W1FIRT C MOVEL W0Clr W1HELP ---- -[source,rpg] +[source,rpg,diff-id=2,diff-type=compliant] ---- D W0Clr C CONST('CLEAR') /free @@ -48,8 +48,6 @@ D W0Clr C CONST('CLEAR') /end-free ---- -include::../exceptions.adoc[] - ifdef::env-github,rspecator-view[] ''' @@ -63,9 +61,6 @@ include::../parameters.adoc[] include::../highlighting.adoc[] ''' -== Comments And Links -(visible only on this page) -include::../comments-and-links.adoc[] endif::env-github,rspecator-view[] diff --git a/rules/S1192/ruby/rule.adoc b/rules/S1192/ruby/rule.adoc index 8e9a43f096c..c75c1b5e200 100644 --- a/rules/S1192/ruby/rule.adoc +++ b/rules/S1192/ruby/rule.adoc @@ -2,11 +2,21 @@ include::../description.adoc[] -=== Noncompliant code example +=== Exceptions + +To prevent generating some false-positives, literals having 5 or less characters are excluded as well as literals containing only letters, digits and '_'. + +== How to fix it + +include::../howtofix.adoc[] + +=== Code examples + +==== Noncompliant code example With the default threshold of 3: -[source,ruby] +[source,ruby,diff-id=1,diff-type=noncompliant] ---- def foo() prepare('action random1') #Noncompliant - "action random1" is duplicated 3 times @@ -15,22 +25,18 @@ def foo() end ---- -=== Compliant solution +==== Compliant solution -[source,ruby] +[source,ruby,diff-id=1,diff-type=compliant] ---- def foo() - action1 = 'action random1' - prepare(action1) - execute(action1) - release(action1) + ACTION1 = 'action random1' + prepare(ACTION1) + execute(ACTION1) + release(ACTION1) end ---- -=== Exceptions - -To prevent generating some false-positives, literals having 5 or less characters are excluded as well as literals containing only letters, digits and '_'. - ifdef::env-github,rspecator-view[] ''' @@ -44,9 +50,6 @@ include::../parameters.adoc[] include::../highlighting.adoc[] ''' -== Comments And Links -(visible only on this page) -include::../comments-and-links.adoc[] endif::env-github,rspecator-view[] diff --git a/rules/S1192/rule.adoc b/rules/S1192/rule.adoc index 3ccc2919f2d..dade3ed62eb 100644 --- a/rules/S1192/rule.adoc +++ b/rules/S1192/rule.adoc @@ -2,4 +2,10 @@ include::description.adoc[] +=== Exceptions + include::exceptions.adoc[] + +== How to fix it + +include::howtofix.adoc[] diff --git a/rules/S1192/scala/rule.adoc b/rules/S1192/scala/rule.adoc index 3ad22cf22b3..a2558b5e52e 100644 --- a/rules/S1192/scala/rule.adoc +++ b/rules/S1192/scala/rule.adoc @@ -2,11 +2,21 @@ include::../description.adoc[] -=== Noncompliant code example +=== Exceptions + +To prevent generating some false-positives, literals having 5 or less characters are excluded as well as literals containing only letters, digits and '_'. + +== How to fix it + +include::../howtofix.adoc[] + +=== Code examples + +==== Noncompliant code example With the default threshold of 3: -[source,scala] +[source,scala,diff-id=1,diff-type=noncompliant] ---- public def run() { prepare("action random1") // Noncompliant - "action random1" is duplicated 3 times @@ -15,22 +25,18 @@ public def run() { } ---- -=== Compliant solution +==== Compliant solution -[source,scala] +[source,scala,diff-id=1,diff-type=compliant] ---- public def run() { - val action = "action random1" - prepare(action) - execute(action) - release(action) + val Action = "action random1" + prepare(Action) + execute(Action) + release(Action) } ---- -=== Exceptions - -To prevent generating some false-positives, literals having 5 or less characters are excluded as well as literals containing only letters, digits and '_'. - ifdef::env-github,rspecator-view[] ''' @@ -44,9 +50,6 @@ include::../parameters.adoc[] include::../highlighting.adoc[] ''' -== Comments And Links -(visible only on this page) -include::../comments-and-links.adoc[] endif::env-github,rspecator-view[] diff --git a/rules/S1192/swift/rule.adoc b/rules/S1192/swift/rule.adoc index 33f2efdc827..3b084c21e97 100644 --- a/rules/S1192/swift/rule.adoc +++ b/rules/S1192/swift/rule.adoc @@ -2,20 +2,30 @@ include::../description.adoc[] -=== Noncompliant code example +=== Exceptions + +To prevent generating some false-positives, literals having 5 or less characters are excluded as well as literals containing only letters, digits and '_'. + +== How to fix it + +include::../howtofix.adoc[] + +=== Code examples + +==== Noncompliant code example With the default threshold of 3: -[source,swift] +[source,swift,diff-id=1,diff-type=noncompliant] ---- prepare("a message") // Noncompliant; duplicated 3 times execute("a message") release("a message") ---- -=== Compliant solution +==== Compliant solution -[source,swift] +[source,swift,diff-id=1,diff-type=compliant] ---- let message = "a message" @@ -24,10 +34,6 @@ execute(message) release(message) ---- -=== Exceptions - -To prevent generating some false-positives, literals having 5 or less characters are excluded as well as literals containing only letters, digits and '_'. - ifdef::env-github,rspecator-view[] ''' @@ -41,9 +47,5 @@ include::../parameters.adoc[] include::../highlighting.adoc[] ''' -== Comments And Links -(visible only on this page) - -include::../comments-and-links.adoc[] endif::env-github,rspecator-view[] diff --git a/rules/S1192/tsql/rule.adoc b/rules/S1192/tsql/rule.adoc index ce74d471502..7de2681fddb 100644 --- a/rules/S1192/tsql/rule.adoc +++ b/rules/S1192/tsql/rule.adoc @@ -1,12 +1,12 @@ -== Why is this an issue? +include::../rule.adoc[] -include::../description.adoc[] +=== Code examples -=== Noncompliant code example +==== Noncompliant code example With the default threshold of 3: -[source,sql] +[source,sql,diff-id=1,diff-type=noncompliant] ---- IF @x='Yes' SELECT ... @@ -18,9 +18,9 @@ IF @x='Yes' ... ---- -=== Compliant solution +==== Compliant solution -[source,sql] +[source,sql,diff-id=1,diff-type=compliant] ---- DECLARE @Yes VARCHAR(3) = 'Yes' IF @x=@Yes @@ -33,8 +33,6 @@ IF @x=@Yes ... ---- -include::../exceptions.adoc[] - ifdef::env-github,rspecator-view[] ''' @@ -48,9 +46,5 @@ include::../parameters.adoc[] include::../highlighting.adoc[] ''' -== Comments And Links -(visible only on this page) - -include::../comments-and-links.adoc[] endif::env-github,rspecator-view[] diff --git a/rules/S1192/vbnet/rule.adoc b/rules/S1192/vbnet/rule.adoc index 0f709c04d41..1ff7e109242 100644 --- a/rules/S1192/vbnet/rule.adoc +++ b/rules/S1192/vbnet/rule.adoc @@ -2,9 +2,23 @@ include::../description.adoc[] -=== Noncompliant code example +=== Exceptions + +The following are ignored: + +* literals with fewer than 5 characters +* literals matching one of the parameter names +* literals used in attributes + +== How to fix it + +include::../howtofix.adoc[] + +=== Code examples + +==== Noncompliant code example -[source,vbnet] +[source,vbnet,diff-id=1,diff-type=noncompliant] ---- Public Class Foo @@ -21,9 +35,9 @@ Public Class Foo End Class ---- -=== Compliant solution +==== Compliant solution -[source,vbnet] +[source,vbnet,diff-id=1,diff-type=compliant] ---- Public Class Foo @@ -42,14 +56,6 @@ Public Class Foo End Class ---- -=== Exceptions - -The following are ignored: - -* literals with fewer than 5 characters -* literals matching one of the parameter names -* literals used in attributes - ifdef::env-github,rspecator-view[] ''' @@ -71,9 +77,5 @@ secondaries: all instances of the string literal ''' -== Comments And Links -(visible only on this page) - -include::../comments-and-links.adoc[] endif::env-github,rspecator-view[]