Configuring SCSS rule using web service API had no effect

35 views
Skip to first unread message

alix....@gmail.com

unread,
Aug 17, 2017, 10:36:13 AM8/17/17
to SonarQube
Hi,

I have made a configuration tool for our SonarQube instance where we basically reset our rules the way we want them. 
In one particular case I could see that a request did not have any effect (although the server did not return any errors).

These are the details (I've replaced our URL and quality profile id with placeholders ($$) but the rest of the data is exactly the same:

SonarQube version: 5.6.6 (LTS)
Relevant SonarQube plugin: CSS / SCSS / Less 3.1
Rule key: scss:class-selector-naming-convention

Request URL: https://$MY_INSTANCE$/api/qualityprofiles/activate_rule 

Request body (HTML encoded): 
profile_key=$MY_QUALITY_PROFILE_ID$&rule_key=scss%3Aclass-selector-naming-convention&severity=MINOR&params=format%3D%5E.%28_%29%3F%28%5Ba-z%5D%2B-%29%3F%5Ba-z0-9-%5D%2B%28%28_%7B2%7D%7C-%7B2%7D%29%3F%5Ba-z0-9-%5D%2B%29%3F%28-%7B2%7D%5Ba-z0-9-%5D%2B%29%3F%24

Request body (clear text):
profile_key=$MY_QUALITY_PROFILE_ID$&rule_key=scss%3Aclass-selector-naming-convention&severity=MINOR&params=format%3D%5E.%28_%29%3F%28%5Ba-z%5D%2B-%29%3F%5Ba-z0-9-%5D%2B%28%28_%7B2%7D%7C-%7B2%7D%29%3F%5Ba-z0-9-%5D%2B%29%3F%28-%7B2%7D%5Ba-z0-9-%5D%2B%29%3F%24

I'm getting 200 OK from the server but the "format" is not changed... The severity is set/changed correctly though. Any idea what could be wrong?

alix....@gmail.com

unread,
Aug 17, 2017, 10:38:48 AM8/17/17
to SonarQube, alix....@gmail.com
My copy paste was not accurate... For the clear text version this is what I wanted:

 ruleKey=scss:class-selector-naming-convention, priority=MINOR, params=format=^.(_)?([a-z]+-)?[a-z0-9-]+((_{2}|-{2})?[a-z0-9-]+)?(-{2}[a-z0-9-]+)?$]

G. Ann Campbell

unread,
Aug 17, 2017, 10:41:49 AM8/17/17
to SonarQube, alix....@gmail.com
Hi,

Would you share why you felt the need to build a separate tool for rule configuration?

Regarding the formatting of your web services request, the easiest thing to do is submit the same request via the SonarQube UI and use your browser's developer tools to see the format of the request that's submitted.


Ann

alix....@gmail.com

unread,
Aug 17, 2017, 10:53:08 AM8/17/17
to SonarQube, alix....@gmail.com
Hi,

Certainly. What the tools does is to (for each Quality Profile, we typically have one per language):
- Disable all deprecated rules 
- Enable all possible rules that are not deprecated from all rule repositories
- Try to "reset" those that we have not made custom exceptions for (that is, reset the severity to the default severity)
- Configure rules that we have made custom modifications to (for example a decision to change the default severity or set some parameters)

We do this every time we update SonarQube or any of its plugins. Our custom changes are persisted with references to JIRA to have a background as to why we disabled or changed rules. That way we are always up to date and never miss out on any good rule.

Regarding the browser it's difficult since the web service is a POST request, I would need some addtional tool I think to get that in there.

G. Ann Campbell

unread,
Aug 17, 2017, 11:07:38 AM8/17/17
to alix....@gmail.com, SonarQube
Hi,

That's... impressive. :-)

Regarding the format, here's what I was able to see using Chrome's Developer Tools:

The different headers I've highlighted at the bottom toggle the data presentation.

Inline image 1


HTH,
Ann




---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/tD393KnI2qY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/c295e5f2-06e5-4593-9567-2dd2944b5cd7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

alix....@gmail.com

unread,
Aug 18, 2017, 3:13:13 AM8/18/17
to SonarQube, alix....@gmail.com
Hi, since I don't use a browser I cannot get this information.

However, I used an online tool to "de-URL-encode" the form data and this is what I got:

profile_key=$MY_QUALITY_PROFILE_ID$&rule_key=scss:class-selector-naming-convention&severity=MINOR&params=format=^.(_)?([a-z]+-)?[a-z0-9-]+((_{2}|-{2})?[a-z0-9-]+)?(-{2}[a-z0-9-]+)?$
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.

G. Ann Campbell

unread,
Aug 18, 2017, 8:21:39 AM8/18/17
to SonarQube, alix....@gmail.com
Hi Alix,

If you don't use a browser then how did you submit the form?

Anyway, when you submitted, were the changes accepted? 


Ann

alix....@gmail.com

unread,
Aug 18, 2017, 8:29:34 AM8/18/17
to SonarQube, alix....@gmail.com
Hi,

I've made a Java client that uses a network library (Retrofit) to post the change to the Web Service API.
According to the client, the input is accepted (HTTP 200) and it seems to have effect at least on the priority of the bug. But the configuration (format) is not being set properly.

G. Ann Campbell

unread,
Aug 18, 2017, 8:34:23 AM8/18/17
to alix....@gmail.com, SonarQube
Hi Alix,

The point in asking you to submit the values via a browser was so you could see what a successful submission looked like. Or you could show that even through the official UI your particular regex didn't "take".

Perhaps you could ask a colleague with a browser to try this?


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/498d93e1-35c9-4f7d-96d4-713bb75e2d96%40googlegroups.com.

alix....@gmail.com

unread,
Aug 18, 2017, 10:10:56 AM8/18/17
to SonarQube, alix....@gmail.com
Ah. I completely misunderstood what you were after.

Doing the same thing through a browser works fine. This is what it looks like:

  1. severity:
    MINOR
  2. profile_key:
    $MY_QUALITY_PROFILE_ID$
  3. rule_key:
    scss:class-selector-naming-convention
  4. params:
    Format="^.(_)?([a-z]+-)?[a-z0-9-]+((_{2}|-{2})?[a-z0-9-]+)?(-{2}[a-z0-9-]+)?$"

G. Ann Campbell

unread,
Aug 18, 2017, 10:16:05 AM8/18/17
to Alix Warnke, SonarQube
Hi,

Perhaps you should look at the URL-encoded version & try submitting that from your custom client?


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/62a9f204-84d6-4f65-9990-407c4ab55f3c%40googlegroups.com.

alix....@gmail.com

unread,
Aug 18, 2017, 10:29:39 AM8/18/17
to SonarQube, alix....@gmail.com
I've solved it.

The SCSS rule has a config called "Format" instead of "format" (used by squid rules).
Using the correct case solves the issue for me.

I think that it would be good if the Web Service API was stricter and failed on unknown parameters. Anyway, thank you, G. Ann, for your help solving the issue!

/ Alix
Reply all
Reply to author
Forward
0 new messages