π Disallow unnecessary Blob to File conversion.
πΌ This rule is enabled in the following configs: β
recommended, βοΈ unopinionated.
π‘ This rule is manually fixable by editor suggestions.
File objects implement the Blob interface. Converting a Blob to a File just to pass it to APIs that already accept a Blob is unnecessary.
This rule currently checks a narrow pattern: a standalone const, initialized with new File([blob], 'filename') and used once in URL.createObjectURL(), FormData#append(), or FormData#set(). The blob value must be an earlier const initialized with new Blob(), new Blob(parts), or new File(parts, name) without type options, since the File wrapper clears the MIME type. For FormData, the receiver must be a const initialized with new FormData().
// β
const blob = new Blob();
const file = new File([blob], 'image.jpg');
URL.createObjectURL(file);
// β
URL.createObjectURL(blob);// β
const blob = new Blob();
const formData = new FormData();
const file = new File([blob], 'image.jpg');
formData.append('file', file);
// β
formData.append('file', blob, 'image.jpg');// β
const blob = new Blob();
const formData = new FormData();
const file = new File([blob], 'image.jpg');
formData.set('file', file);
// β
formData.set('file', blob, 'image.jpg');