Some problems highlighted in SQ not appearing in VScode sonarlint

So far i’ve noticed this with 1 specific rule which is “Functions should always return the same type”, other rules are working fine. Tested out on multiple different machines and in connected + unconnected mode.

Versions:
VScode: 1.56.2
SonarLint: 2.0.0
SonarQube: 8.9

Hi Ahmed, welcome to the SonarSource Community!

I am guessing you mean the rule for JavaScript. I just tested with the same releases in my local environment, and the noncompliant code from the SonarQube rule documentation raises an issue in SonarLint for me:

function foo(a) {  // Noncompliant
  if (a === 1) {
    return true;
  }
  return 3;
}

It might help if you give an example of code that is not raising the issue for you.

Hey Jeff,

The code you posted is working fine for me as well, but it doesnt seem to work for something like this written in React:

const MyComponent = () => {
  const [counter, setCounter] = useState(0);
  
  if(counter) return counter; // number
  return 'string';
}

On the other hand this works:
const MyComponent = () => {
const counter = 1;

  if(counter) return counter; // number
  return 'string';
}

So i guess SonarLint isn’t able to identify variable types in some cases? They are being caught on SonarQube though.

hello @awa ,

I created issue in our backlog to track this problem

Thanks for reporting it

1 Like