Remove this useless assignment to variable

I am using SimpleDataTables JS Library and their minimal suggested implementation:
const dataTable = new DataTable("#myTable");

In SC this throws me an Remove this useless assignment to variable "dataTable". and an Remove the declaration of the unused 'dataTable' variable.

If I remove the assignement SC tells me to Either remove this useless object instantiation of "DataTable" or use it.

In SC, the FIRST approach is considered a code-smell, the second approach is considered a bug. So I prefer to use first approach, but still SC is not fully happy.

With my rather limited knowledge of JS, I would say simply doing new DataTable("#myTable"); is the right approach.
Of course, strictly speaking, that library should probably not have sideffects when instantiating the object but rather provide a method (like DataTable->run()), but that is not the case.

Is there some other approach to do it “correctly” other than marking this as a false alarm?


Indeed you are using some lib probably having side-effects on constructor execution. I don’t think we will support this lib (I see from npm downloads it’s not very popular), so it’s up to you to ignore the issues.

I would keep the variable (it seems the recommended way as you might hook some events on it later). So either you could “won’t fix” the issues, or you can set in SC settings to ignore particular files for these rules (Administration → General Settings → Analysis Scope → Ignore Issues on Multiple Criteria).

1 Like

Understood, I will maybe switch to the official data tables lib by jQuery.
I had chosen the current one because it is much lighter, but in the end with modern computers and servers etc this doesn’t matter that much anyway.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.