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.4.0 to 4.5.0

src/rules/no-duplicate-properties.js

7

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

@@ -46,6 +46,7 @@ "keywords": [

"is-plain-obj": "^2.0.0",
"jsonc-parser": "^2.2.0",
"log-symbols": "^3.0.0",
"meow": "^5.0.0",
"meow": "^6.0.0",
"plur": "^3.1.1",
"semver": "^6.3.0",
"semver": "^7.0.0",
"strip-json-comments": "^3.0.1"

@@ -52,0 +53,0 @@ },

@@ -50,5 +50,6 @@ /* eslint class-methods-use-this: 'off', global-require: 'off', import/no-dynamic-require: 'off' */

let json = {};
let fileContents = '';
try {
const fileContents = readFile(fileName);
fileContents = readFile(fileName);

@@ -60,2 +61,9 @@ json = JSON.parse(stripComments(fileContents));

Object.defineProperty(json, Parser.sourceSymbol, {
value: fileContents,
enumerable: false,
writable: false,
configurable: false
});
return json;

@@ -84,2 +92,4 @@ }

Parser.sourceSymbol = Symbol('JSON source');
module.exports = Parser;

@@ -0,1 +1,3 @@

const parser = require('jsonc-parser');
/**

@@ -11,4 +13,42 @@ * Determines whether or not the node exists in the package.json file

/**
* Search for duplicate properties in package.json file
* @param {string} packageJsonSource JSON source string
* @return {string[]} List of duplicate property names.
*/
const findDuplicatePropNames = packageJsonSource => {
const tree = parser.parseTree(packageJsonSource);
if (!tree) {
return [];
}
const traverse = (node, dups = []) => {
const foundProps = new Map();
// eslint-disable-next-line
for (const child of node.children) {
const [propNameNode, propValNode] = child.children;
const propName = propNameNode.value;
if (foundProps.has(propName)) {
dups.push(propName);
} else {
foundProps.set(propName, true);
}
if (propValNode.type === 'object') {
traverse(propValNode, dups);
}
}
return dups;
};
return traverse(tree);
};
module.exports = {
exists
exists,
findDuplicatePropNames
};
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