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 2.6.0 to 2.7.0

9

CHANGELOG.md

@@ -14,2 +14,11 @@ # Change Log

## [2.7.0] - 2017-08-08
### Added
- The ability to pass config using:
1. a `npmPackageJsonLintConfig` property in `package.json`
2. a `.npmpackagejsonlintrc` file in the current working directory
3. a `npmpackagejsonlint.config.js` file that exports a config object in the current working directory.
4. a global `.npmpackagejsonlintrc` file in the root of your user directory
5. a global `npmpackagejsonlint.config.js` file that exports a config object in the root of your user directory
## [2.6.0] - 2017-07-30

@@ -16,0 +25,0 @@ ### Changed

16

package.json
{
"name": "npm-package-json-lint",
"version": "2.6.0",
"version": "2.7.0",
"description": "CLI app for linting package.json files.",

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

"test": "mocha tests/unit --recursive",
"coverage": "nyc --extension .js --check-coverage --lines 99 --branches 97 --functions 98 npm test"
"coverage": "nyc --extension .js --check-coverage --lines 99 --branches 97 --functions 96 npm test"
},
"dependencies": {
"chalk": "^2.0.1",
"chalk": "^2.1.0",
"commander": "^2.11.0",

@@ -49,10 +49,10 @@ "in-array": "^0.1.2",

"devDependencies": {
"chai": "^4.1.0",
"eslint": "^4.3.0",
"eslint-config-tc": "^2.0.0",
"chai": "^4.1.1",
"eslint": "^4.4.1",
"eslint-config-tc": "^2.1.0",
"eslint-formatter-pretty": "^1.1.0",
"figures": "^2.0.0",
"mocha": "^3.4.2",
"mocha": "^3.5.0",
"nyc": "^11.1.0",
"sinon": "^2.4.1"
"sinon": "^3.1.0"
},

@@ -59,0 +59,0 @@ "engines": {

@@ -69,5 +69,8 @@ # npm-package-json-lint

Run using the default config on a file relative to the current working directory
Run on file relative to the current working directory. npm-package-json-lint attempts to find config. See lookup order below.
`pjl-cli -f "../relative-path/package.json"`
Run on file in the current working directory. npm-package-json-lint attempts to find config. See lookup order below.
`pjl-cli`
## Lint Rules

@@ -84,4 +87,10 @@

As mentioned in the "Commands and configuration" section there are two ways to specify rule sets. The first is using `--rule` to specify a given rule. This will run npm-package-json-lint with just this rule. The second is using `--rules-file` to specify a JSON file, named [`.npmpackagejsonlintrc`](https://github.com/tclindner/npm-package-json-lint/wiki/npm-package-json-lint-rc), to run a set of rules. If neither of the options above are specified then npm-package-json-lint looks for a global [`.npmpackagejsonlintrc`](https://github.com/tclindner/npm-package-json-lint/wiki/npm-package-json-lint-rc) file in the root of your user directory.
As mentioned in the "Commands and configuration" section there are two ways to specify rule sets. The first is using `--rule` to specify a given rule. This will run npm-package-json-lint with just this rule. The second is providing a configuration object. 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 `--rules-file` to the command to specify a JSON file. This file is typically named [`.npmpackagejsonlintrc`](https://github.com/tclindner/npm-package-json-lint/wiki/npm-package-json-lint-rc); however, you may optionally add a .json extension if you prefer.
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

@@ -88,0 +97,0 @@

@@ -5,5 +5,7 @@ 'use strict';

const fs = require('fs');
const inArray = require('in-array');
const Parser = require('./Parser');
const path = require('path');
const userHome = require('user-home');

@@ -15,4 +17,5 @@ class Config {

* @param {Object|String} passedConfigParam Object or string with desired configuration
* @param {Object} packageJsonData User's package.json data
*/
constructor(passedConfigParam) {
constructor(passedConfigParam, packageJsonData) {
this.arrayRules = [

@@ -28,2 +31,5 @@ 'valid-values-author',

this.passedConfigParam = passedConfigParam;
this.packageJsonData = packageJsonData;
this.rcFileName = '.npmpackagejsonlintrc';
this.configFileName = 'npmpackagejsonlint.config.js';
}

@@ -36,21 +42,43 @@

get() {
if (this._isConfigPassed(this.passedConfigParam)) {
const passedConfig = this._getPassedConfig(this.passedConfigParam);
let extendsConfig = {};
const userConfig = this._getUserConfig();
if (passedConfig.hasOwnProperty('extends')) {
extendsConfig = this._getExtendsConfig(passedConfig.extends);
}
this._validateConfig(userConfig);
if (!passedConfig.hasOwnProperty('rules')) {
return Object.assign({}, extendsConfig);
}
let extendsConfig = {};
return Object.assign({}, extendsConfig, passedConfig.rules);
if (userConfig.hasOwnProperty('extends')) {
extendsConfig = this._getExtendsConfig(userConfig.extends);
}
throw new Error('No configuration passed');
if (!userConfig.hasOwnProperty('rules')) {
return Object.assign({}, extendsConfig);
}
return Object.assign({}, extendsConfig, userConfig.rules);
}
/**
* Get users config with multiple fallbacks
*
* @returns {Object} Users config
*/
_getUserConfig() {
if (this._isConfigPassed(this.passedConfigParam)) {
return this._getPassedConfig(this.passedConfigParam);
} else if (this.packageJsonData.hasOwnProperty('npmPackageJsonLintConfig')) {
return this.packageJsonData.npmPackageJsonLintConfig;
} else if (this._isConfigFileExist(this._getRelativeConfigFilePth(this.rcFileName))) {
return this._loadRcFile(this._getRelativeConfigFilePth(this.rcFileName));
} else if (this._isConfigFileExist(this._getRelativeConfigFilePth(this.configFileName))) {
return this._loadConfigFile(this._getRelativeConfigFilePth(this.configFileName));
} else if (this._isConfigFileExist(this._getUsrHmConfigFilePath(this.rcFileName))) {
return this._loadRcFile(this._getUsrHmConfigFilePath(this.rcFileName));
} else if (this._isConfigFileExist(this._getUsrHmConfigFilePath(this.configFileName))) {
return this._loadConfigFile(this._getUsrHmConfigFilePath(this.configFileName));
}
throw new Error('No configuration found');
}
/**
* Checks whether config has been passed or not

@@ -80,7 +108,3 @@ * @param {Object|String} passedConfig Object or string with desired configuration

const rcFileObj = parser.parse(configFile);
this._validateConfig(rcFileObj);
return rcFileObj;
return parser.parse(configFile);
}

@@ -113,2 +137,53 @@

/**
* Gets relative config file path
*
* @param {String} fileName Name of the file
* @return {String} File path of the config file
*/
_getRelativeConfigFilePth(fileName) {
return path.join(process.cwd(), fileName);
}
/**
* Gets userhome directory config file path
*
* @param {String} fileName Name of the file
* @return {String} File path of the config file
*/
_getUsrHmConfigFilePath(fileName) {
return path.join(userHome, fileName);
}
/**
* Checks if a .npmpackagejsonlintrc.json file exists
*
* @param {String} filePath Path of the file
* @return {Boolean} true if it exists, false if not
*/
_isConfigFileExist(filePath) {
return fs.existsSync(filePath);
}
/**
* Gets configuration from a extends config module
* @param {String} filePath File path of config file
* @return {Object} Configuration object
*/
_loadRcFile(filePath) {
const parser = new Parser();
return parser.parse(filePath);
}
/**
* Checks if a .npmpackagejsonlintrc.json file exists
*
* @param {String} filePath File path of config file
* @return {Boolean} true if it exists, false if not
*/
_loadConfigFile(filePath) {
return require(filePath);
}
/**
* Loads extends config module

@@ -115,0 +190,0 @@ * @param {String} moduleName Name of the configuration module

@@ -95,3 +95,3 @@ 'use strict';

_getConfig(config) {
const configObj = new Config(config);
const configObj = new Config(config, this.packageJsonData);

@@ -98,0 +98,0 @@ return configObj.get();

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