unicorn/require-css-escape
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/require-css-escape": "error",
},
},
];Require CSS.escape() for interpolated values in CSS selectors.
document.querySelector(`[data-id="${id}"]`);element.querySelectorAll(`a[href^="#${hash}"]`);document.querySelector(`[data-id="${CSS.escape(id)}"]`);element.querySelectorAll(`a[href^="#${CSS.escape(hash)}"]`);document.querySelector(cssEscape`#${id}`);Examples from the ESLint documentation.
unicorn/require-css-escape
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/require-css-escape": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Prefer URLSearchParams over manually splitting query strings.
Require passive event listeners for high-frequency events.
Require boolean-returning Proxy traps to return booleans.
Prefer URL.canParse() over constructing a URL in a try/catch for validation.
Require streaming decoding of fetch-body chunks with TextDecoder.