unicorn/no-unused-properties
eslint-plugin-unicorn
No autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-unused-properties": "error",
},
},
];const myEnum = {
used: 1,
unused: 2, // <- Property `unused` is defined but never used.
};
console.log(myEnum.used);
const {used} = myEnum;function foo(args: {used: number; unused: number}) {
return args.used;
}function foo(args: {used: number}) {
return args.used;
}const myEnum = {
used: 1,
};
console.log(myEnum.used);
const {used} = myEnum;const myEnum = {
used: 1,
usedToo: 2,
};
console.log(myEnum); // The whole object is used
console.log(myEnum.used, myEnum.usedToo); // Every property is used individually
myEnum[x] // Unpredictable, all properties are considered to be used
// Objects with methods, getters, setters, or `function` values are skipped too, all properties are considered used
const foo = {
used: 1,
method() {
return this;
}
};Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
unicorn/no-unused-properties
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-unused-properties": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Prefer using using/await using over manual try/finally resource disposal.
Prefer Iterator.concat(…) over temporary spread arrays.