Skip to content

Latest commit

 

History

History
62 lines (43 loc) · 1.94 KB

repository-shorthand.md

File metadata and controls

62 lines (43 loc) · 1.94 KB

repository-shorthand

💼 This rule is enabled in the ✅ recommended config.

🔧 This rule is automatically fixable by the --fix CLI option.

This rule enforces that repository entries in a package.json use either object (default) or shorthand notation to refer to GitHub repositories when possible.

Rule Details

npm previously allowed a "shorthand" form like "JoshuaKGoldberg/eslint-plugin-package-json" to specifying a full URL to a GitHub repository like "https://github.com/JoshuaKGoldberg/eslint-plugin-package-json". However, current versions of npm now normalize that form to the object longhand with type and url and warn against the shorthand.

Examples of incorrect code for this rule with the default options:

{
	"repository": "JoshuaKGoldberg/eslint-plugin-package-json"
}

Examples of correct code for this rule with the default options:

{
	"repository": {
		"type": "git",
		"url": "https://github.com/JoshuaKGoldberg/eslint-plugin-package-json"
	}
}

Options

{
	"package-json/order-properties": [
		"error",
		{
			"form": "shorthand"
		}
	]
}

Form

The form property specifies whether to use:

  • "object" (default): an object with "type" and "url"
  • "shorthand": the shorthand string equivalent.

The object form is generally recommended as that's what npm publish prefers.

If and when npm drops support for the "shorthand" form, this rule will likely remove its options.

Further Reading