no-empty-pattern

Disallow destructuring patterns that bind nothing

warn by default

const {} = user looks like a declaration but doesn't create a variable. The usual cause is one wrong character. { settings: {} } destructures settings into nothing, while { settings = {} } would give it a default value.

This rule is on by default.

Configure#

On by default as a warning. To turn it off:

bunfig.toml
[lint.rules]
"no-empty-pattern" = "off" # or "error"

Every option, set to its default:

bunfig.toml
[lint.rules]
"no-empty-pattern" = ["warn", {
  allowObjectPatternsAsParameters = true,
}]

Examples#

example.js3 problems
const { settings: {} } = user;
const [] = items;

function render([]) {
  return "<div></div>";
}
example.jsNo problems
const { settings = {} } = user;
const [first] = items;

function render({ title }) {
  return `<div>${title}</div>`;
}

Options#

OptionDefaultWhat it does
allowObjectPatternsAsParameterstrueAllow {} as a function parameter, with no default value or with the default {}.

This is for a function that's called with an object it doesn't need, but that uses a later parameter. Playwright requires the {} in a fixture that uses no other fixture. With an ESLint config file the default is ESLint's, false.

example.jsNo problems
function withServer({}, use) {
  return use(startServer());
}

function withDatabase({} = {}, use) {
  return use(openDatabase());
}
example.jswith { "allowObjectPatternsAsParameters": false }1 problem
function withServer({}, use) {
  return use(startServer());
}

An empty array pattern as a parameter is still reported:

example.js1 problem
function withServer([], use) {
  return use(startServer());
}