compressorjs icon indicating copy to clipboard operation
compressorjs copied to clipboard

Violates "no new" lint rule

Open julix-unity opened this issue 2 years ago • 4 comments

Describe the bug

The regular use of this starts with new Compressor without storing the result (since the main effect is in side effect).

From ESLint docs https://eslint.org/docs/latest/rules/no-new

In this case, the created object is thrown away because its reference isn’t stored anywhere, and in many cases, this means that the constructor should be replaced with a function that doesn’t require new to be used.

What lead to using new rather than just importing some kind of function like compress() or equivalent?

julix-unity avatar Jan 07 '23 15:01 julix-unity

Maybe you can try to use the native Reflect.construct() method, e.g.:

import Compressor from 'compressorjs';

// const compressor =  new Compressor(file, options);
const compressor = Reflect.construct(Compressor, [file, options]);

fengyuanchen avatar Jan 08 '23 06:01 fengyuanchen

hay @fengyuanchen, how can I push compressor result to data ? I'm using vuex and some parameter as payload to upload, and I cann't using vuex inside compressor

image

uzianhar avatar Jan 25 '23 07:01 uzianhar

@uzianhar I'm sorry. I have no idea about your situation.

fengyuanchen avatar Feb 04 '23 12:02 fengyuanchen

hay @fengyuanchen, how can I push compressor result to data ? I'm using vuex and some parameter as payload to upload, and I cann't using vuex inside compressor

image

did you solve your issue, i have the same problem

Murtdha avatar May 08 '23 17:05 Murtdha