I am getting this linting error for the below code- "error Unexpected empty object pattern no-empty-pattern". Does anyone know how to solve this issue? Its a tsx file.
const stateToProps = ({}, { data = [], filters = {}, staticFilters =
[{}] }) => {
const allFilters = staticFilters ? Object.assign({}, filters, ...staticFilters) : filters;
const newData = getFilteredRows(allFilters, data);
return {
data: newData,
unfilteredData: data,
};
};
//called like this
export const NodeList = connect<{}, {}, CustomNodeTableProps>(stateToProps)(CustomNodeTable);
I ran this code through the ESLint demo app after transpiling the TypeScript; the linter error is coming from {}
in the first line.
const stateToProps = ({}, // rest of the function
no-empty-pattern is meant to catch code that appears to be using destructuring, but does not assign any variables. In the code above, stateToProps
accepts a first argument, but no matter what that argument is, it is destructured as an empty object {}
and nothing is assigned.
If that first argument matters, you could change the code to descructure it:
const stateToProps = ({importantThing},
If not, indicate that we don't care:
const stateToProps = (_,
Or, set a default.
const stateToProps = (importantThing = {},
Each of these changes resolve the ESLint warning.
In no-empty-pattern situations like this I tend to disable the lint rule for that particular line by adding the following comment.
JavaScript:
// eslint-disable-next-line no-empty-pattern
const stateToProps = ({}, otherParams, // rest of the function
...
TypeScript:
// eslint-disable-next-line @typescript-eslint/no-empty-pattern
const stateToProps = ({}, otherParams, // rest of the function
...
The reasoning for this is first, that I DO NOT want turn off the no-empty-pattern globally, and second I also DO NOT want to collect plenty of lint warnings, as this would blur the important warnings and errors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With