
org.sonar.l10n.yaml.rules.yaml.ForbiddenValueCheck.html Maven / Gradle / Ivy
Show all versions of sonar-yaml-plugin Show documentation
Use this rule to control that the YAML documents do not contain a scalar value. Forbidden values can
be defined as a regular expression. That can be globally forbidden (for any key) or forbidden for a specific key
(also identifiable with a regular expression). The location of the key can be defined with two ancestor regular expressions.
Parameters
- key-name
- Regular expression that matches keys for which the value is forbidden. In order to match any key, set it to
.*
. The start and end line markers ^
and $
are implicit: this means that
setting foo
is equivalent to ^foo$
.
- included-ancestors
- Regular expression that matches against an ancestor string made of joining the parent chain of the matching key.
The parents are separated by a colon (
:
) and always start with an implicit <root>
parent.
So, the ancestor string for a connectionTimeout key could be: <root>:spring:datasource:hikari
.
If the includedAncestors regex matches the ancestor string of the key, the value is checked.
The start and end line markers ^
and $
are implicit, just like the key regex.
Leave empty for no included ancestor matching.
- excluded-ancestors
- Regular expression that matches against the ancestor string of the matching key, just like above.
However, if this regex matches, the value is *not* checked.
The start and end line markers
^
and $
are implicit, just like the key regex.
Leave empty for no excluded ancestor matching.
- value
- Regular expression that matches forbidden values. This regex will be checked against all lines of multiline
values. As a consequence and contrary to the
key-name
parameter, if you want to match a single word
you must use the start and end line markers ^
and $
. For example, if you set foo
as the regular expression then any value containing the "foo" word will be caught, whereas ^foo$
will match only the values that are exactly foo
.
Setting .*
would have the same effect as the rule ForbiddenKeyCheck
.
Examples
With key-name = [tT]e.*t
and value = ^forbi.*en$
the following code snippet would PASS:
Test: any forbidden value
tesT: {key1: 4, key2: forbidden}
the following code snippets would FAIL:
Test: forbidden
test: forbi anything in between
Test: {key1: 4, forbidden: forbidden}
With key-name = [tT]e.*t
and value = .*forbidden.*
or value = forbidden
the following code snippet would PASS:
Test: any value
tesT: {key1: 4, key2: forbidden}
the following code snippets would FAIL:
Test: any forbidden value
tesT: {key1: 4, forbidden: forbidden}
test: >
with
a forbidden
value
test: |
with
a forbidden
value
With key-name = .*
and value = ^forbi.*en$
the following code snippet would PASS:
foo: any forbidden value
Bar: {key1: 4, key2: 8}
the following code snippets would FAIL:
foo: forbidden
Bar: forbi anything in between
Bar: {key1: 4, key2: forbidden}
With key-name = [tT]e.*t
and value = .*
the following code snippet would PASS:
Test1: value
tesT: {key1: 4, key2: 8}
the following code snippets would FAIL:
test: value
tesT: {Test: 4, key2: 8}