Virtual folder not excluded during scanning with SonarLint in Eclipse

I am running Code Composer Studio from Texas Instruments (which is Eclipse based) and using SonarLint which is bind to the SonarQube running on our server. On the server this is triggered with a job in Jenkins and in this job the include paths, exclude paths and exclude files are given as commands.

Because part of the software project is not our in-house developed code we want to exclude these paths, on the server this works like a charm.

But locally with SonarLint this does not work for all paths. I think this is related to the fact that we are using some virtual folders in Eclipse. The reason for using virtual folder is that we have multiple subprojects which are sharing a common code base. Each subproject has virtual folders to this common code to make it part of the subproject. But the excluding of such a virtual folder (or even when excluding each file separately in this virtual folder is ignored).

What else can I try to pinpoint (or even better: solve) this issue?

I see now that I have made a mistake in my original post. Virtual folder should be linked folder. This is a slight difference. I cannot change my original post.

In this project the shared code is included in each sub project with a virtual folder. When I exclude that folder the exclusion in SonarLint works. But I only want to exclude specific linked folder which are placed in this virtual folder. And that doesn’t work.

I have now also tried to exclude this folder in the work space settings but this gives the same result.

Hello Willem.
Welcome to the community and thank you for your feedback.
Also thank you for additional clarification you provided. We are working on your question and will answer as soon as we can.
Best regards.

1 Like

Hi @willemr

If you pass exclusions on the command line in Jenkins, SonarLint has no way to apply the same. We suggest that you move those exclusions to the SonarQube server (in project administration), it will be automatically applied in Eclipse, without having to configure a local exclusion.

Now, if you are using linked folders there is maybe something not working, but I cannot reproduce.
I have create a simple project with 2 files, one is a link to this other. I can exclude the linked file, and it doesn’t affect the other one.

image

I can see issues in foo.js, and not in foo2.js.

Maybe you could try to provide a simple reproducer: a sample project that you put on GitHub, with the steps to reproduce your issue?

This was something I didn’t think of myself but is actually helpful. It makes the command in Jenkins less complex and the settings in SonarQube more clear.

But the results are a bit mixed in SonarLint. It is excluding the folders and files which should be excluding now but it is also missing a lot of issue (like a factor of 10).

Unfortunately it is also not solving the other issue that I am facing and made a separate topic for False positives in SonarLint C++ rules in C header files in Eclipse.

I am not sure if I can find the time for this. But for clarification it is a C project and the structure is as follows:

Project 1
  include
  source
  shared (Linked folder to SharedCode)
     externalCode (Virtual folder of SharedCode/externalCode) 
     internalCode (Virtual folder of SharedCode/internalCode)  
Project 2
  include
  source
  shared (Linked folder to SharedCode)
     externalCode (Virtual folder of SharedCode/externalCode) 
     internalCode (Virtual folder of SharedCode/internalCode)  
SharedCode
   externalCode
   internalCode

So the folder externalCode should be excluded from scanning Project 1 or Project 2 but the folder internalCode should be scanned as folder include and source.

What happens if you configure a SonarLint exclusion in both Project 1 and Project 2 for shared/externalCode?

This is what I already have from the beginning because I am scanning each project individually. I now also tried to exclude the externalCode in the project SharedCode but that also doesn’t help.

Forgot to mention those exclusions are GLOB patterns. Maybe try to add exclusion for shared/externalCode/** or even **/shared/externalCode/**

This is what I didn’t try yet. And yes the GLOB patterns do work!

So in addition to moving the exclusions to the project administration I added file exclusions as GLOB patterns to my projects in the following form
shared/externalCode/** and this works!

I also solved this issue of missing issues. I saw that in the org.sonarlint.eclipse.core.prefs files which are located in each .settings folder of each project something strange was going on.
This was how it was set:

idePrefixKey=shared
sqPrefixKey=SharedCode

Where shared is the linked folder to SharedCode. I have changed this to:

idePrefixKey=
sqPrefixKey=Project1

And then it works just fine. I am not sure why the binding following the wizard did not work for this.

We an Eclipse project is bound to a SonarQube project, we are trying to guess the best subfolder prefix that should be applied/removed to convert local paths to server side paths. If locally you are using virtual folders, to create a hierarchy of folders that is totally different than the one on the server, then this strategy will not work.
Not sure of what we can do here.

Manually changing idePrefixKey and sqPrefixKey is a possible workaround, but those settings will be overridden each time you update the project binding.

Anyway I’m glad you managed to make it work.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.