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

165
Visualizações
There is ESLint rule to avoid try-catch if there just one line?

Let's say I have this code:


export class a {

    private async func(){

        try {
            await something();
        } catch (error) {
          /////
        }

    }
}

I want to avoid the use of try-catch when there is only one line in the try block and instead use catch like this:

await something().catch(err => {…});

There is any ESLint rule that will raise an error for that?

Thanks!

EDIT 1

I tried to use the no-restricted-syntax rule with my @typescript-eslint/parser according to the AST, but it does not work:

    "no-restricted-syntax": [
      "error",
      {
        "selector": "TryStatement > BlockStatement[body.length=0]",
        "message": "No try block for one line!"
      }
    ],
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