Skip to content

Commit

Permalink
Create rule S6958: Literals should not be used as functions (#3812)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Mar 27, 2024
1 parent ee3c651 commit 1df4ed5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rules/S6958/javascript/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
24 changes: 24 additions & 0 deletions rules/S6958/javascript/rule.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
== Why is this an issue?

Calling a literal throws a TypeError, and is likely the result of an unintentional error in the code.

This rule raises an issue when an attempt is made to use a literal as a function.


[source,js]
----
true(); // Noncompliant, literal should not be used as function
----

This rule also detects when a literal is used as a _tag_ function.

[source,js]
----
true``; // Noncompliant, literal should not be used as tag function
----

== Resources
=== Documentation

* 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]
25 changes: 25 additions & 0 deletions rules/S6958/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"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": "infeasible",
"tags": [
]
}

0 comments on commit 1df4ed5

Please sign in to comment.