Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

npm-package-json-lint

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npm-package-json-lint - npm Package Compare versions

Comparing version 4.0.0 to 4.0.1

7

CHANGELOG.md

@@ -7,4 +7,9 @@ # Change Log

## [4.0.1] - 2019-10-19
### Fixed
- Resolved an issue with applying override config. Please see [#123](https://github.com/tclindner/npm-package-json-lint/issues/123) for more details. Thank you @simison for reporting this issue.
## [4.0.0] - 2019-10-06
### Added
- Added configuration override support via glob patterns. This is especially useful for monorepos. Addresses [#96](https://github.com/tclindner/npm-package-json-lint/issues/96). Check out the [documentation](https://npmpackagejsonlint.org/docs/en/configuration) for more details.
- Added exception support to the following rules:

@@ -40,2 +45,4 @@

- Node.js API consolidated. NpmPackageJsonLint constructor now takes an options object and exposes one public method, `lint`. The linter automatically scans for relevant config. The CLIEngine has been removed. Addresses [#82](https://github.com/tclindner/npm-package-json-lint/issues/82). Check out the [documentation](https://npmpackagejsonlint.org/docs/en/api) for more details.
- Improved schema validation that runs against npm-package-json-lint config files. Highlights include:

@@ -42,0 +49,0 @@

8

package.json
{
"name": "npm-package-json-lint",
"version": "4.0.0",
"version": "4.0.1",
"description": "Configurable linter for package.json files.",

@@ -54,6 +54,6 @@ "keywords": [

"eslint": "^6.5.1",
"eslint-config-tc": "^8.0.1",
"eslint-config-tc": "^8.1.0",
"eslint-formatter-pretty": "^2.1.1",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^22.17.0",
"eslint-plugin-jest": "^22.19.0",
"eslint-plugin-prettier": "^3.1.1",

@@ -63,3 +63,3 @@ "figures": "^3.0.0",

"npm-package-json-lint-config-default": "^2.0.0",
"npm-package-json-lint-config-tc": "^2.2.0",
"npm-package-json-lint-config-tc": "^3.0.0",
"prettier": "^1.18.2"

@@ -66,0 +66,0 @@ },

@@ -26,3 +26,3 @@ # npm-package-json-lint

Please see the [wiki](https://github.com/tclindner/npm-package-json-lint/wiki) for a list of rules.
Please see the [website](https://npmpackagejsonlint.org/docs/en/rules) for a list of rules.

@@ -50,287 +50,25 @@ ## How do I install it?

## CLI commands and configuration
## Documentation
| Command | Alias | Description |
|---|---|---|
| npmPkgJsonLint --help | N/A | Lists supported CLI options |
| npmPkgJsonLint --version | N/A | Lists the current version number |
| npmPkgJsonLint --configFile <file path> | -c | File path to local config file or module name. |
| npmPkgJsonLint --quiet | -q | Report errors only |
| npmPkgJsonLint --noConfigFiles | -ncf | Skips loading project config files (i.e. .npmpackagejsonlintrc.json and npmpackagejsonlint.config.js) |
| npmPkgJsonLint --ignorePath | -i | Path to a file containing patterns that describe files to ignore. |
[Website](https://npmpackagejsonlint.org)
### Examples
Quick links
```bash
$ npmPkgJsonLint .
```
[CLI commands and configuration](https://npmpackagejsonlint.org/docs/en/cli) | [Node.js API](https://npmpackagejsonlint.org/docs/en/api)
> Looks for all `package.json` files in the project. The CLI engine automatically looks for relevant config files for each package.json file that is found.
## Migrating from v3.x.x to 4.x.x
```bash
$ npmPkgJsonLint ./packages
```
Please see the [migration guide](https://npmpackagejsonlint.org/docs/en/v3-to-v4).
> Looks for all `package.json` files in the `packages` directory. The CLI engine automatically looks for relevant config files for each package.json file that is found.
```bash
$ npmPkgJsonLint ./package1 ./package2
```
> Looks for all `package.json` files in the `package1` and `package2` directories. The CLI engine automatically looks for relevant config files for each package.json file that is found.
```bash
$ npmPkgJsonLint -c ./config/.npmpackagejsonlintrc.json .
```
> Looks for all `package.json` files in the project. The CLI engine automatically looks for relevant config files for each package.json file that is found. The CLI also merges the config found in `./config/.npmpackagejsonlintrc.json`
```bash
$ npmPkgJsonLint --configFile ./config/npmpackagejsonlint.config.json .
```
> Same as above using the long form for specifying config files.
```bash
$ npmPkgJsonLint -q .
```
> Looks for all `package.json` files in the project. The CLI engine automatically looks for relevant config files for each package.json file that is found. Removes any warnings from the output.
```bash
$ npmPkgJsonLint --quiet ./packages
```
> Looks for all `package.json` files in the `packages` directory. The CLI engine automatically looks for relevant config files for each package.json file that is found. Removes any warnings from the output using the long form for quieting output.
```bash
$ npmPkgJsonLint . --ignorePath .gitignore
```
> Looks for all `package.json` files in the project and exclude ignored paths. The CLI engine automatically looks for relevant config files for each package.json file that is found.
## Node.js API
npm-package-json-lint exports two main objects: `CLIEngine` and `NpmPackageJsonLint`.
### NpmPackageJsonLint()
Creates an instance of NpmPackageJsonLint
`NpmPackageJsonLint` has one public method, `lint`. `lint` takes a package.json object in object form and a config object as parameters.
#### .lint(packageJsonData, configObj)
Runs configured rules against the provided package.json object.
##### packageJsonData
Type: `object`
A package.json file in object form.
##### configObj
Type: `object`
A valid configuration object.
##### Example
The following example demostrates how to use `lint`.
```js
const NpmPackageJsonLint = require('npm-package-json-lint').NpmPackageJsonLint;
const npmPackageJsonLint = new NpmPackageJsonLint();
const results = npmPackageJsonLint.lint(packageJsonDataAsObject, configObject);
```
##### Return
`lint` returns an object with an array of `LintIssue`s. Please see `LintIssue` section for more detail.
```js
{
issues: [
{
lintId: 'require-name',
severity: 'error',
node: 'name',
lintMessage: 'name is required'
}
]
}
```
#### .version
Calling `.version` on an instance of `NpmPackageJsonLint` will return the version number of npm-package-json-lint that the linter is associated with.
##### Example
```js
const NpmPackageJsonLint = require('npm-package-json-lint').NpmPackageJsonLint;
const npmPackageJsonLint = new NpmPackageJsonLint();
npmPackageJsonLint.version; // => '3.0.0'
```
### CLIEngine(options)
Creates an instance of CLIEngine
##### options
Type: `object`
CLIEngine configuration object
* `configFile` {string} Name of module/file to use.
* `cwd` {string} The current working diretory for all file operations.
* `useConfigFiles` {boolean} False disables use of .npmpackagejsonlintrc.json files and npmpackagejsonlint.config.js files.
* `ignorePath` {string} Path to a file containing patterns that describe files to ignore. The path can be absolute or relative to process.cwd(). By default, npm-package-json-lint looks for .npmpackagejsonlintignore in process.cwd().
* `rules` {object} An object of rules to use.
##### Example
The following example demostrates how to initialize a `CLIEngine`.
```js
const CLIEngine = require('npm-package-json-lint').CLIEngine;
const cliEngineOptions = {
configFile: '',
cwd: process.cwd(),
useConfigFiles: true,
ignorePath: '',
rules: {}
};
const cliEngine = new CLIEngine(cliEngineOptions);
```
#### .executeOnPackageJsonFiles(patterns)
Runs npm-package-json-lint against the array a patterns.
##### patterns
Type: `array`
An array of glob patterns
##### Example
The following example demostrates how to use `executeOnPackageJsonFiles`.
```js
const CLIEngine = require('npm-package-json-lint').CLIEngine;
const cliEngineOptions = {
configFile: '',
cwd: process.cwd(),
useConfigFiles: true,
ignorePath: '',
rules: {}
};
const patterns = ['.'];
const cliEngine = new CLIEngine(cliEngineOptions);
const results = cliEngine.executeOnPackageJsonFiles(patterns);
```
##### Return
`executeOnPackageJsonFiles` returns an object with an array of results.
```js
{
results: [
{
filePath: './package.json',
issues: [
{
lintId: 'require-name',
severity: 'error',
node: 'name',
lintMessage: 'name is required'
}
],
errorCount: 1,
warningCount: 0
}
],
errorCount: 1,
warningCount: 0
}
```
#### .version
Calling `.version` on an instance of `CLIEngine` will return the version number of npm-package-json-lint that the CLIEngine is associated with.
##### Example
```js
const CLIEngine = require('npm-package-json-lint').CLIEngine;
const cliEngineOptions = {
configFile: '',
cwd: process.cwd(),
useConfigFiles: true,
ignorePath: '',
rules: {}
};
const cliEngine = new CLIEngine(cliEngineOptions);
cliEngine.version; // => '3.0.0'
```
> **WARNING**
Only the functions documented above are supported. All other functions that are exposed may change with any release. Please refrain from using them.
## Lint Rules
npm-package-json-lint has a configurable set of rules. Please see the [wiki](https://github.com/tclindner/npm-package-json-lint/wiki) for a full list of available rules. By default no rules are enabled. If you would like to use npm-package-json-lint's default ruleset, please see [npm-package-json-lint-config-default](https://github.com/tclindner/npm-package-json-lint-config-default).
Each rule contains the following properties:
1. ID - example: require-author
2. Node - example: author
3. Message - example: author is required
4. Rule Type - example: required
As of v2.7.0, there are multiple ways to provide a [configuration object](https://github.com/tclindner/npm-package-json-lint/wiki/configuration).
1. Adding a `--configFile` to the command to specify a JSON file. This file is named [`.npmpackagejsonlintrc.json`](https://github.com/tclindner/npm-package-json-lint/wiki/npm-package-json-lint-rc).
2. Add a `npmPackageJsonLintConfig` property in `package.json` file
3. Add a `npmpackagejsonlint.config.js` file that exports a config object in the current working directory.
4. Add a global `.npmpackagejsonlintrc.json` file in the root of your user directory
5. Add a global `npmpackagejsonlint.config.js` file that exports a config object in the root of your user directory
### 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"`
## Migrating from v2.x.x to 3.x.x
Please see the [migration guide](https://github.com/tclindner/npm-package-json-lint/wiki/migrating-from-v2-to-v3).
Please see the [migration guide](https://npmpackagejsonlint.org/docs/en/v2-to-v3).
## Migrating from v1.x.x to 2.x.x
Please see the [migration guide](https://github.com/tclindner/npm-package-json-lint/wiki/migrating-from-v1-to-v2).
Please see the [migration guide](https://npmpackagejsonlint.org/docs/en/v1-to-v2).
## Migrating from v0.x.x to 1.x.x
Please see the [migration guide](https://github.com/tclindner/npm-package-json-lint/wiki/migrating-from-v0-to-v1).
Please see the [migration guide](https://npmpackagejsonlint.org/docs/en/v0-to-v1).

@@ -337,0 +75,0 @@ ## Contributing

@@ -34,5 +34,2 @@ const debug = require('debug')('npm-package-json-lint:Config');

this.rules = rules;
this.explorer = cosmiconfig('npmpackagejsonlint', {
transform: cosmicConfigTransformer.transform(cwd, configBaseDirectory)
});
}

@@ -58,6 +55,10 @@

debug(`Config file specified, loading it.`);
config = this.explorer.loadSync(this.configFile);
config = cosmiconfig('npmpackagejsonlint', {
transform: cosmicConfigTransformer.transform(this.cwd, this.configBaseDirectory, this.configFile)
}).loadSync(this.configFile);
} else {
debug(`Config file wasn't specified, searching for config.`);
config = this.explorer.searchSync(filePathToSearch);
config = cosmiconfig('npmpackagejsonlint', {
transform: cosmicConfigTransformer.transform(this.cwd, this.configBaseDirectory, filePathToSearch)
}).searchSync(filePathToSearch);
}

@@ -83,2 +84,4 @@ } else {

debug(`Overrides applied for ${filePath}`);
debug('Final Config');
debug(config);

@@ -85,0 +88,0 @@ configValidator.validateRules(config, 'cli', this.rules);

const path = require('path');
const debug = require('debug')('npm-package-json-lint:cosmicConfigTransformer');
const applyExtendsIfSpecified = require('./applyExtendsIfSpecified');
const applyOverrides = require('./applyOverrides');
const transform = (cwd, configBaseDirectory) => {
const transform = (cwd, configBaseDirectory, filePathBeingLinted) => {
debug(`cwd: ${cwd}`);
debug(`configBaseDirectory`);
debug(configBaseDirectory);
return cosmiconfigResult => {
debug(`cosmiconfigResult`);
debug(cosmiconfigResult);
if (!cosmiconfigResult) {

@@ -13,2 +21,7 @@ return null;

debug(`cosmiconfigResult.config`);
debug(config);
debug(`cosmiconfigResult.filepath`);
debug(filepath);
/* eslint-disable no-unused-vars */

@@ -18,4 +31,9 @@ const configDir = configBaseDirectory || path.dirname(filepath || '');

const configAfterExtends = applyExtendsIfSpecified(npmPackageJsonLintConfig, filepath);
const configAfterOverrides = applyOverrides(cwd, filepath, configAfterExtends.rules, configAfterExtends.overrides);
const configAfterExtends = applyExtendsIfSpecified(npmPackageJsonLintConfig, filePathBeingLinted);
const configAfterOverrides = applyOverrides(
cwd,
filePathBeingLinted,
configAfterExtends.rules,
configAfterExtends.overrides
);

@@ -22,0 +40,0 @@ return configAfterOverrides;

@@ -46,3 +46,3 @@ const debug = require('debug')('npm-package-json-lint:getFileList');

debug('files');
debug('Final file list from `getFileList`');
debug(files);

@@ -49,0 +49,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc