Siegfried
(Siegfried Ehret)
June 16, 2021, 1:56pm
1
Hello folks!
I hope you are doing well.
I need you! I have this small (and amazing) example component:
import React from "react";
export default function Plop({ handler = () => {} }) {
return <button onClick={handler}>Plop</button>;
}
SonarLint is angry at me and raises a critical issue about this rule :
I think using empty functions as default parameters is a special case for this rule and should not raise a critical issue.
I use:
IntelliJ IDEA 2021.1.2 (Ultimate Edition) Build #IU-211 .7442.40
SonarLint 4.16.0.31683
Cheers !
2 Likes
Lena
(Elena Vilchik)
June 17, 2021, 5:12am
2
Hi @Siegfried
This is the rule coming from ESLint core (no-empty-function - Rules - ESLint - Pluggable JavaScript linter ), so we don’t have ability to adjust it directly.
Still motivation for this rule is applicable even for default parameter value: block {}
can be confused with an empty object.
So the suggestion to you would be to add comment, e.g. /* do nothing */
inside empty block. You could also argue if rule should raise critical
issues, but as it is a code smell, having critical
is ok to me.
1 Like
Siegfried
(Siegfried Ehret)
June 17, 2021, 7:57am
3
Oh ok! Thanks a lot @Lena !
Have a nice day!
system
(system)
Closed
June 24, 2021, 7:58am
4
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.