Skip to content

Latest commit

 

History

History
120 lines (89 loc) · 3.17 KB

File metadata and controls

120 lines (89 loc) · 3.17 KB

restrict-private-properties

🔧💡 This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.

This rule disallows unnecessary properties in private packages that are never published to npm.

Rule Details

When a package is marked as "private": true, it will never be published to npm. This makes certain properties unnecessary since they only affect how packages are published or consumed from the registry.

By default, this rule flags files and publishConfig in private packages:

  • files: Controls which files are included when publishing to npm
  • publishConfig: Configures how the package is published to npm

The rule will flag all blocked properties and provides auto-fix for empty values (empty arrays [] or empty objects {}). For non-empty values, the rule provides a suggestion that can be applied in your IDE, allowing you to review and remove them manually if desired.

Examples of incorrect code for this rule with default options:

{
	"name": "my-app",
	"private": true,
	"files": ["dist"]
}
{
	"name": "my-app",
	"private": true,
	"publishConfig": {
		"access": "public"
	}
}
{
	"name": "my-app",
	"private": true,
	"files": []
}

Examples of correct code for this rule with default options:

{
	"name": "my-app",
	"private": true
}
{
	"name": "my-library",
	"files": ["dist"]
}

Options

Name Description Type Default
blockedProperties Array of property names to disallow in private packages. String[] [files, publishConfig]

blockedProperties

You can customize which properties are flagged in private packages.

For example, to also flag dependencies in private packages:

{
	"package-json/restrict-private-properties": [
		"error",
		{
			"blockedProperties": ["files", "publishConfig", "dependencies"]
		}
	]
}

This can be useful for private packages that won't be published.

Or to check for different properties entirely:

{
	"package-json/restrict-private-properties": [
		"error",
		{
			"blockedProperties": ["main", "exports"]
		}
	]
}

When Not To Use It

Disable this rule if you:

  • Want to keep these properties as documentation of what would be published
  • Plan to make the package public in the future
  • Use these properties for tooling that reads them even for private packages

Further Reading