unicorn/text-encoding-identifier-case Style
What it does
This rule aims to enforce consistent case for text encoding identifiers.
Enforces 'utf8'
for UTF-8 encoding Enforces 'ascii'
for ASCII encoding.
Why is this bad?
- Inconsistency in text encoding identifiers can make the code harder to read and understand.
- The ECMAScript specification does not define the case sensitivity of text encoding identifiers, but it is common practice to use lowercase.
Example
Examples of incorrect code for this rule:
javascript
import fs from "node:fs/promises";
async function bad() {
await fs.readFile(file, "UTF-8");
await fs.readFile(file, "ASCII");
const string = buffer.toString("utf-8");
}
Examples of correct code for this rule:
javascript
async function good() {
await fs.readFile(file, "utf8");
await fs.readFile(file, "ascii");
const string = buffer.toString("utf8");
}