Skip to content

Latest commit

Β 

History

History
64 lines (44 loc) Β· 1.58 KB

File metadata and controls

64 lines (44 loc) Β· 1.58 KB

text-encoding-identifier-case

πŸ“ Enforce consistent case for text encoding identifiers.

πŸ’Ό This rule is enabled in the following configs: βœ… recommended, β˜‘οΈ unopinionated.

πŸ”§πŸ’‘ This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.

  • Enforce 'utf8' for UTF-8 encoding.
  • Enforce 'ascii' for ASCII encoding.

This rule only auto-fix encoding in fs.readFile() and fs.readFileSync().

Examples

// ❌
await fs.readFile(file, 'UTF-8');

// βœ…
await fs.readFile(file, 'utf8');
// ❌
await fs.readFile(file, 'ASCII');

// βœ…
await fs.readFile(file, 'ascii');
// ❌
const string = buffer.toString('utf-8');

// βœ…
const string = buffer.toString('utf8');

Options

Type: object

withDash

Type: boolean
Default: false

Use WHATWG standard encoding notation with dashes (e.g., ⁠utf-8 instead of ⁠utf8).

// ❌
/* eslint unicorn/text-encoding-identifier-case: ["error", {"withDash": true}] */
await fs.readFile(file, 'utf8');
// βœ…
/* eslint unicorn/text-encoding-identifier-case: ["error", {"withDash": true}] */
await fs.readFile(file, 'utf-8');