unicorn/prefer-literal-ascii
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-literal-ascii": "error",
},
},
];Prefer literal printable ASCII characters over escape sequences.
const letter = '\x41';
const word = '\u0042\u{43}';
const template = `\u0024\u007Bvalue}`;const letter = 'A';
const word = 'BC';
const template = `\${value}`;Examples from the ESLint documentation.
unicorn/prefer-literal-ascii
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-literal-ascii": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Prefer moving .toArray() to the end of iterator helper chains.
Prefer new Map() over Object.fromEntries() when using the result as a map.
Prefer iterator helpers over temporary arrays from iterators.
Prefer moving ternaries into the minimal varying part of an expression.
Prefer passing iterables directly to constructors instead of filling empty collections.
Prefer Object.defineProperties() over multiple Object.defineProperty() calls.