Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
How to allow only multiline or single-line object declarations

I would like to allow single-line declarations like this:

const allowed = { foo: 1, bar: 2 }

And multi-line declarations like this:

const allowed = {
  foo: 1,
  bar: 2
}

const alsoAllowed = {
  foo: 1
}

While forbidding multiple properties on the same line of a multi-line declaration, like this

const forbidden = {
  foo: 1, bar: 2
}

Is that possible with ESLint? I've tried to achieve this by tweaking object-curly-newline and object-property-newline, but I can't seem to find the right combination.

I've gotten close with the following settings, but alsoAllowed above then violates object-curly-newline. Trying to mitigate that with the consistent and minProperties options seems to result in allowing the unwanted syntax too.

"object-curly-newline": [
    "warn",
    {
        "ObjectExpression": { "multiline": true },
        "ObjectPattern": { "multiline": true },
        "ImportDeclaration": { "multiline": true },
        "ExportDeclaration": { "multiline": true }
    }
],
"object-property-newline": [
    "warn",
    { "allowAllPropertiesOnSameLine": true }
],
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda