Workspace.Checks.ValidateProject (Workspace v0.2.1)

View Source

Checks that the given project is valid

This is a generic check since you can define any arbitrary check for the given project.

It expects an anonymous of arity 1 to be provided that will accept a Workspace.Project as input.

Common use cases

This check can be used to verify any high level setting of your Mix projects like:

  • Ensure that the test coverage threshold is above a limit
  • A package maintainer is defined
  • All projects have a description set

Configuration

  • :validate (function of arity 1) - Required. An anonymous function of arity 1 for validating a workspace project. The project's struct is passed as input to the user provided function. It must return one of:
    • {:ok, message :: String.t()} in case of success
    • {:error, message :: String.t()} in case of error

Example

In order to configure this check add the following, under checks, in your .workspace.exs:

[
  module: Workspace.Checks.ValidateProject,
  description: "all projects must have elixir version set to 1.13",
  opts: [
    validate: fn config ->
      case config[:elixir] do
        "~> 1.13" -> {:ok, "elixir version set to 1.13"}
        other -> {:error, "wrong elixir version, expected 1.13, got #{other}"}
      end
    end
  ]
]