From f2cae45f99ac817ab4a3b24db6138cfcf944edd7 Mon Sep 17 00:00:00 2001 From: ericmorand-sonarsource Date: Mon, 25 Mar 2024 12:58:32 +0000 Subject: [PATCH 1/7] Create rule S6958 --- rules/S6958/javascript/metadata.json | 25 ++++++++++++++++ rules/S6958/javascript/rule.adoc | 44 ++++++++++++++++++++++++++++ rules/S6958/metadata.json | 2 ++ 3 files changed, 71 insertions(+) create mode 100644 rules/S6958/javascript/metadata.json create mode 100644 rules/S6958/javascript/rule.adoc create mode 100644 rules/S6958/metadata.json diff --git a/rules/S6958/javascript/metadata.json b/rules/S6958/javascript/metadata.json new file mode 100644 index 00000000000..c587712dcdb --- /dev/null +++ b/rules/S6958/javascript/metadata.json @@ -0,0 +1,25 @@ +{ + "title": "FIXME", + "type": "CODE_SMELL", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "5min" + }, + "tags": [ + ], + "defaultSeverity": "Major", + "ruleSpecification": "RSPEC-6958", + "sqKey": "S6958", + "scope": "All", + "defaultQualityProfiles": ["Sonar way"], + "quickfix": "unknown", + "code": { + "impacts": { + "MAINTAINABILITY": "HIGH", + "RELIABILITY": "MEDIUM", + "SECURITY": "LOW" + }, + "attribute": "CONVENTIONAL" + } +} diff --git a/rules/S6958/javascript/rule.adoc b/rules/S6958/javascript/rule.adoc new file mode 100644 index 00000000000..4bd440f87a8 --- /dev/null +++ b/rules/S6958/javascript/rule.adoc @@ -0,0 +1,44 @@ +FIXME: add a description + +// If you want to factorize the description uncomment the following line and create the file. +//include::../description.adoc[] + +== Why is this an issue? + +FIXME: remove the unused optional headers (that are commented out) + +//=== What is the potential impact? + +== How to fix it +//== How to fix it in FRAMEWORK NAME + +=== Code examples + +==== Noncompliant code example + +[source,text,diff-id=1,diff-type=noncompliant] +---- +FIXME +---- + +==== Compliant solution + +[source,text,diff-id=1,diff-type=compliant] +---- +FIXME +---- + +//=== How does this work? + +//=== Pitfalls + +//=== Going the extra mile + + +//== Resources +//=== Documentation +//=== Articles & blog posts +//=== Conference presentations +//=== Standards +//=== External coding guidelines +//=== Benchmarks diff --git a/rules/S6958/metadata.json b/rules/S6958/metadata.json new file mode 100644 index 00000000000..2c63c085104 --- /dev/null +++ b/rules/S6958/metadata.json @@ -0,0 +1,2 @@ +{ +} From c8f323424b99cfa715f4644c1eb40fca92a5fa02 Mon Sep 17 00:00:00 2001 From: Eric MORAND Date: Mon, 25 Mar 2024 17:46:14 +0100 Subject: [PATCH 2/7] Add rule S6958 --- rules/S6958/javascript/metadata.json | 23 ---------------- rules/S6958/javascript/rule.adoc | 41 ++++++++-------------------- rules/S6958/metadata.json | 23 +++++++++++++++- 3 files changed, 33 insertions(+), 54 deletions(-) diff --git a/rules/S6958/javascript/metadata.json b/rules/S6958/javascript/metadata.json index c587712dcdb..2c63c085104 100644 --- a/rules/S6958/javascript/metadata.json +++ b/rules/S6958/javascript/metadata.json @@ -1,25 +1,2 @@ { - "title": "FIXME", - "type": "CODE_SMELL", - "status": "ready", - "remediation": { - "func": "Constant\/Issue", - "constantCost": "5min" - }, - "tags": [ - ], - "defaultSeverity": "Major", - "ruleSpecification": "RSPEC-6958", - "sqKey": "S6958", - "scope": "All", - "defaultQualityProfiles": ["Sonar way"], - "quickfix": "unknown", - "code": { - "impacts": { - "MAINTAINABILITY": "HIGH", - "RELIABILITY": "MEDIUM", - "SECURITY": "LOW" - }, - "attribute": "CONVENTIONAL" - } } diff --git a/rules/S6958/javascript/rule.adoc b/rules/S6958/javascript/rule.adoc index 4bd440f87a8..1d1031a75bd 100644 --- a/rules/S6958/javascript/rule.adoc +++ b/rules/S6958/javascript/rule.adoc @@ -1,44 +1,25 @@ -FIXME: add a description - -// If you want to factorize the description uncomment the following line and create the file. -//include::../description.adoc[] - == Why is this an issue? -FIXME: remove the unused optional headers (that are commented out) - -//=== What is the potential impact? - -== How to fix it -//== How to fix it in FRAMEWORK NAME +Calling a literal throws a TypeError, and is likely the result of an unintentional error in the code. -=== Code examples +This rule raises an issue when an attempt is made to use a literal as a function. -==== Noncompliant code example +=== Noncompliant code example [source,text,diff-id=1,diff-type=noncompliant] ---- -FIXME +true(); // Noncompliant, literal should not be used as function ---- -==== Compliant solution +This rule also detects when a literal is used as a _tag_ function. -[source,text,diff-id=1,diff-type=compliant] +[source,text,diff-id=1,diff-type=noncompliant] ---- -FIXME +true``; // Noncompliant, literal should not be used as tag function ---- -//=== How does this work? - -//=== Pitfalls - -//=== Going the extra mile - +== Resources +=== Documentation -//== Resources -//=== Documentation -//=== Articles & blog posts -//=== Conference presentations -//=== Standards -//=== External coding guidelines -//=== Benchmarks +* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions[Functions] +* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals[Template literals] diff --git a/rules/S6958/metadata.json b/rules/S6958/metadata.json index 2c63c085104..ad7cb16e3f1 100644 --- a/rules/S6958/metadata.json +++ b/rules/S6958/metadata.json @@ -1,2 +1,23 @@ { -} + "title": "Literals should not be used as functions", + "type": "BUG", + "code": { + "impacts": { + "RELIABILITY": "HIGH" + }, + "attribute": "LOGICAL" + }, + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "5min" + }, + "defaultSeverity": "Critical", + "ruleSpecification": "RSPEC-6958", + "sqKey": "S6958", + "scope": "Main", + "defaultQualityProfiles": [ + "Sonar way" + ], + "quickfix": "unknown" +} \ No newline at end of file From cbd4513a08806b44b82faa560e1b1288efeba7f5 Mon Sep 17 00:00:00 2001 From: Eric Morand <156682586+ericmorand-sonarsource@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:08:03 +0100 Subject: [PATCH 3/7] Update rules/S6958/javascript/rule.adoc Co-authored-by: Yassin Kammoun <52890329+yassin-kammoun-sonarsource@users.noreply.github.com> --- rules/S6958/javascript/rule.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/S6958/javascript/rule.adoc b/rules/S6958/javascript/rule.adoc index 1d1031a75bd..a47643c827d 100644 --- a/rules/S6958/javascript/rule.adoc +++ b/rules/S6958/javascript/rule.adoc @@ -6,7 +6,7 @@ This rule raises an issue when an attempt is made to use a literal as a function === Noncompliant code example -[source,text,diff-id=1,diff-type=noncompliant] +[source,js] ---- true(); // Noncompliant, literal should not be used as function ---- From 273d9995af65f53aa96763c6c3ba8165a73b4c18 Mon Sep 17 00:00:00 2001 From: Eric Morand <156682586+ericmorand-sonarsource@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:08:09 +0100 Subject: [PATCH 4/7] Update rules/S6958/javascript/rule.adoc Co-authored-by: Yassin Kammoun <52890329+yassin-kammoun-sonarsource@users.noreply.github.com> --- rules/S6958/javascript/rule.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/S6958/javascript/rule.adoc b/rules/S6958/javascript/rule.adoc index a47643c827d..b35922cedff 100644 --- a/rules/S6958/javascript/rule.adoc +++ b/rules/S6958/javascript/rule.adoc @@ -13,7 +13,7 @@ true(); // Noncompliant, literal should not be used as function This rule also detects when a literal is used as a _tag_ function. -[source,text,diff-id=1,diff-type=noncompliant] +[source,js] ---- true``; // Noncompliant, literal should not be used as tag function ---- From bc7425850607f9373b334cc524b283770be9ebbd Mon Sep 17 00:00:00 2001 From: Eric Morand <156682586+ericmorand-sonarsource@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:08:17 +0100 Subject: [PATCH 5/7] Update rules/S6958/metadata.json Co-authored-by: Yassin Kammoun <52890329+yassin-kammoun-sonarsource@users.noreply.github.com> --- rules/S6958/metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/S6958/metadata.json b/rules/S6958/metadata.json index ad7cb16e3f1..90fe5ff3b39 100644 --- a/rules/S6958/metadata.json +++ b/rules/S6958/metadata.json @@ -19,5 +19,5 @@ "defaultQualityProfiles": [ "Sonar way" ], - "quickfix": "unknown" + "quickfix": "infeasible" } \ No newline at end of file From 2fd58c5be12c87cc3e4131194d94c7a72fbf76c7 Mon Sep 17 00:00:00 2001 From: Eric Morand <156682586+ericmorand-sonarsource@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:08:22 +0100 Subject: [PATCH 6/7] Update rules/S6958/javascript/rule.adoc Co-authored-by: Yassin Kammoun <52890329+yassin-kammoun-sonarsource@users.noreply.github.com> --- rules/S6958/javascript/rule.adoc | 1 - 1 file changed, 1 deletion(-) diff --git a/rules/S6958/javascript/rule.adoc b/rules/S6958/javascript/rule.adoc index b35922cedff..500bfc7282f 100644 --- a/rules/S6958/javascript/rule.adoc +++ b/rules/S6958/javascript/rule.adoc @@ -4,7 +4,6 @@ Calling a literal throws a TypeError, and is likely the result of an unintention This rule raises an issue when an attempt is made to use a literal as a function. -=== Noncompliant code example [source,js] ---- From 46bbcdf7cd95e2e2e271036cdc11665875898bf2 Mon Sep 17 00:00:00 2001 From: Eric MORAND Date: Wed, 27 Mar 2024 12:01:03 +0100 Subject: [PATCH 7/7] Add missing tags metadata --- rules/S6958/metadata.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rules/S6958/metadata.json b/rules/S6958/metadata.json index 90fe5ff3b39..7317b707bbb 100644 --- a/rules/S6958/metadata.json +++ b/rules/S6958/metadata.json @@ -19,5 +19,7 @@ "defaultQualityProfiles": [ "Sonar way" ], - "quickfix": "infeasible" + "quickfix": "infeasible", + "tags": [ + ] } \ No newline at end of file