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

195
Vistas
SonarQube code smell due to it ignoring `this` in two of three options

Here's an example of the issue I'm facing.

I suspect the reason I get this error on this block of code is because according to javascript:3AS3800...

Functions returning this are ignored.

Assuming this is the case, I'm having trouble coming up with a clean workaround.

    if (typeof (row) === 'string') {
      return (
        <Grid key={i}>
          <Divider className={classes.divider} />
            <Typography>
              { row }
            </Typography>
        </Grid>
      )
    }

    if (row.constructor === Array) {
      return row.map((item, index) => (
        <Grid key={index}>
          { this.getItem(item, formProps) }
        </Grid>
      ))
    }

    return (
      <Grid key={i}>
        { this.getItem(row, formProps) }
      </Grid>
    )
  }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

For those that might stumble upon this, I misunderstood the error message.

Sonarqube wants each return to be a value of the same type. In my example, the middle block returns a list of Grid components while the rest return solo Grid components. The solution was to return the solo Grid components as lists like so:

    if (typeof (row) === 'string') {
      return ([
        <Grid key={i}>
          <Divider className={classes.divider} />
            <Typography>
              { row }
            </Typography>
        </Grid>,
      ])
    }

    if (row.constructor === Array) {
      return row.map((item, index) => (
        <Grid key={index}>
          { this.getItem(item, formProps) }
        </Grid>
      ))
    }

    return ([
      <Grid key={i}>
        { this.getItem(row, formProps) }
      </Grid>,
    ])
  }
about 4 years ago · Juan Pablo Isaza Denunciar
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