no-data-view-mutation
Disallow in-place mutation of DataView instances.
Targeted pattern scopeâ
This rule targets mutating setter calls on known DataView instances created via new DataView(...), including direct constructor expressions and tracked variable aliases.
What this rule reportsâ
DataViewmutations via.setInt8(...),.setInt16(...),.setInt32(...)DataViewmutations via.setUint8(...),.setUint16(...),.setUint32(...)DataViewmutations via.setFloat32(...),.setFloat64(...)DataViewmutations via.setBigInt64(...),.setBigUint64(...)
Why this rule existsâ
DataView writes directly mutate an underlying ArrayBuffer. In shared binary workflows, these writes can create non-obvious side effects that propagate across decoding, parsing, and transport layers.
This rule encourages immutable binary-state handling by rejecting setter-based mutation on known DataView values.
â Incorrectâ
const view = new DataView(new ArrayBuffer(8));
view.setUint8(0, 255);
â Correctâ
const view = new DataView(new ArrayBuffer(8));
view.getUint8(0);
Additional examplesâ
// â Mutates shared DataView state
const sharedView = new DataView(new ArrayBuffer(8));
sharedView.setFloat32(0, 1.5);
// â
Read-only DataView usage
const sharedView = new DataView(new ArrayBuffer(8));
sharedView.getFloat32(0);
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-data-view-mutation": "error",
},
},
];
When not to use itâ
If your code intentionally performs imperative writes through DataView for low-level binary protocols, this rule may be too strict for those tightly controlled modules.
Rule catalog ID: R922