Skip to content

Commit 8cdb471

Browse files
authored
4.5.0 (#183)
* Fix lint issues * Create v4.5.0 docs * Remove exceptions and fix version * Bump version
1 parent 60a81fe commit 8cdb471

File tree

8 files changed

+66
-23
lines changed

8 files changed

+66
-23
lines changed

docs/rules/dependencies/no-dup-fields.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,6 @@ Enabling this rule will result in an error being generated if package.json has d
1515
}
1616
```
1717

18-
With exceptions
19-
20-
```json
21-
{
22-
"rules": {
23-
"no-dup-fields": ["error", {
24-
"exceptions": ["myModule"]
25-
}]
26-
}
27-
}
28-
```
29-
3018
## Rule Details
3119

3220
### *Incorrect* examples
@@ -60,4 +48,4 @@ With exceptions
6048

6149
## History
6250

63-
* Introduced in version 4.3.0
51+
* Introduced in version 4.5.0

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "npm-package-json-lint",
3-
"version": "4.4.0",
3+
"version": "4.5.0",
44
"description": "Configurable linter for package.json files.",
55
"keywords": [
66
"lint",

src/rules/no-dup-fields.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ const LintIssue = require('./../LintIssue');
44

55
const lintId = 'no-duplicate-fields';
66
const nodeName = '';
7-
const ruleType = 'optionalObject';
7+
const ruleType = 'standard';
88

99
const lint = (packageJsonData, severity) => {
1010
/**
1111
* If we send package json straight to npm-package-json-lint, fallback to empty string.
1212
* Because we already lose information about duplicate properties.
1313
*/
14-
const source = packageJsonData[Parser.sourceSymbol] || ''; // eslint-disable-line
14+
const source = packageJsonData[Parser.sourceSymbol] || '';
1515
const dupProps = findDuplicatePropNames(source);
1616

1717
if (dupProps.length) {

src/validators/property.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const parser = require('jsonc-parser');
2+
13
/**
24
* Determines whether or not the node exists in the package.json file
35
* @param {object} packageJsonData Valid JSON
@@ -14,7 +16,6 @@ const exists = (packageJsonData, nodeName) => {
1416
* @return {string[]} List of duplicate property names.
1517
*/
1618
const findDuplicatePropNames = packageJsonSource => {
17-
const parser = require("jsonc-parser"); // eslint-disable-line
1819
const tree = parser.parseTree(packageJsonSource);
1920

2021
if (!tree) {

test/unit/rules/no-dup-fields.test.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ const {lint, ruleType} = ruleModule;
55

66
const parsePackageJson = source => {
77
const json = JSON.parse(source);
8-
json[Parser.sourceSymbol] = source; // eslint-disable-line
8+
9+
json[Parser.sourceSymbol] = source;
910

1011
return json;
1112
};
1213

1314
describe('no-dup-fields Unit Tests', () => {
1415
describe('a rule type value should be exported', () => {
15-
test('it should equal "optionalObject"', () => {
16-
expect(ruleType).toStrictEqual('optionalObject');
16+
test('it should equal "standard"', () => {
17+
expect(ruleType).toStrictEqual('standard');
1718
});
1819
});
1920

@@ -23,7 +24,7 @@ describe('no-dup-fields Unit Tests', () => {
2324
"name": "package1",
2425
"name": "package2"
2526
}`);
26-
const response = lint(packageJsonData, 'error', {exceptions: ['grunt-npm-package-json-lint']});
27+
const response = lint(packageJsonData, 'error');
2728

2829
expect(response.lintId).toStrictEqual('no-duplicate-fields');
2930
expect(response.severity).toStrictEqual('error');
@@ -41,7 +42,7 @@ describe('no-dup-fields Unit Tests', () => {
4142
"eslint": "6.7.2"
4243
}
4344
}`);
44-
const response = lint(packageJsonData, 'error', {exceptions: ['grunt-npm-package-json-lint']});
45+
const response = lint(packageJsonData, 'error');
4546

4647
expect(response.lintId).toStrictEqual('no-duplicate-fields');
4748
expect(response.severity).toStrictEqual('error');
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
id: version-4.5.0-no-dup-fields
3+
title: no-dup-fields
4+
original_id: no-dup-fields
5+
---
6+
7+
Enabling this rule will result in an error being generated if package.json has duplicate fields in block section.
8+
9+
## Example .npmpackagejsonlintrc configuration
10+
11+
```json
12+
{
13+
"rules": {
14+
"no-dup-fields": "error"
15+
}
16+
}
17+
```
18+
19+
## Rule Details
20+
21+
### *Incorrect* examples
22+
23+
```json
24+
{
25+
"name": "packageName",
26+
"name": "packageName"
27+
}
28+
```
29+
30+
31+
### *Correct* examples
32+
33+
34+
```json
35+
{
36+
"name": "packageName"
37+
}
38+
```
39+
40+
## Shorthand for disabling the rule in .npmpackagejsonlintrc configuration
41+
42+
```json
43+
{
44+
"rules": {
45+
"no-dup-fields": "off"
46+
}
47+
}
48+
```
49+
50+
## History
51+
52+
* Introduced in version 4.5.0

website/versions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[
2+
"4.5.0",
23
"4.4.0",
34
"4.3.0",
45
"4.2.0",

0 commit comments

Comments
 (0)