Skip to content

Latest commit

 

History

History
205 lines (158 loc) · 9.5 KB

rules.md

File metadata and controls

205 lines (158 loc) · 9.5 KB
id title
rules
Rules

Rules allow npm-package-json-lint to be fully customizable. npm-package-json-lint will only run the rules supplied. As of v2.7.0, there are multiple ways to supply configuration. One of the easiest way is via a .npmpackagejsonlintrc.json file. The default configuration supplied in v1 is no longer provided in v2. Please see the new default config module, npm-package-json-lint-config-default instead.

Migrating from v2.x.x to 3.x.x?

Please see migrating-from-v2-to-v3

Migrating from v1.x.x to 2.x.x?

Please see migrating-from-v1-to-v2

Migrating from v0.x.x to 1.x.x?

Please see migrating-from-v0-to-v1

Configuring rules

npm-package-json-lint rules can either be run as an error, warning, or off.

  • "warning" - run the rule as a warning
  • "error" - run the rule as an error
  • "off" - disables the rule

Ex: "require-author": "error"

.npmpackagejsonlintrc.json file

Please see .npmpackagejsonlintrc.json file.

Shareable config

v2 added support for shareable npm-package-json-lint config! If you would like to use your .npmpackagejsonlintrc.json file in multiple projects you can create a npm module that exports your config.

How to create shared config

Create a new npm module that exports the desired npm-package-json-lint configuration. The module name must start with npm-package-json-lint-config-. Add the desired configuration to the index.js file.

const config = {
  'rules': {
    'require-name': 'error'
  }
};

module.exports = config;

For a complete example, please see npm-package-json-lint-config-default

How to publish a shared config module

Follow these instructions for publishing to npm. Please add the following keywords for discoverability, npm-package-json-lint, npm-package-json-lintconfig, and npm-package-json-lint-config.

Please also add a dependency on npm-package-json-lint using peerdependencies. Example

peerDependencies: {
  "npm-package-json-lint": ">= 2"
}

How to use a shared config module

Add the following to your .npmpackagejsonlintrc.json file.

{
  "extends": "npm-package-json-lint-config-default"
}

npm-package-json-lint-config-default can be replaced by the name of the shared module you are using.

Require node rules

Generates an error if node is missing from package.json file

Type rules

Generates an error if node's value doesn't have the correct data type

Valid value rules

Generates an error if node's value doesn't match one of the values in the supplied array

Dependency rules

Generates an error if dependencies fail to meet the rules requirements

Format rules

Generates an error if node's value fails to meet the format requirements

Package.json property rules

Generates an error if the package.json properties fail to meet the desired requirements

Disallowed node rules

Generates an error if the node is present