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

201
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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