PyCharm ignores sonar-project.properties when running in bound mode

Please provide

  • Operating system: MacOS
  • SonarQube for IntelliJ plugin version: 10.19.0.80823
  • PyCharm version: 2024.3.5
  • Programming language you’re coding in: Python
  • Is connected mode used: Yes - SonarQube Server Enterprise Edition Version 10.3 (build 82913)

Our enterprise provides a SonarQube server for multiple projects to use, we are not permitted to update the rules so we make use of sonar-project.properties to ignore rules. PyCharm when bound to the server does not honor those properties so all the rules we ignored should up, and since it is bound turning the rules off in PyCharm configuration has no effect.

1 Like

Hi,

Welcome to the community!

Can you explain how you’re ignoring rules using sonar-project.properties?

 
Thx,
Ann

Sure we are ignoring 4 rules

# Comma-delimited list of ignored code smell rules
# https://sonarqube.accenturefederaldev.com/coding_rules?languages=py&selected=python
# https://docs.sonarsource.com/sonarcloud/advanced-setup/analysis-scope/#rule-key-pattern
sonar.issue.ignore.multicriteria=e1,e2,e3,e4
# python:S117 Local variable and function parameter names should comply with a naming convention
sonar.issue.ignore.multicriteria.e1.ruleKey=python:S117
sonar.issue.ignore.multicriteria.e1.resourceKey=**/*.py

# python:S116 Field names should comply with a naming convention
sonar.issue.ignore.multicriteria.e2.ruleKey=python:S116
sonar.issue.ignore.multicriteria.e2.resourceKey=**/*.py

# python:S1542 Function names should comply with a naming convention
sonar.issue.ignore.multicriteria.e3.ruleKey=python:S1542
sonar.issue.ignore.multicriteria.e3.resourceKey=**/*.py

# python:S100 Method names should comply with a naming convention
sonar.issue.ignore.multicriteria.e4.ruleKey=python:S100
sonar.issue.ignore.multicriteria.e4.resourceKey=**/*.py

Hi,

Thanks for sharing the configuration file. I guess what I was asking was: are you expecting it to be picked up automatically, or did you try to configure its use somehow?

 
Thx,
Ann

If I don’t have the project bound to Sonar then the properties file is picked up and the excluded rules are excluded with no custom config on my part. When I bind to the server the the properties file is not picked up.

On the Sonar Server it is making use of the properties file so the ignored items are properly ignored.

Hi,

This is expected. When you’re in connected mode, one of the features is that the settings saved on the server are applied in-IDE. This includes Quality Profiles and things like exclusions.

Running analysis with exclusions specified in a properties file applies them for that analysis. It does not save them server-side. And thus, they’re not there to be applied in connected mode.

 
HTH,
Ann

So that is where I’m stuck. I’m prohibited from modifying the server which is why I’m using the properties file. But that makes binding in the IDE useless since all the ignored rules show up.

If I unbind I loose the benefit of some of the other checks but I guess I don’t have a see of highlighted warnings.

Hi,

Can you buy the project admin a coffee? :wink:

 
Ann

1 Like

I’d probably have better luck buying someone here a coffee.

1 Like

Hello,
I have the same problem, although I’m using IntelliJ IDEA and not PyCharm.

However, I’m not sure I’ve understood what is the “expected” behavior of this plugin, or at least the rationale behind it.

In my company, we have a SonarQube server, where all our projects are scanned. If I log into the SonarQube server web UI, I can see the results of the scan. These results are honoring what I’ve written in the sonar-project.properties file, including rule exclusions, and whatsoever. Moreover, I can mark issues as "false positive"s or “won’t fix”, etc.

Then, I installed the plugin, so that I can intercept issues earlier compared to the current workflow (which is: push to our git repository, this triggers a CI build with Jenkins, which in turn triggers an updated scan on the SonarQube server, where I can see the results). So, I connected the plugin to our SonarQube server hoping that what I see on the web UI is exactly what I will see in the IDE. But, because of this problem, it seems it’s not the case. So I was wondering what is the “right” way of using this plugin to get the exact same reporting I get on the server (+ earlier feedback when I have outgoing changes pending).

What am I missing of the whole picture?

1 Like

Hi @mauromol,

This is a precedence quesiton.

When you connect SonarQube for IDE to SonarQube Server / Cloud, our understanding is that you want to apply the data at the server to your local experience. So the remote settings take precedence over your local ones.

On the other hand, during analysis, we follow a last-saved-wins sort of model, and give the values set most closely to the analysis command the highest precedence (diagram here).

And once I’ve said it that way, I do see the contradiction.

I’ve flagged this for the PMs, but I wouldn’t hold my breath if I were you.

In the meantime, your best bet is to have a project admin apply on the server the values you’ve set in your properties file.

 
Ann

Thank you very much Ann for the explanation.

So, this sounds like a design flaw to me, or at least it makes the IDE plugin work in a different way compared to what was our expectation (i.e.: to see exactly the same results of analysis conducted on the server, but in the IDE, so earlier). I’m not sure I understand the benefits of the current approach. The main problem here, after talking about this with our operation team, is that changing the server settings for all our projects (which are countless) is not sustainable and goes against the advantage and transparency given by persisting the configuration-as-code in git along with each project.

Hi,

You’re making the assumption there’s a grand, cohesive design here :joy:

These things were built at different times, with different goals in the moment.

And yes, what you’re saying makes sense.

 
Ann

2 Likes