Validation of parameter of type REGULAR_EXPRESSION not working

Hi,

It looks like a validation is expected for parameters of type REGULAR_EXPRESSION.

 @RuleProperty(
    key = "regex",
    description = "My description",
    type = "REGULAR_EXPRESSION",
    defaultValue = ".+"
  )

But, it does not seem to work…

Thank you

Regards

Nicolas

Hey there.

What doesn’t seem to work? More details (screenshots, logs, error messages), please :slight_smile:

Hi Colin,

When I activate a rule with parameter of type REGULAR_EXPRESSION, I would expect an error message when saving the following because it is not a valid regular expression. But I don’t get any error message.

Validation works for instance for parameters of type INTEGER:

Thank you

Regards

Nicolas

Thanks for clarifying. Indeed, it would be cool if rule parameters checked the validity of RegEx patterns, but that’s not the case today.

It probably wouldn’t be too difficult since we already check for valid patterns when RegEx is set for server settings.

I’ll pass this on as a good idea!

Thanks Colin. There might be some issue in the code of sonar-plugin-api because code for validation seems to be already there: sonar-plugin-api/plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java at master · SonarSource/sonar-plugin-api · GitHub

@pierreguillot Based on the last comment, it seems to be a bug more than a possible improvement, isn’t it?

Yes. @antoine.vinot Can you please have a look here?

Hi folks,

@Chris and @pierreguillot This is not a bug. The code mentioned by @Nicolas_Alcaraz in PropertyDefinition is for the settings properties.
For the Rule params, it is handled in RuleParamType. As we can see there, Regular Expression are just parsed as standard String and we never checked the validity of RegEx before for rule parameters, as mentioned by Colin.

Hi @antoine.vinot,

Thank you for your feedback.
It would be a feature request then :slight_smile:

Thank you

Regards

Nicolas

1 Like

Thanks for the suggestion, @Nicolas_Alcaraz. This is a good idea that we’ll definitely keep in mind.