no-dom-token-list-mutation
Disallow in-place mutation of DOM token lists (classList, relList, part).
Targeted pattern scopeâ
This rule targets mutating DOMTokenList method calls on common token-list properties and aliases.
What this rule reportsâ
classList.add(...),classList.remove(...),classList.replace(...),classList.toggle(...)relList.add(...),relList.remove(...),relList.replace(...),relList.toggle(...)part.add(...),part.remove(...),part.replace(...),part.toggle(...)
Why this rule existsâ
DOM token list mutation mutates shared UI state in place. In immutable architectures, mutating class/relationship token lists can hide side effects and make rendering behavior harder to reason about.
This rule helps enforce immutable view-state composition by flagging token-list mutators.
â Incorrectâ
element.classList.add("active");
â Correctâ
element.classList.contains("active");
Additional examplesâ
// â Mutates DOM token list via alias
const tokens = element.classList;
tokens.toggle("open");
// â
Reads token state without mutation
const tokens = element.classList;
tokens.contains("open");
ESLint flat config exampleâ
import immutable from "eslint-plugin-immutable-2";
export default [
{
files: ["**/*.{js,mjs,cjs,ts,mts,cts,tsx}"],
plugins: { immutable },
rules: {
"immutable/no-dom-token-list-mutation": "error",
},
},
];
When not to use itâ
If your rendering approach intentionally mutates DOM token lists imperatively (for example in low-level UI adapters), this rule may be too strict for those internals.
Rule catalog ID: R935