- What language is this for? javascript
- Which rule? RSPEC-2208
- Why do you believe it’s a false-positive/false-negative? [Question][RSPEC-2208] Is `Wildcard imports should not be used` in js supposed to be marked as 'critical'? · Issue #16 · rikkeisoft/sonar-rules · GitHub
- Are you using
- SonarCloud? No
- SonarQube - which version? jest-sonar-reporter 2.0.0
- SonarLint - which IDE/version?
- in connected mode with SonarQube or SonarCloud?
- How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
I am raising this issue for unnecessary strict assessment of this ( I think it should be minor instead of critical )
the rule link is here: JavaScript static code analysis: Wildcard imports should not be used
while I agree that this should not be used for everytime, I still think this is not a critical but up to developer’s decision.
for example, if I have 2 files which hold a lot of same functions, and I have to import them at the same time, using wildcard is pretty clear to differentiate those functions instead of importing them with bunch of aliases.
// mobile.js
export const clickButton(){...}
export const selectTab(){...}
export const getImageList(){...}
// desktop.js
export const clickButton(){...}
export const selectTab(){...}
export const getImageList(){...}
// app.js
import * as mobile from './mobile'
import * as desktop from './desktop'
const clickButton(){
if(screen === 'mobile') mobile.clickButton();
else if(screen === 'desktop') desktop.clickButton();
}
...
but If we don’t use wildcard, we might need to do something like this:
import {
clickButton as mobileClickButton,
selectTab as mobileSelectTab,
getImageList as mobileGetImageList
}
...
I don’t think above code is cleaner than the first code.
In my opinion, this should be marked a minor rather than critical or should be removed.