Create rule S6647: Unnecessary constructors should be removed (#2243)
https://github.com/SonarSource/SonarJS/issues/3906
This commit is contained in:
parent
7a2b6606ba
commit
ac8cd23e5b
17
rules/S6647/javascript/metadata.json
Normal file
17
rules/S6647/javascript/metadata.json
Normal 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"
|
||||
}
|
30
rules/S6647/javascript/rule.adoc
Normal file
30
rules/S6647/javascript/rule.adoc
Normal 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]
|
2
rules/S6647/metadata.json
Normal file
2
rules/S6647/metadata.json
Normal file
@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user