Skip to content

Commit

Permalink
docs(nx-dev): update conformance docs (#28151)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry authored Sep 27, 2024
1 parent 2630e7f commit 81b3fc9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The conformance plugin allows you to encode your own organization's standards so

The plugin also provides the following pre-written rules:

- [**Enforce Module Boundaries**](#enforce-module-boundaries): Similar to the Nx [ESLint Enforce Module Boundaries rule](/features/enforce-module-boundaries), but enforces the boundaries on every project dependency, not just those created from TypeScript imports or `package.json` dependencies.
- [**Enforce Project Boundaries**](#enforce-project-boundaries): Similar to the Nx [ESLint Enforce Module Boundaries rule](/features/enforce-module-boundaries), but enforces the boundaries on every project dependency, not just those created from TypeScript imports or `package.json` dependencies.
- [**Ensure Owners**](#ensure-owners): Require every project to have an owner defined for the [`@nx/powerpack-owners` plugin](/nx-api/powerpack-owners)

{% callout title="This plugin requires an active Nx Powerpack license" %}
Expand Down Expand Up @@ -63,7 +63,7 @@ Use `npx nx-cloud record --` to capture the logs for `nx conformance` in the Nx
/**
* Relative path to a local rule implementation or node_module path.
*/
"rule": "@nx/powerpack-conformance/enforce-module-boundaries";
"rule": "@nx/powerpack-conformance/enforce-project-boundaries";
/**
* Rule specific configuration options. (Optional)
*/
Expand All @@ -82,18 +82,18 @@ Use `npx nx-cloud record --` to capture the logs for `nx conformance` in the Nx

The following rules are provided by Nx along with the `@nx/powerpack-conformance` plugin.

### Enforce Module Boundaries
### Enforce Project Boundaries

This rule is similar to the Nx [ESLint Enforce Module Boundaries rule](/features/enforce-module-boundaries), but enforces the boundaries on every project dependency, not just those created from TypeScript imports or `package.json` dependencies.

Set the `rule` property to: `@nx/powerpack-conformance/enforce-module-boundaries`
Set the `rule` property to: `@nx/powerpack-conformance/enforce-project-boundaries`

```json {% fileName="nx.json" %}
{
"conformance": {
"rules": [
{
"rule": "@nx/powerpack-conformance/enforce-module-boundaries",
"rule": "@nx/powerpack-conformance/enforce-project-boundaries",
"options": {
// Optional
// Can be a boolean or an object with an array of buildTargetNames
Expand All @@ -110,9 +110,9 @@ Set the `rule` property to: `@nx/powerpack-conformance/enforce-module-boundaries
"sourceTag": "string",
"allSourceTags": ["string"],
// Optional
"onlyDependOnLibsWithTags": [],
"onlyDependOnProjectsWithTags": [],
// Optional
"notDependOnLibsWithTags": []
"notDependOnProjectsWithTags": []
}
],
// Optional
Expand All @@ -130,7 +130,7 @@ Set the `rule` property to: `@nx/powerpack-conformance/enforce-module-boundaries
| ------------------------------------------------ | ------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ignoredCircularDependencies | _Array<[string, string]>_ | _[]_ | List of project pairs that should be skipped from `Circular dependencies` checks, including the self-circular dependency check. E.g. `['feature-project-a', 'myapp']`. Project name can be replaced by catch all `*` for more generic matches. |
| checkDynamicDependenciesExceptions | _Array<string>_ | _[]_ | List of imports that should be skipped for `Imports of lazy-loaded libraries forbidden` checks. E.g. `['@myorg/lazy-project/component/*', '@myorg/other-project']` |
| requireBuildableDependenciesForBuildableProjects | _boolean_ | _false_ | Enable to restrict the buildable libs from importing non-buildable libraries |
| requireBuildableDependenciesForBuildableProjects | _boolean_ | _false_ | Enable to restrict the buildable projects from importing non-buildable libraries |
| depConstraints | _Array<object>_ | _[]_ | List of dependency constraints between projects |

#### Dependency constraints
Expand All @@ -139,12 +139,12 @@ The `depConstraints` is an array of objects representing the constraints defined
constraint must include `sourceTag` or `allSourceTags`. The constraints are applied with **AND** logical operation - for
a given `source` project the resulting constraints would be **all** that match its tags.

| Property | Type | Description |
| ------------------------ | --------------- | ---------------------------------------------------------------------------------- |
| sourceTag | _string_ | Tag that source project must contain to match the constraint |
| allSourceTags | _Array<string>_ | List of tags the source project must contain to match the constraint |
| onlyDependOnLibsWithTags | _Array<string>_ | The source **can depend only** on projects that contain at least one of these tags |
| notDependOnLibsWithTags | _Array<string>_ | The source **can not depend** on projects that contain at least one of these tags |
| Property | Type | Description |
| ---------------------------- | --------------- | ---------------------------------------------------------------------------------- |
| sourceTag | _string_ | Tag that source project must contain to match the constraint |
| allSourceTags | _Array<string>_ | List of tags the source project must contain to match the constraint |
| onlyDependOnProjectsWithTags | _Array<string>_ | The source **can depend only** on projects that contain at least one of these tags |
| notDependOnProjectsWithTags | _Array<string>_ | The source **can not depend** on projects that contain at least one of these tags |

### Ensure Owners

Expand Down
6 changes: 3 additions & 3 deletions docs/shared/features/powerpack/conformance.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The conformance plugin allows you to **encode your own organization's standards*

The plugin also provides the following pre-written rules:

- **Enforce Module Boundaries**: Similar to the Nx [ESLint Enforce Module Boundaries rule](/features/enforce-module-boundaries), but enforces the boundaries on every project dependency, not just those created from TypeScript imports or `package.json` dependencies.
- **Enforce Project Boundaries**: Similar to the Nx [ESLint Enforce Module Boundaries rule](/features/enforce-module-boundaries), but enforces the boundaries on every project dependency, not just those created from TypeScript imports or `package.json` dependencies.
- **Ensure Owners**: Require every project to have an owner defined for the [`@nx/powerpack-owners` plugin](/nx-api/powerpack-owners)

## Setup
Expand All @@ -30,12 +30,12 @@ Conformance rules are configured in the `conformance` property of the `nx.json`
"conformance": {
"rules": [
{
"rule": "@nx/powerpack-conformance/enforce-module-boundaries",
"rule": "@nx/powerpack-conformance/enforce-project-boundaries",
"options": {
"depConstraints": [
{
"sourceTag": "scope:shared",
"onlyDependOnLibsWithTags": ["scope:shared"]
"onlyDependOnProjectsWithTags": ["scope:shared"]
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The conformance plugin allows you to encode your own organization's standards so

The plugin also provides the following pre-written rules:

- [**Enforce Module Boundaries**](#enforce-module-boundaries): Similar to the Nx [ESLint Enforce Module Boundaries rule](/features/enforce-module-boundaries), but enforces the boundaries on every project dependency, not just those created from TypeScript imports or `package.json` dependencies.
- [**Enforce Project Boundaries**](#enforce-project-boundaries): Similar to the Nx [ESLint Enforce Module Boundaries rule](/features/enforce-module-boundaries), but enforces the boundaries on every project dependency, not just those created from TypeScript imports or `package.json` dependencies.
- [**Ensure Owners**](#ensure-owners): Require every project to have an owner defined for the [`@nx/powerpack-owners` plugin](/nx-api/powerpack-owners)

{% callout title="This plugin requires an active Nx Powerpack license" %}
Expand Down Expand Up @@ -63,7 +63,7 @@ Use `npx nx-cloud record --` to capture the logs for `nx conformance` in the Nx
/**
* Relative path to a local rule implementation or node_module path.
*/
"rule": "@nx/powerpack-conformance/enforce-module-boundaries";
"rule": "@nx/powerpack-conformance/enforce-project-boundaries";
/**
* Rule specific configuration options. (Optional)
*/
Expand All @@ -82,18 +82,18 @@ Use `npx nx-cloud record --` to capture the logs for `nx conformance` in the Nx

The following rules are provided by Nx along with the `@nx/powerpack-conformance` plugin.

### Enforce Module Boundaries
### Enforce Project Boundaries

This rule is similar to the Nx [ESLint Enforce Module Boundaries rule](/features/enforce-module-boundaries), but enforces the boundaries on every project dependency, not just those created from TypeScript imports or `package.json` dependencies.

Set the `rule` property to: `@nx/powerpack-conformance/enforce-module-boundaries`
Set the `rule` property to: `@nx/powerpack-conformance/enforce-project-boundaries`

```json {% fileName="nx.json" %}
{
"conformance": {
"rules": [
{
"rule": "@nx/powerpack-conformance/enforce-module-boundaries",
"rule": "@nx/powerpack-conformance/enforce-project-boundaries",
"options": {
// Optional
// Can be a boolean or an object with an array of buildTargetNames
Expand All @@ -110,9 +110,9 @@ Set the `rule` property to: `@nx/powerpack-conformance/enforce-module-boundaries
"sourceTag": "string",
"allSourceTags": ["string"],
// Optional
"onlyDependOnLibsWithTags": [],
"onlyDependOnProjectsWithTags": [],
// Optional
"notDependOnLibsWithTags": []
"notDependOnProjectsWithTags": []
}
],
// Optional
Expand All @@ -130,7 +130,7 @@ Set the `rule` property to: `@nx/powerpack-conformance/enforce-module-boundaries
| ------------------------------------------------ | ------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ignoredCircularDependencies | _Array<[string, string]>_ | _[]_ | List of project pairs that should be skipped from `Circular dependencies` checks, including the self-circular dependency check. E.g. `['feature-project-a', 'myapp']`. Project name can be replaced by catch all `*` for more generic matches. |
| checkDynamicDependenciesExceptions | _Array<string>_ | _[]_ | List of imports that should be skipped for `Imports of lazy-loaded libraries forbidden` checks. E.g. `['@myorg/lazy-project/component/*', '@myorg/other-project']` |
| requireBuildableDependenciesForBuildableProjects | _boolean_ | _false_ | Enable to restrict the buildable libs from importing non-buildable libraries |
| requireBuildableDependenciesForBuildableProjects | _boolean_ | _false_ | Enable to restrict the buildable projects from importing non-buildable libraries |
| depConstraints | _Array<object>_ | _[]_ | List of dependency constraints between projects |

#### Dependency constraints
Expand All @@ -139,12 +139,12 @@ The `depConstraints` is an array of objects representing the constraints defined
constraint must include `sourceTag` or `allSourceTags`. The constraints are applied with **AND** logical operation - for
a given `source` project the resulting constraints would be **all** that match its tags.

| Property | Type | Description |
| ------------------------ | --------------- | ---------------------------------------------------------------------------------- |
| sourceTag | _string_ | Tag that source project must contain to match the constraint |
| allSourceTags | _Array<string>_ | List of tags the source project must contain to match the constraint |
| onlyDependOnLibsWithTags | _Array<string>_ | The source **can depend only** on projects that contain at least one of these tags |
| notDependOnLibsWithTags | _Array<string>_ | The source **can not depend** on projects that contain at least one of these tags |
| Property | Type | Description |
| ---------------------------- | --------------- | ---------------------------------------------------------------------------------- |
| sourceTag | _string_ | Tag that source project must contain to match the constraint |
| allSourceTags | _Array<string>_ | List of tags the source project must contain to match the constraint |
| onlyDependOnProjectsWithTags | _Array<string>_ | The source **can depend only** on projects that contain at least one of these tags |
| notDependOnProjectsWithTags | _Array<string>_ | The source **can not depend** on projects that contain at least one of these tags |

### Ensure Owners

Expand Down Expand Up @@ -183,17 +183,13 @@ To write your own conformance rule, specify a relative path to a TypeScript or J
The rule definition file should look like this:

```ts {% fileName="tools/local-conformance-rule.ts" %}
import type {
ConformanceRule,
ConformanceRuleResult,
createConformanceRule,
} from '@nx/powerpack-conformance';
import type { createConformanceRule } from '@nx/powerpack-conformance';
const rule = createConformanceRule({
name: 'local-conformance-rule-example',
category: 'security', // `consistency`, `maintainability`, `reliability` or `security`
reporter: 'project-reporter', // `project-reporter` or `project-files-reporter`
implementation: async (context): Promise<ConformanceRuleResult> => {
implementation: async (context) => {
const { projectGraph, ruleOptions } = context;
// Your rule logic goes here
return {
Expand Down

0 comments on commit 81b3fc9

Please sign in to comment.