npm-package-json-lint
Advanced tools
Comparing version 4.4.0 to 4.5.0
{ | ||
"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 | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
139501
132
3907
14
+ Addedjsonc-parser@^2.2.0
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Added@types/minimist@1.2.5(transitive)
+ Added@types/normalize-package-data@2.4.4(transitive)
+ Addedcamelcase@5.3.1(transitive)
+ Addedcamelcase-keys@6.2.2(transitive)
+ Addedfind-up@4.1.0(transitive)
+ Addedhard-rejection@2.1.0(transitive)
+ Addedindent-string@4.0.0(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjson-parse-even-better-errors@2.3.1(transitive)
+ Addedjsonc-parser@2.3.1(transitive)
+ Addedkind-of@6.0.3(transitive)
+ Addedlines-and-columns@1.2.4(transitive)
+ Addedlocate-path@5.0.0(transitive)
+ Addedmap-obj@4.3.0(transitive)
+ Addedmeow@6.1.1(transitive)
+ Addedmin-indent@1.0.1(transitive)
+ Addedminimist-options@4.1.0(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@4.1.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedparse-json@5.2.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedquick-lru@4.0.1(transitive)
+ Addedread-pkg@5.2.0(transitive)
+ Addedread-pkg-up@7.0.1(transitive)
+ Addedredent@3.0.0(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedstrip-indent@3.0.0(transitive)
+ Addedtrim-newlines@3.0.1(transitive)
+ Addedtype-fest@0.13.10.6.00.8.1(transitive)
+ Addedyargs-parser@18.1.3(transitive)
- Removedarray-find-index@1.0.2(transitive)
- Removedcamelcase@4.1.0(transitive)
- Removedcamelcase-keys@4.2.0(transitive)
- Removedcurrently-unhandled@0.4.1(transitive)
- Removedfind-up@2.1.0(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedindent-string@3.2.0(transitive)
- Removedload-json-file@4.0.0(transitive)
- Removedlocate-path@2.0.0(transitive)
- Removedloud-rejection@1.6.0(transitive)
- Removedmap-obj@2.0.0(transitive)
- Removedmeow@5.0.0(transitive)
- Removedminimist-options@3.0.2(transitive)
- Removedp-limit@1.3.0(transitive)
- Removedp-locate@2.0.0(transitive)
- Removedp-try@1.0.0(transitive)
- Removedpath-exists@3.0.0(transitive)
- Removedpath-type@3.0.0(transitive)
- Removedpify@3.0.0(transitive)
- Removedquick-lru@1.1.0(transitive)
- Removedread-pkg@3.0.0(transitive)
- Removedread-pkg-up@3.0.0(transitive)
- Removedredent@2.0.0(transitive)
- Removedsemver@6.3.1(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedstrip-bom@3.0.0(transitive)
- Removedstrip-indent@2.0.0(transitive)
- Removedtrim-newlines@2.0.0(transitive)
- Removedyargs-parser@10.1.0(transitive)
Updatedmeow@^6.0.0
Updatedsemver@^7.0.0