Skip to main content

no-writeonly

Disallow setter-only accessors.

Targeted pattern scopeโ€‹

This rule targets object and class accessors.

What this rule reportsโ€‹

This rule reports setters that do not have corresponding getters.

Why this rule existsโ€‹

Write-only properties hide state flow and make object behavior harder to debug.

โŒ Incorrectโ€‹

const state = {
set value(next: number) {
this._value = next;
},
};

โœ… Correctโ€‹

const state = {
_value: 0,
get value() {
return this._value;
},
set value(next: number) {
this._value = next;
},
};

Behavior and migration notesโ€‹

This rule forwards options and behavior to ESLint core accessor-pairs.

Additional examplesโ€‹

class Box {
set value(next: number) {
this._value = next;
}
}
// โŒ reported

class BoxFixed {
_value = 0;

get value() {
return this._value;
}

set value(next: number) {
this._value = next;
}
}
// โœ… valid

ESLint flat config exampleโ€‹

import etcMisc from "eslint-plugin-etc-misc";

export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/no-writeonly": "error",
},
},
];

When not to use itโ€‹

Disable this rule if you intentionally use write-only sink objects and the pattern is documented.

Package documentationโ€‹

Rule catalog ID: R052

Further readingโ€‹

Adoption resourcesโ€‹

  • Start at warning level in CI, then move to error after cleanup.
  • Use focused codemods/autofix batches per package or directory.