Run Language-Agnostic Conformance Rules

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.

Buy a Powerpack LicenseUnlock all the features of Nx

Then, add the Conformance plugin to your workspace.

Nx Plugin

Conformance

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.

nx.json
1{ 2 "conformance": { 3 "rules": [ 4 { 5 "rule": "@nx/powerpack-conformance/enforce-project-boundaries", 6 "options": { 7 "depConstraints": [ 8 { 9 "sourceTag": "scope:shared", 10 "onlyDependOnProjectsWithTags": ["scope:shared"] 11 } 12 ] 13 } 14 }, 15 { 16 "rule": "@nx/powerpack-conformance/ensure-owners", 17 "projects": ["!experimental-app"] 18 }, 19 { 20 "rule": "./tools/local-conformance-rule.ts" 21 } 22 ] 23 } 24} 25

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.

1- name: Enforce all conformance rules 2 run: npx nx conformance 3

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