commonality-checks-recommended
v0.0.40
Published
Checks that encourage best practices for most multi-package monorepos.
Downloads
1,796
Readme
commonality-checks-recommended
These checks that benefit most multi-package projects. This package also provides some composable checks that can be used to enforce existing conventions within your project.
Installation
npm install commonality-checks-recommended
Usage
{
"$schema": "https://commonality.co/config.json",
"checks": {
"*": [
"recommended/has-codeowner",
"recommended/has-readme",
"recommended/sorted-dependencies"
]
}
}
Static checks
These checks don't require any configuration and can be used directly within your project configuration (.commonality/config.json
).
recommended/has-codeowner
⚠️ Warning
Ensures that a package has at least one codeowner as determined by the CODEOWNERS
file. It is important to have a codeowner for each package to ensure that there is a responsible person for the maintenance and updates of the package.
{
"checks": [
"*": [
"recommended/has-codeowner"
]
]
}
recommended/has-readme
⚠️ Warning
Ensures that a package has a README.md file.
Auto-fix:
A README.md
file will be created in the package directory with the title and description of the package as well as an installation script.
{
"checks": [
"*": [
"recommended/has-readme"
]
]
}
recommended/valid-package-name
❌ Error
Ensures that the package name in a package's package.json
file is valid. This will prevent unforeseen issues when publishing packages.
{
"checks": [
"*": [
"recommended/valid-package-name"
]
]
}
recommended/sorted-dependencies
⚠️ Warning
Ensures that the dependencies in a package's package.json
file are sorted alphabetically. Some package managers will sort dependencies automatically on dependency installation, sorting ahead of time will decrease the size of diffs.
Auto-fix:
dependencies
, devDependencies
, and peerDependencies
will be sorted in alphabetical order.
{
"checks": [
"*": [
"recommended/sorted-dependencies"
]
]
}
recommended/extends-repository-field
❌ Error
Ensures that the repository field in the package.json of a package extends the repository field at the root of your project. If there is no repository field in your project's root package.json
then this check will always pass.
Auto-fix:
A repository
field will be added to the package's package.json
with the correct path to the package.
{
"checks": [
"*": [
"recommended/extends-repository-field"
]
]
}
recommended/consistent-external-version
❌ Error
Ensures that the external dependencies of a package match the most common or highest version across all packages.
Auto-fix:
Dependency versions will be updated to match the most common or highest version of a dependency across all packages in the workspace.
{
"checks": [
"*": [
"recommended/consistent-external-version"
]
]
}
recommended/unique-dependency-types
⚠️ Warning
Ensures that a dependency should only be in one of dependencies, devDependencies, or optionalDependencies in the package.json of a package.
Auto-fix:
If a dependency is a dependency
it will be removed from devDependencies
and optionalDependencies
. If a depdnency is a devDependency
and an optionalDependency
it will be removed from dependencies
.
{
"checks": [
"*": [
"recommended/unique-dependency-types"
]
]
}
recommended/matching-dev-peer-versions
⚠️ Warning
Ensures that every peerDependency
is also listed as `devDependency`` with a version range that is a subset of the peerDependency. This will align local development to the experience external consumers will have when installing the package.
Auto-fix:
The version range for a devDependency
will be updated to match it's matching peerDependency
.
{
"checks": [
"*": [
"recommended/matching-dev-peer-versions"
]
]
}
Composable checks
Use these checks to create new checks customized to your current conventions and workflows.
has-json-file
❌ Error
Ensures that a JSON file exists with the specified content.
Auto-fix:
If the JSON file does not exist or does not contain the expected content, it will be created or merged with the specified content.
import { hasJson } from 'commonality-checks-recommended';
export default hasJson('package.json', {
scripts: {
build: 'tsc --build',
dev: 'tsc --watch'
}
})
{
"checks": [
"buildable": [
"has-build-scripts"
]
]
}
has-text-file
❌ Error
Ensures that a text file exists with the specified content.
Auto-fix:
If the text file does not exist or does not contain the expected content, it will be created or appended to with the specified content.
import { hasText } from 'commonality-checks-recommended';
export default hasText('.npmignore', ["dist"])
{
"checks": [
"publishable": [
"has-npm-ignore"
]
]
}