which versions are you using (SonarQube Server / Community Build, Scanner, Plugin, and any relevant extension): * Community Edition v10.7 (96327)
how is SonarQube deployed: zip, Docker, Helm: Docker
what are you trying to achieve: Running Sonarqube scanner in a Jenkins pipeline without any errors/warnings
what have you tried so far to achieve this: locally running eslint does not produce the error/warning
I am getting this Warning message when the sonarqube scanner runs in my Jenkins pipeline:
Warning: React version specified in eslint-plugin-react-settings must be a valid semver version, or “detect”; got “^17”
I have a .eslintrc file with this setup:
“settings”: {
“react”: {
“version”: “detect”
},
My package.json file has:
“react”: “^17”,
With “detect” option in eslinrc, it should pickup the installed version of react. This works fine locally with eslint but is failing with the sonarqube scanner
At what point do you get this warning? Can you share what’s happening before and after you get this message? Basically, a more complete log sample, please.
So in a nutshell, our Jenkins pipeline for our React frontend goes like this:
→ npm i → npm run test (playwright) → Dependency Checker → Sonarqube Scanner
When Sonarqube scanner runs these are the command parameters:
I can provide a log around where the warning/error is issued:
…
INFO: Sensor JavaScript/TypeScript analysis [javascript]
INFO: Detected os: Linux arch: amd64 alpine: false. Platform: LINUX_X64
INFO: Using embedded Node.js runtime.
INFO: Using Node.js executable: ‘/root/.sonar/js/node-runtime/node’.
INFO: Memory configuration: OS (515601 MB), Node.js (4144 MB).
INFO: Found 0 tsconfig.json file(s):
INFO: Creating TypeScript program
INFO: TypeScript configuration file /tmp/tmp-136905-L5CFcU8VT4yg
INFO: 179 source files to be analyzed
INFO: Starting analysis with current program
INFO: 4/179 files analyzed, current file: src/components/Base/MenuItemWithTooltip/styled.js ERROR: Warning: React version specified in eslint-plugin-react-settings must be a valid semver version, or “detect”; got “^17”
INFO: Analyzed 179 file(s) with current program
INFO: 179/179 source files have been analyzed
INFO: Hit the cache for 0 out of 179
INFO: Miss the cache for 179 out of 179: ANALYSIS_MODE_INELIGIBLE [179/179]
INFO: Sensor JavaScript/TypeScript analysis [javascript] (done) | time=24716ms
INFO: Sensor JavaScript inside YAML analysis [javascript]
…
If you need further log context let me know and I can provide it. Thanks for the help
You discovered a bug in the eslint-plugin-react library that our analyzer uses to implement some React rules. Your declared version ^17 is a perfectly valid semver constraint, as confirmed there, and by the semver package that eslint-plugin-react uses for that matter:
There is a bug in the React plugin that makes it fail with ^17 (and any other constraint that does not contain only digits and dots). Not really surprising, considering that it is visually obvious that this code will fail as soon as the first part is not a number:
Since you discovered the bug, you may want to open the issue in their repository and/or propose a PR - and enjoy the deserved glory . We would, of course, back you up to try and make the issue noticed by the maintainers. But if you prefer, we can take care of opening the issue ourselves.
Prior to opening this topic here on the sonarqube community, I had already reached out to the eslint-react-plugin maintainer (Jordan Harband) as you can see in the GitHub issue:
Based on your feedback I went back to that issue and asked Jordan for feedback and he does not agree with your interpretation of the root cause of the issue.
Care to assist me in finding a consensus? I would appreciate it if you could reply back on that GitHub issue, if possible.
Well, I’m proven wrong: I double-checked and ranges are not part of Semantic Versioning specification.
The issue is definitely on our side, when our plugin reads the version from the project manifest (package.json). It is passing the version verbatim to the React plugin; instead, it should coerce the version using the semver package to guarantee that the version sent to eslint-plugin-react is Semantic Versioning compatible.