Skip to content

Commit 972f673

Browse files
authored
4.6.0 (#207)
* Bump version * Add forbidEndingPeriod Closes #196 * Add docs for forbidEndingPeriod
1 parent 078bdec commit 972f673

File tree

7 files changed

+296
-2
lines changed

7 files changed

+296
-2
lines changed

docs/rules/format/description-format.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Enabling this rule will result in an error being generated if `description` does
77

88
1. `requireCapitalFirstLetter` - Throws an error if the first character in the description isn't capitalized.
99
2. `requireEndingPeriod` - Throws an error if the description doesn't end with a period.
10+
3. `forbidEndingPeriod` - Throws an error if the description ends with a period.
1011

1112
## Example .npmpackagejsonlintrc configuration
1213

@@ -139,6 +140,58 @@ Enabling this rule will result in an error being generated if `description` does
139140
}
140141
```
141142

143+
## Example .npmpackagejsonlintrc configuration with only `forbidEndingPeriod`
144+
145+
```json
146+
{
147+
"rules": {
148+
"description-format": ["error", {
149+
"forbidEndingPeriod": true
150+
}]
151+
}
152+
}
153+
```
154+
155+
```json
156+
{
157+
"rules": {
158+
"description-format": ["error", {
159+
"requireCapitalFirstLetter": false,
160+
"forbidEndingPeriod": true
161+
}]
162+
}
163+
}
164+
```
165+
166+
## Rule Details
167+
168+
### *Incorrect* example(s)
169+
170+
```json
171+
{
172+
"description": "I'm a valid description."
173+
}
174+
```
175+
176+
### *Correct* example(s)
177+
178+
```json
179+
{
180+
"description": "I'm a valid description"
181+
}
182+
```
183+
184+
```json
185+
{
186+
"description": "i'm a valid description"
187+
}
188+
```
189+
190+
## Configuration Exception
191+
192+
An exception will be thrown if `requireEndingPeriod` and `forbidEndingPeriod` are set to `true`.
193+
142194
## History
143195

196+
* Added `forbidEndingPeriod` option in version 4.6.0
144197
* Introduced in version 3.3.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.5.2",
3+
"version": "4.6.0",
44
"description": "Configurable linter for package.json files.",
55
"keywords": [
66
"lint",

src/rules/description-format.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const lintId = 'description-format';
55
const nodeName = 'description';
66
const ruleType = 'object';
77

8+
// eslint-disable-next-line complexity
89
const lint = (packageJsonData, severity, config) => {
910
if (!packageJsonData.hasOwnProperty(nodeName)) {
1011
return true;
@@ -30,10 +31,18 @@ const lint = (packageJsonData, severity, config) => {
3031
);
3132
}
3233

34+
if (config.hasOwnProperty('requireEndingPeriod') && config.hasOwnProperty('forbidEndingPeriod')) {
35+
throw new Error('description-format does not support `requireEndingPeriod` and `forbidEndingPeriod` being `true`.');
36+
}
37+
3338
if (config.hasOwnProperty('requireEndingPeriod') && config.requireEndingPeriod && !description.endsWith('.')) {
3439
return new LintIssue(lintId, severity, nodeName, 'The description should end with a period.');
3540
}
3641

42+
if (config.hasOwnProperty('forbidEndingPeriod') && config.forbidEndingPeriod && description.endsWith('.')) {
43+
return new LintIssue(lintId, severity, nodeName, 'The description should not end with a period.');
44+
}
45+
3746
return true;
3847
};
3948

test/unit/rules/description-format.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ describe('description-format Unit Tests', () => {
4646
});
4747
});
4848

49+
describe('when package.json has requireEndingPeriod and forbidEndingPeriod set', () => {
50+
test('An exception should be thrown', () => {
51+
const packageJsonData = {
52+
description: 'My description'
53+
};
54+
const config = {
55+
forbidEndingPeriod: true,
56+
requireEndingPeriod: true
57+
};
58+
59+
expect(() => {
60+
lint(packageJsonData, 'error', config);
61+
}).toThrow('description-format does not support `requireEndingPeriod` and `forbidEndingPeriod` being `true`.');
62+
});
63+
});
64+
4965
describe('when package.json has node without period at end', () => {
5066
test('LintIssue object should be returned', () => {
5167
const packageJsonData = {
@@ -63,6 +79,23 @@ describe('description-format Unit Tests', () => {
6379
});
6480
});
6581

82+
describe('when package.json has node with period at end', () => {
83+
test('LintIssue object should be returned', () => {
84+
const packageJsonData = {
85+
description: 'My description.'
86+
};
87+
const config = {
88+
forbidEndingPeriod: true
89+
};
90+
const response = lint(packageJsonData, 'error', config);
91+
92+
expect(response.lintId).toStrictEqual('description-format');
93+
expect(response.severity).toStrictEqual('error');
94+
expect(response.node).toStrictEqual('description');
95+
expect(response.lintMessage).toStrictEqual('The description should not end with a period.');
96+
});
97+
});
98+
6699
describe('when package.json has empty node', () => {
67100
test('true should be returned', () => {
68101
const packageJsonData = {
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
---
2+
id: version-4.6.0-description-format
3+
title: description-format
4+
original_id: description-format
5+
---
6+
7+
Enabling this rule will result in an error being generated if `description` doesn't meet the configured options. Two options exist:
8+
9+
1. `requireCapitalFirstLetter` - Throws an error if the first character in the description isn't capitalized.
10+
2. `requireEndingPeriod` - Throws an error if the description doesn't end with a period.
11+
3. `forbidEndingPeriod` - Throws an error if the description ends with a period.
12+
13+
## Example .npmpackagejsonlintrc configuration
14+
15+
```json
16+
{
17+
"rules": {
18+
"description-format": ["error", {
19+
"requireCapitalFirstLetter": true,
20+
"requireEndingPeriod": true
21+
}]
22+
}
23+
}
24+
```
25+
26+
## Rule Details
27+
28+
### *Incorrect* example(s)
29+
30+
```json
31+
{
32+
"description": "i'm a valid description."
33+
}
34+
```
35+
36+
```json
37+
{
38+
"description": "I'm a valid description"
39+
}
40+
```
41+
42+
### *Correct* example(s)
43+
44+
```json
45+
{
46+
"description": "I'm a valid description."
47+
}
48+
```
49+
50+
## Example .npmpackagejsonlintrc configuration with only `requireCapitalFirstLetter`
51+
52+
```json
53+
{
54+
"rules": {
55+
"description-format": ["error", {
56+
"requireCapitalFirstLetter": true
57+
}]
58+
}
59+
}
60+
```
61+
62+
```json
63+
{
64+
"rules": {
65+
"description-format": ["error", {
66+
"requireCapitalFirstLetter": true,
67+
"requireEndingPeriod": false
68+
}]
69+
}
70+
}
71+
```
72+
73+
## Rule Details
74+
75+
### *Incorrect* example(s)
76+
77+
```json
78+
{
79+
"description": "i'm a valid description."
80+
}
81+
```
82+
83+
### *Correct* example(s)
84+
85+
```json
86+
{
87+
"description": "I'm a valid description."
88+
}
89+
```
90+
91+
```json
92+
{
93+
"description": "I'm a valid description"
94+
}
95+
```
96+
97+
## Example .npmpackagejsonlintrc configuration with only `requireEndingPeriod`
98+
99+
```json
100+
{
101+
"rules": {
102+
"description-format": ["error", {
103+
"requireEndingPeriod": true
104+
}]
105+
}
106+
}
107+
```
108+
109+
```json
110+
{
111+
"rules": {
112+
"description-format": ["error", {
113+
"requireCapitalFirstLetter": false,
114+
"requireEndingPeriod": true
115+
}]
116+
}
117+
}
118+
```
119+
120+
## Rule Details
121+
122+
### *Incorrect* example(s)
123+
124+
```json
125+
{
126+
"description": "I'm a valid description"
127+
}
128+
```
129+
130+
### *Correct* example(s)
131+
132+
```json
133+
{
134+
"description": "I'm a valid description."
135+
}
136+
```
137+
138+
```json
139+
{
140+
"description": "i'm a valid description."
141+
}
142+
```
143+
144+
## Example .npmpackagejsonlintrc configuration with only `forbidEndingPeriod`
145+
146+
```json
147+
{
148+
"rules": {
149+
"description-format": ["error", {
150+
"forbidEndingPeriod": true
151+
}]
152+
}
153+
}
154+
```
155+
156+
```json
157+
{
158+
"rules": {
159+
"description-format": ["error", {
160+
"requireCapitalFirstLetter": false,
161+
"forbidEndingPeriod": true
162+
}]
163+
}
164+
}
165+
```
166+
167+
## Rule Details
168+
169+
### *Incorrect* example(s)
170+
171+
```json
172+
{
173+
"description": "I'm a valid description."
174+
}
175+
```
176+
177+
### *Correct* example(s)
178+
179+
```json
180+
{
181+
"description": "I'm a valid description"
182+
}
183+
```
184+
185+
```json
186+
{
187+
"description": "i'm a valid description"
188+
}
189+
```
190+
191+
## Configuration Exception
192+
193+
An exception will be thrown if `requireEndingPeriod` and `forbidEndingPeriod` are set to `true`.
194+
195+
## History
196+
197+
* Added `forbidEndingPeriod` option in version 4.6.0
198+
* Introduced in version 3.3.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.6.0",
23
"4.5.2",
34
"4.5.1",
45
"4.5.0",

0 commit comments

Comments
 (0)