Create rule S6647: Unnecessary constructors should be removed (#2243)

https://github.com/SonarSource/SonarJS/issues/3906
This commit is contained in:
github-actions[bot] 2023-06-21 16:42:01 +02:00 committed by GitHub
parent 7a2b6606ba
commit ac8cd23e5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,17 @@
{
"title": "Unnecessary constructors should be removed",
"type": "CODE_SMELL",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "5min"
},
"tags": [
],
"defaultSeverity": "Minor",
"ruleSpecification": "RSPEC-6647",
"sqKey": "S6647",
"scope": "All",
"defaultQualityProfiles": ["Sonar way"],
"quickfix": "covered"
}

View File

@ -0,0 +1,30 @@
== Why is this an issue?
If the class declaration does not include a constructor, one is automatically created, so there is no need to provide an empty constructor, or one that just delegates to the parent class.
[source,javascript]
----
class Foo {
constructor() {} // Noncompliant, empty
}
class Bar extends Foo {
constructor(params) { // Noncompliant, just delegates to the parent
super(params);
}
}
----
Instead, you can safely remove the empty constructor without affecting the functionality.
[source,javascript]
----
class Foo {}
class Bar extends Foo {}
----
== Resources
=== Documentation
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/constructor[MDN - constructor]

View File

@ -0,0 +1,2 @@
{
}