Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

168
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda