-
Notifications
You must be signed in to change notification settings - Fork 35
Description
Feature Request Checklist
- I have searched for related issues and found none that matched my issue.
Overview
package.json allows arbitrary properties which are often used by other tools, such as prettier, lint-staged or pnpm. Some people prefer to consolidate different tools' settings in one place as much as possible to avoid creating a multitude of configuration files in the root of the repo - while others may prefer the opposite.
I have two use cases for which I would like a rule that can restrict certain top-level properties in package.json:
- The first case (described above): I prefer to keep my package.json as minimal and clean as possible, since tools' options sometimes can be long and/or unrepresentable in JSON;
- The second case: older versions of pnpm used the
pnpmpackage.json key for pnpm specific options. Nowadays, the recommended way is to use a separatepnpm-workspace.yamlfile, while the former method continues to work. It'd be nice to disallowpnpmproperty in that scenario.
Proposed rule name
restrict-top-level-properties
Proposed options
type Options = [{
ban?: (string | {property: string; message?: string})[]; // Alternative option: Record<string, true | string>
}];ban
Provides a list of banned top-level properties with an optional custom message shown in the error message when the banned property is used. Can include any property, even standard ones like name or version. If the same property is banned multiple times, the last declaration takes precedence. (Alternatively, ban could be represented as Record<string, true | string> where a string value represents a custom message.)
Dropped from this issue
allow
- If omitted: all properties are allowed except those listed in
ban. - If an empty array: no extra top-level properties are allowed (only standard package.json fields).
- If a non-empty array: only the listed extra properties are allowed in addition to the standard fields.
ban can still be used alongside with allow to provide a custom message for specific properties.
If the same property appears in both allow and ban, the rule should throw an error.