require-attribution
💼 This rule is enabled in the following configs: ✅ recommended, 📦 recommended-publishable.
💡 This rule is manually fixable by editor suggestions.
This rule ensures that proper attribution is included in a package, requiring that either author or contributors is defined.
If contributors is present, it should include at least one contributor.
More Details
Section titled “More Details”When publishing a package, it’s helpful to include some amount of attribution.
npm supports two ways of defining attribution in a package.json:
author: this is either a string with name, email, and url combined, or an object withname,email, andurl. This is generally the original creator of the package, or sole maintainer in smaller projects.contributors: a list of all collaborators contributing to the project. Each item in the array has the samename,email, andurlproperties asauthorhas.
Examples
Section titled “Examples”With Default Options (preferContributorsOnly: false)
Section titled “With Default Options (preferContributorsOnly: false)”{ "name": "nin"}{ "author": "Trent Reznor <treznor@nin.com> (https://nin.com)", "contributors": []}{ "author": "Trent Reznor <treznor@nin.com> (https://nin.com)"}{ "author": { "name": "Trent Reznor", "email": "treznor@nin.com", "url": "https://nin.com" }}{ "contributors": [ { "name": "Trent Reznor", "email": "treznor@nin.com", "url": "https://nin.com" }, { "name": "Atticus Ross", "email": "atticus@nin.com", "url": "https://nin.com" } ]}{ "author": { "name": "Trent Reznor", "email": "treznor@nin.com", "url": "https://nin.com" }, "contributors": [ { "name": "Trent Reznor", "email": "treznor@nin.com", "url": "https://nin.com" }, { "name": "Atticus Ross", "email": "atticus@nin.com", "url": "https://nin.com" } ]}With preferContributorsOnly: true
Section titled “With preferContributorsOnly: true”{ "name": "nin"}{ "author": "Trent Reznor <treznor@nin.com> (https://nin.com)", "contributors": []}{ "author": "Trent Reznor <treznor@nin.com> (https://nin.com)"}{ "author": { "name": "Trent Reznor", "email": "treznor@nin.com", "url": "https://nin.com" }}{ "author": { "name": "Trent Reznor", "email": "treznor@nin.com", "url": "https://nin.com" }, "contributors": [ { "name": "Trent Reznor", "email": "treznor@nin.com", "url": "https://nin.com" }, { "name": "Atticus Ross", "email": "atticus@nin.com", "url": "https://nin.com" } ]}{ "contributors": [ { "name": "Trent Reznor", "email": "treznor@nin.com", "url": "https://nin.com" }, { "name": "Atticus Ross", "email": "atticus@nin.com", "url": "https://nin.com" } ]}Options
Section titled “Options”| Name | Description | Type | Default |
|---|---|---|---|
ignorePrivate |
Skip attribution requirements for packages with "private": true. |
Boolean | true |
preferContributorsOnly |
Require that only contributors is present, and author is not defined. |
Boolean | false |
ignorePrivate
Section titled “ignorePrivate”When enabled, ignorePrivate skips all attribution checks for packages that have "private": true set.
This is useful for internal packages that won’t be published to npm.
{ "package-json/require-attribution": [ "error", { "ignorePrivate": true } ]}preferContributorsOnly
Section titled “preferContributorsOnly”When enabled, preferContributorsOnly requires that only contributors may be defined for attribution, and will report if author is also present.
{ "package-json/require-attribution": [ "error", { "preferContributorsOnly": true } ]}When Not to Use It
Section titled “When Not to Use It”If your package is not going to be published, and attribution is not important, then this rule can safely be disabled.
Related Rules
Section titled “Related Rules”require-author- Enforces that theauthorproperty is present.require-contributors- Enforces that thecontributorsproperty is present.valid-author- Enforces that theauthorproperty is valid.valid-contributors- Enforces that thecontributorsproperty is valid.