consistent-property-aliases
🔧💡 This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.
The following package.json properties are recognized under two spellings:
| Canonical spelling | Alternative spelling |
|---|---|
bundleDependencies |
bundledDependencies |
license |
licence |
Both spellings work, so a project can easily end up with a mix of them.
Also, tools that read package.json directly, without npm’s normalization, usually only look for one spelling.
This rule enforces a single spelling for each property, and reports a package.json that declares both.
More Details
Section titled “More Details”npm resolves each pair in favor of the canonical spelling.
normalize-package-data reads the license as data.license || data.licence, and only copies bundledDependencies into bundleDependencies when the latter is missing.
So when both are present, the alternative spelling is ignored.
Examples
Section titled “Examples”{ "licence": "MIT"}{ "bundledDependencies": ["foo"]}{ "license": "MIT", "licence": "MIT"}{ "license": "MIT"}{ "bundleDependencies": ["foo"]}Options
Section titled “Options”| Name | Description | Type |
|---|---|---|
bundleDependencies |
The spelling to enforce (bundleDependencies or bundledDependencies), true for the canonical one, or false to only report using both spellings at once. |
|
license |
The spelling to enforce (license or licence), true for the canonical one, or false to only report using both spellings at once. |
|
prefer |
Specifies the spelling to enforce for each aliased property. Properties left unspecified keep their default, which is the canonical spelling. | Object |
prefer
Section titled “prefer”Each key of prefer is an aliased property, and its value is the spelling to enforce for it.
Properties you leave out keep their default, which is always the canonical spelling.
So configuring one property does not turn off the others.
Setting a property to true also selects the canonical spelling, so you can pass a boolean value from your own configuration.
{ "package-json/consistent-property-aliases": [ "error", { "prefer": { "license": "licence" } } ]}Setting a property to false turns off the spelling preference, but declaring both spellings at once is still reported:
{ "package-json/consistent-property-aliases": [ "error", { "prefer": { "bundleDependencies": false } } ]}Fixes and Suggestions
Section titled “Fixes and Suggestions”The rule can only fix the spelling automatically when just the non-preferred property is present: the fix renames the key and keeps the value as is.
When both spellings are present, there is no autofix, because the two values may differ, and picking one for you would change what the package declares.
Instead, the rule suggests removing the non-preferred property.
If the property is set to true, which is the default, or to false, it suggests removing the non-canonical one, like licence.
If a key appears more than once in the file, each occurrence is reported and can be fixed on its own.
When Not to Use It
Section titled “When Not to Use It”If you need to keep both spellings of a property (for example, for a tool that only reads the alternative one), disable this rule.
Related Rules
Section titled “Related Rules”valid-bundleDependencies- Enforces that thebundleDependenciesproperty is valid, under either spelling.valid-license- Enforces that thelicenseproperty is valid, under either spelling.require-bundleDependencies- Requires thebundleDependenciesproperty to be present, under either spelling.require-license- Requires thelicenseproperty to be present, under either spelling.order-properties- Enforces a consistent ordering of top-level properties.