Skip to content

Latest commit

 

History

History
38 lines (29 loc) · 654 Bytes

prefer-destructuring-in-parameters.md

File metadata and controls

38 lines (29 loc) · 654 Bytes

Prefer destructuring in parameters over accessing properties

Makes your code shorter and nicer.

This rule is fixable.

Fail

const getObjectProperty = object => object.property;
const removeEmptyValues = object => Object.fromEntries(
	Object.entries(object).filter(keyValuePair => Boolean(keyValuePair[1]))
);

Pass

const getFoo = ({property}) => property;
const removeEmptyValues = object => Object.fromEntries(
	Object.entries(object).filter(([, value]) => Boolean(value))
);
// Used property and index together
function foo(array) {
	if (array.length > 0) {
		return bar(array[0]);
	}
}