string

Note

This target doesn't match any syntactical elements. It is used as an option from another target. In case you want to search for strings in code, take a look at literal.

Sensei allows for both a very simple and very advanced configuration to match text.

Shorthands

As stated before, we can use a very simple string-based configuration to match text. We call these configurations shorthands.

search:
  <target>:
    <option>: Example

Advanced configuration

These shorthand notations are insufficient in certain scenarios. That's why Sensei allows to configure the text-matching in a similar fashion as configuring a target.

is

Performs an equality check. Only configuring this option behaves the same as using the shorthand notation.

search:
  <target>:
    <option>:
      is: "Example"

matches

Performs a regular expression match.

search:
  <target>:
    <option>:
      matches: "Ex.*"

contains

Checks if the text contains a certain substring.

search:
  <target>:
    <option>:
      contains: "Ex"

Generic Configuration options

The following options are generic and available for every target.

anyOf

Similar to the logical operator OR: one or more descendant options should match.

search:
  <target>:
    anyOf:
    - name: "illegal"
    - name: "alsoIllegal"

allOf

Similar to the logical operator AND: all descendant options must match.

search:
  <target>:
    allOf:
    - annotation: "HttpPost"
    - annotation: "AllowUnAuthorized"

with

The only purpose to use this field is to make the recipe easier to read. It provides no additional functionality.

search:
  <target>:
    with:
      annotation: "HttpPost"

not, without

Works as the logical operator NOT. It will negate the result of the descendant options. Sensei presents the user with both options. They display the same behavior, but certain scenarios tend to read better using without.

search:
  <target>:
    not:
      annotation: "HttpPost"
search:
  <target>:
    without:
      annotation: "HttpPost"

in

Performs a structural search, this option is mainly used to narrow down recipes. Examples of this would be to only analyze and mark code inside a certain class or method that has a specific annotation. However, we haven't limited this option to only support these two scenarios. More advanced configuration can be achieved.

search:
  <target>:
    in:
      class:
        name:
          contains: "Controller"
search:
  <target>:
    in:
      method:
        annotation:
          type: "HttpPost"