accessor-pairs
eslint
No autofix
eslint.config.js
export default [
{
rules: {
"accessor-pairs": "error",
},
},
];const q = {
set a(value) {
this.val = value;
}
};
const r = {d: 1};
Object.defineProperty(r, 'c', {
set: function(value) {
this.val = value;
}
});
const r2 = {d: 1};
Object.defineProperty(r2, 'c', {
'set': function(value) {
this.val = value;
}
});
const r3 = {d: 1};
Object.defineProperty(r3, 'c', {
['set']: function(value) {
this.val = value;
}
});class Foo {
get a() {
return this.val;
}
}
class Bar {
static get a() {
return this.val;
}
}
const Baz = class {
get a() {
return this.val;
}
static set a(value) {
this.val = value;
}
}class Foo {
set a(value) {
this.val = value;
}
}
const Bar = class {
static set a(value) {
this.val = value;
}
}const s = {
set a(value) {
this.val = value;
},
get a() {
return this.val;
}
};
const t = {d: 1};
Object.defineProperty(t, 'c', {
set: function(value) {
this.val = value;
},
get: function() {
return this.val;
}
});
const t2 = {d: 1};
Object.defineProperty(t2, 'c', {
'set': function(value) {
this.val = value;
},
['get']: function() {
return this.val;
}
});const y = {
set a(value) {
this.val = value;
},
get a() {
return this.val;
}
};
const z = {d: 1};
Object.defineProperty(z, 'c', {
set: function(value) {
this.val = value;
},
get: function() {
return this.val;
}
});
const z2 = {d: 1};
Object.defineProperty(z2, 'c', {
'set': function(value) {
this.val = value;
},
['get']: function() {
return this.val;
}
});/*eslint accessor-pairs: ["error", {
"getWithoutSet": true, "setWithoutGet": true, "enforceForClassMembers": false
}]*/
class Foo {
get a() {
return this.val;
}
}
class Bar {
static set a(value) {
this.val = value;
}
}
const Baz = class {
static get a() {
return this.val;
}
}
const Quux = class {
set a(value) {
this.val = value;
}
}Examples from the ESLint documentation.
accessor-pairs
eslint
export default [
{
rules: {
"accessor-pairs": "error",
},
},
];accessor-pairs
eslint plugin · pedantic
{
"rules": {
"accessor-pairs": "error"
}
}nursery/useAccessorPairs
nursery · since 2.6.5
{
"linter": {
"rules": {
"nursery": {
"useAccessorPairs": "error"
}
}
}
}Disallow unmodified loop conditions
Require return statements to either always or never specify values
Disallow dangling underscores in identifiers