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.