Skip to content

Latest commit

Β 

History

History
48 lines (35 loc) Β· 1.63 KB

no-blob-to-file.md

File metadata and controls

48 lines (35 loc) Β· 1.63 KB

no-blob-to-file

πŸ“ 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().

Examples

// ❌
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');