-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(linter): add documentation on dependency-checks rule (#17962)
- Loading branch information
Showing
11 changed files
with
201 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
docs/generated/packages/eslint-plugin/documents/dependency-checks.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Dependency Checks rule | ||
|
||
The `@nx/dependency-checks` ESLint rule enables you to discover mismatches between dependencies specified in a project's `package.json` and the dependencies that your project depends on. If your project is using, for example, the `axios`, but the `package.json` does not specify it as a dependency, your library might not work correctly. This rule helps catch these problems before your users do. | ||
|
||
The rule uses the project graph to collect all the dependencies of your project, based on the input of your `build` target. It will filter out all the dependencies marked as `devDependencies` in your root `package.json` to ensure dependencies of your compilation pipelines (e.g. dependencies of `webpack.config` or `vite.config`) or test setups are not included in the expected list. | ||
|
||
We use the version numbers of the installed packages when checking whether the version specifier in `package.json` is correct. We do this because this is the only version for which we can "guarantee" that things work and were tested. If you specify a range outside of that version, that would mean that you are shipping potentially untested code. | ||
|
||
## Usage | ||
|
||
You can use the `dependency-checks` rule by adding it to your ESLint rules configuration: | ||
|
||
```jsonc {% fileName=".eslintrc.json" %} | ||
{ | ||
// ... more ESLint config here | ||
"overrides": [ | ||
{ | ||
"files": ["*.json"], | ||
"parser": "jsonc-eslint-parser", | ||
"rules": { | ||
"@nx/dependency-checks": "error" | ||
} | ||
} | ||
// ... more ESLint overrides here | ||
] | ||
} | ||
``` | ||
|
||
Linting `JSON` files is not enabled by default, so you will also need to add `package.json` to the `lintFilePatterns`: | ||
|
||
```jsonc {% fileName="project.json" %} | ||
{ | ||
// ... project.json config | ||
"targets": { | ||
// ... more targets | ||
"lint": { | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"libs/my-lib/**/*.{ts,tsx,js,jsx}", | ||
"libs/my-lib/package.json" // add this line | ||
] | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Sometimes we intentionally want to add or remove a dependency from our `package.json` despite what the rule suggests. We can use the rule's options to override default behavior: | ||
|
||
```jsonc {% fileName=".eslintrc.json" %} | ||
{ | ||
"@nx/dependency-checks": [ | ||
"error", | ||
{ | ||
// for available options check below | ||
} | ||
] | ||
} | ||
``` | ||
|
||
## Options | ||
|
||
| Property | Type | Default | Description | | ||
| ------------------------- | --------------- | ----------- | ----------------------------------------------------------------------- | | ||
| buildTargets | _Array<string>_ | _["build"]_ | List of build target names | | ||
| ignoredDependencies | _Array<string>_ | _[]_ | List of dependencies to ignore for checks | | ||
| checkMissingDependencies | _boolean_ | _true_ | Disable to skip checking for missing dependencies | | ||
| checkObsoleteDependencies | _boolean_ | _true_ | Disable to skip checking for unused dependencies | | ||
| checkVersionMismatches | _boolean_ | _true_ | Disable to skip checking if version specifier matches installed version | |
2 changes: 2 additions & 0 deletions
2
docs/generated/packages/eslint-plugin/documents/enforce-module-boundaries.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Dependency Checks rule | ||
|
||
The `@nx/dependency-checks` ESLint rule enables you to discover mismatches between dependencies specified in a project's `package.json` and the dependencies that your project depends on. If your project is using, for example, the `axios`, but the `package.json` does not specify it as a dependency, your library might not work correctly. This rule helps catch these problems before your users do. | ||
|
||
The rule uses the project graph to collect all the dependencies of your project, based on the input of your `build` target. It will filter out all the dependencies marked as `devDependencies` in your root `package.json` to ensure dependencies of your compilation pipelines (e.g. dependencies of `webpack.config` or `vite.config`) or test setups are not included in the expected list. | ||
|
||
We use the version numbers of the installed packages when checking whether the version specifier in `package.json` is correct. We do this because this is the only version for which we can "guarantee" that things work and were tested. If you specify a range outside of that version, that would mean that you are shipping potentially untested code. | ||
|
||
## Usage | ||
|
||
You can use the `dependency-checks` rule by adding it to your ESLint rules configuration: | ||
|
||
```jsonc {% fileName=".eslintrc.json" %} | ||
{ | ||
// ... more ESLint config here | ||
"overrides": [ | ||
{ | ||
"files": ["*.json"], | ||
"parser": "jsonc-eslint-parser", | ||
"rules": { | ||
"@nx/dependency-checks": "error" | ||
} | ||
} | ||
// ... more ESLint overrides here | ||
] | ||
} | ||
``` | ||
|
||
Linting `JSON` files is not enabled by default, so you will also need to add `package.json` to the `lintFilePatterns`: | ||
|
||
```jsonc {% fileName="project.json" %} | ||
{ | ||
// ... project.json config | ||
"targets": { | ||
// ... more targets | ||
"lint": { | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"libs/my-lib/**/*.{ts,tsx,js,jsx}", | ||
"libs/my-lib/package.json" // add this line | ||
] | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Sometimes we intentionally want to add or remove a dependency from our `package.json` despite what the rule suggests. We can use the rule's options to override default behavior: | ||
|
||
```jsonc {% fileName=".eslintrc.json" %} | ||
{ | ||
"@nx/dependency-checks": [ | ||
"error", | ||
{ | ||
// for available options check below | ||
} | ||
] | ||
} | ||
``` | ||
|
||
## Options | ||
|
||
| Property | Type | Default | Description | | ||
| ------------------------- | --------------- | ----------- | ----------------------------------------------------------------------- | | ||
| buildTargets | _Array<string>_ | _["build"]_ | List of build target names | | ||
| ignoredDependencies | _Array<string>_ | _[]_ | List of dependencies to ignore for checks | | ||
| checkMissingDependencies | _boolean_ | _true_ | Disable to skip checking for missing dependencies | | ||
| checkObsoleteDependencies | _boolean_ | _true_ | Disable to skip checking for unused dependencies | | ||
| checkVersionMismatches | _boolean_ | _true_ | Disable to skip checking if version specifier matches installed version | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5af5e6c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nx-dev – ./
nx.dev
nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx-dev-nrwl.vercel.app