Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create rule S6958: Literals should not be used as functions #3812

Merged
merged 8 commits into from
Mar 27, 2024
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": [
]
}
Loading