Ignore a particular rule in React TypeScript framework

Sonar Version:

  • Data Center Edition
  • Version 7.9.1 (build 27448)
  • LGPL v3

Issue:
Seeing code smell error - typescript:S4328

Details:
Dependencies should be explicit

Dependencies should be explicitly listed in the package.json file. Importing a module that is not declared as a dependency makes it an implicit one and is bound to create problems.

Need Help:
Above dependency need to be imported in individual files. Ask is to ignore this rule within code base. We have approx. 150 developers working on multiple projects with the same parent project. So //NoSonar will not work.

We do have a sonar file with some exclusions like
“sonar.test.inclusions”: "${relDirname}/**/__tests__/**",
“sonar.exclusions”:
“**/*.abc.tsx, **/jest.config.js, /abc-api/”,

Please suggest the format to add a line to ignore typescript:S4328 or any other way.
Thanks in advance,
Sowmya

Howdy Sowmya,

Thanks for the question. It looks like you want to Ignore an Issue on Multiple Criteria.

To do that navigate to Administration > General Settings > Analysis Scope > Issues and scroll down to the section “Ignore Issues on Multiple Criteria” - you should be able to enter something like the image shown below.

I believe that this setting can only be set in the UI.

The other approach would be to remove this rule from the Quality Profile, but I think your initial instinct to ignore the issue raised during analysis in a more targeted way is probably better.

I hope that helps, let me know if you have any other questions.

thanks,
Aaron

Thanks Aaron,

Will try and let you know in case of further clarifications. I was wondering if we can do internally within the code base.

Regards,
Sowmya

Hi Aaron,

Turns out that none of us has Admin rights and can’t fix through Sonar UI Administration > General Settings > Analysis Scope > Issues

Is there any solution through code that you can suggest?

Thanks,
Sowmya