lukastaegert/eslint-plugin-tree-shaking

Class field initialization false positives?

ziacik opened this issue · 5 comments

ziacik commented

Hi, is this a bug?

This
image

and this
image

is syntactically equivalent, isn't it?

It should not give error in the first case, should it?

Yes, but the plugin is quite old and badly maintained, which is why advanced logic for class fields is missing.

ziacik commented

@lukastaegert

Thanks for your reply.

I'd be happy to try providing a PR, but I noticed this particular case is explicitly set as invalid in tests.
I'm unable to identify a reason for this decision. Could you please offer an explanation why this is considered a possible side effect?

{
code: "class x {y = ext()}",
parser: PARSER_BABEL,
errors: [
{
message: "Cannot determine side-effects of calling global function",
type: "Identifier",
},
],
},

Because ext is an unknown function with unknown side effects

ziacik commented

Yes, ext can have side effects, but it is only called at class construction, so it shouldn't be considered side-effected unless the class is globally constructed, no?

ziacik commented

I've created a PR for this. If you agree with my points, I'd appreciate if you could review and merge the PR. Thank you.