nx/docs/shared/features/powerpack/conformance.md
Isaac Mann ce7f1b5e4a
docs(core): move powerpack features to enterprise section (#28528)
- Makes a new Enterprise section under the Nx section of the docs
- Moves Powerpack docs into the Enterprise section
2024-10-22 14:53:08 -04:00

3.4 KiB

Run Language-Agnostic Conformance Rules

{% youtube src="https://youtu.be/6wg23sLveTQ" title="Nx Powerpack workspace conformance" /%}

The @nx/powerpack-conformance plugin allows Nx Powerpack users to write and apply rules for your entire workspace that help with consistency, maintainability, reliability and security. Powerpack is available for Nx version 19.8 and higher.

The conformance plugin allows you to encode your own organization's standards so that they can be enforced automatically. Conformance rules can also complement linting tools by enforcing that those tools are configured in the recommended way. The rules are written in TypeScript but can be applied to any language in the codebase or focus entirely on configuration files.

The plugin also provides the following pre-written rules:

Setup

The @nx/powerpack-conformance plugin requires an Nx Powerpack license to function. Activating Powerpack is a simple process.

{% call-to-action title="Buy a Powerpack License" icon="nx" description="Unlock all the features of Nx" url="https://cloud.nx.app/powerpack/purchase" /%}

Then, add the Conformance plugin to your workspace.

{% link-card title="Conformance" type="Nx Plugin" url="/nx-api/powerpack-conformance" icon="CheckBadgeIcon" /%}

Configure Conformance Rules

Conformance rules are configured in the conformance property of the nx.json file. You can use the pre-defined rules or reference your own custom rule. See the plugin documentation for more details.

{
  "conformance": {
    "rules": [
      {
        "rule": "@nx/powerpack-conformance/enforce-project-boundaries",
        "options": {
          "depConstraints": [
            {
              "sourceTag": "scope:shared",
              "onlyDependOnProjectsWithTags": ["scope:shared"]
            }
          ]
        }
      },
      {
        "rule": "@nx/powerpack-conformance/ensure-owners",
        "projects": ["!experimental-app"]
      },
      {
        "rule": "./tools/local-conformance-rule.ts"
      }
    ]
  }
}

Enforce Rules with the nx conformance Command

The @nx/powerpack-conformance plugin enables the nx conformance command which checks all the configured rules. This command should be added to the beginning of your CI process so that the conformance rules are enforced for every PR.

{% tabs %} {% tab label="Without Nx Cloud" %}

- name: Enforce all conformance rules
  run: npx nx conformance

{% /tab %} {% tab label="Using Nx Cloud" %}

- name: Enforce all conformance rules
  run: npx nx-cloud record -- npx nx conformance

Use npx nx-cloud record -- to capture the logs for nx conformance in the Nx Cloud dashboard.

{% /tab %} {% /tabs %}

If there is not a valid Powerpack license in the workspace, the nx conformance command will fail without checking any rules.