Skip to content

Configuring Sourcery

You can configure Sourcery to fit your needs and to give you the recommendations and reviews you need to see when you want to see them.

Sourcery Configuration File

Sourcery reads configuration settings from .sourcery.yaml in the project directory.

The config file uses YAML syntax. If you are new to YAML checkout "Learn YAML in 5 minutes".

Here is the default set of values set for the file. If a config file isn't set or if a setting isn't specified then Sourcery will use these values:

ignore: []

  skip: []

  quality_threshold: 25.0

  min_lines: 3
  min_duplicates: 2
  identical_clones_only: false

  labels: []
  ignore_labels: [sourcery-ignore]
  request_review: author
  sourcery_branch: sourcery/{base_branch}

Here is the full list of configurable settings

Ignoring Paths or Files

Any path or file you specify to be ignored will be ignored both in your IDE & in GitHub. You will not see refactoring suggestions in any of these files.

By default any files in the path .github/workflows/* will be ignored within GitHub as third party GitHub applications can't update the workflows folder.

Add paths or files as items in a list underneath the ignore setting.

For example:

  - data/*
  - .venv/*
  - '*'  # Note that any strings beginning with * must be quoted

Skipping Types of Refactorings

You can tell Sourcery to never suggest a specific refactoring type to you. Specify a list of refactoring IDs under the refactor - skip section of the config file.

Individual refactoring ids are displayed in the plugin suggestions and GitHub Bot comments for easy lookup or you can find a full list in the refactorings section of the docs.

For example:

    - assign-if-exp
    - de-morgan
Would make it so Sourcery never shows you the Assign If Expression and De Morgan's Identity refactorings.

For more details on skipping or ignoring refactorings (including skipping single instances of a refactoring) check out our section on customizing refactorings

Setting Metrics Thresholds

Sourcery's code quality metrics will show a warning in your IDE if the quality score for a function drops below a certain threshold. By

Note - You can control whether or not Sourcery's metrics are displayed in your IDE by toggling the switch within the IDE plugin settings.

By default the warnings will appear if a function's score drops below 25. Changing the value in the metrics - quality threshold section of the config will change this threshold

For example:

  quality_threshold: 30.0

GitHub Specific Configuration Options

There are a number of GitHub specific configuration options you can set. All of these are nested under the github section of the config file.

Ignore Labels

You can set a configuration to ignore pull requests that have certain labels.

These labels are tracked as a list under ignore_labels: For example:

    - sourcery-ignore
This configuration setting would ignore all new pull requests tagged with the label sourcery-ignore

Add Labels

You can set custom labels that will be attached to all pull requests created by Sourcery.

These can be used to tell other automations to ignore Sourcery's PRs.

These labels are tracked as a list under labels: For example:

    - build-ignore

Request Reviews

You can automatically trigger Sourcery PRs to request a review from a certain person. The possible set of values for this configuration are:

  • author - The author of the original PR or the sender of the refactoring request. This is the default
  • none - No review is requested
  • owner - The owner of the base repository. This option is not valid for organizations
  • username - A specific user
  • org/teamname - A specific team within an organization

You can have one value that will apply to both origin and forked PRs:

  request_review: owner

Or you can specify separate values for origin and forked PRs:

    origin: owner
    forked: author

Sourcery Branch Name

You can set a default name for the branch of Sourcery pull requests.

This setting must contain `{base_branch} which will be replaced with the branch name on theoriginal pull request.

For example:

  sourcery_branch: sourcery/{base_branch}

Advanced Features

For refactorings related to the detect clones feature please see our section on Advanced Features

Back to top