Skip to content

Commit 39fa18b

Browse files
committed
fix (require-returns): remove extra space in reported error
fix (valid-types): ensure memberof type ending in member type operator (yet still bad) always includes whole type in error message testing: add some uncovered tests; fix indentation refactor: unused method, prefer `const` feat(npm): add `test-cov` script showing more coverag info than just summary
1 parent 142ac17 commit 39fa18b

13 files changed

+253
-34
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"build": "rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --copy-files --source-maps",
6565
"create-readme": "gitdown ./.README/README.md --output-file ./README.md && npm run add-assertions",
6666
"lint": "eslint ./src ./test",
67+
"test-cov": "BABEL_ENV=test nyc mocha --recursive --require @babel/register --reporter progress",
6768
"test": "BABEL_ENV=test nyc --reporter text-summary mocha --recursive --require @babel/register --reporter progress"
6869
},
6970
"nyc": {

src/iterateJsdoc.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ const curryUtils = (
4747
return jsdocUtils.getFunctionParameterNames(node);
4848
};
4949

50-
utils.getFunctionSourceCode = () => {
51-
return sourceCode.getText(node);
52-
};
53-
5450
utils.isConstructor = () => {
5551
return node.parent && node.parent.kind === 'constructor';
5652
};

src/rules/requireReturns.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default iterateJsdoc(({
5858
const tags = utils.getTags(tagName);
5959

6060
if (tags.length > 1) {
61-
report('Found more than one @' + tagName + ' declaration.');
61+
report('Found more than one @' + tagName + ' declaration.');
6262
}
6363

6464
// In case the code returns something, we expect a return value in JSDoc.

src/rules/validTypes.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ export default iterateJsdoc(({
1818
} catch (err) {
1919
let error = err;
2020

21-
let endChar;
2221
if (tagName && ['memberof', 'memberof!'].includes(tagName)) {
23-
endChar = type.slice(-1);
22+
const endChar = type.slice(-1);
2423
if (['#', '.', '~'].includes(endChar)) {
2524
try {
2625
parse(type.slice(0, -1));
2726
error = {};
2827
} catch (memberofError) {
29-
error = memberofError;
28+
// Use the original error for including the whole type
3029
}
3130
}
3231
}

test/rules/assertions/checkTagNames.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,16 @@ export default {
236236
},
237237
{
238238
code: ALL_JSDOC_TAGS_COMMENT + '\nfunction quux (foo) {}'
239+
},
240+
{
241+
code: `
242+
/**
243+
*
244+
*/
245+
function quux (foo) {
246+
247+
}
248+
`
239249
}
240250
]
241251
};

test/rules/assertions/checkTypes.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,16 @@ export default {
20422042
}
20432043
}
20442044
}
2045+
},
2046+
{
2047+
code: `
2048+
/**
2049+
* @param {Number<} Ignore the error as not a validating rule
2050+
*/
2051+
function quux (foo) {
2052+
2053+
}
2054+
`
20452055
}
20462056
]
20472057
};

test/rules/assertions/implementsOnClasses.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ export default {
5454
}
5555
`
5656
},
57+
{
58+
code: `
59+
/**
60+
*
61+
*/
62+
const quux = class {
63+
/**
64+
* @implements {SomeClass}
65+
*/
66+
constructor () {
67+
68+
}
69+
}
70+
`
71+
},
5772
{
5873
code: `
5974
/**

test/rules/assertions/newlineAfterDescription.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,36 @@ export default {
3333
}
3434
`
3535
},
36+
{
37+
code: `
38+
/**
39+
* Foo.
40+
*
41+
* Foo.
42+
* @foo
43+
*/
44+
function quux () {
45+
46+
}
47+
`,
48+
errors: [
49+
{
50+
message: 'There must be a newline after the description of the JSDoc block.'
51+
}
52+
],
53+
output: `
54+
/**
55+
* Foo.
56+
*
57+
* Foo.
58+
*
59+
* @foo
60+
*/
61+
function quux () {
62+
63+
}
64+
`
65+
},
3666
{
3767
code: `
3868
/**

test/rules/assertions/requireExample.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,23 @@ export default {
130130
}
131131
}
132132
},
133+
{
134+
code: `
135+
class Foo {
136+
/**
137+
*
138+
*/
139+
constructor () {
140+
141+
}
142+
}
143+
`,
144+
settings: {
145+
jsdoc: {
146+
avoidExampleOnConstructors: true
147+
}
148+
}
149+
},
133150
{
134151
code: `
135152
/**

test/rules/assertions/requireHyphenBeforeParamDescription.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@ export default {
2727
}
2828
`
2929
},
30+
{
31+
code: `
32+
/**
33+
* @param foo Foo.
34+
*/
35+
function quux () {
36+
37+
}
38+
`,
39+
errors: [
40+
{
41+
line: 3,
42+
message: 'There must be a hyphen before @param description.'
43+
}
44+
],
45+
output: `
46+
/**
47+
* @param foo - Foo.
48+
*/
49+
function quux () {
50+
51+
}
52+
`
53+
},
3054
{
3155
code: `
3256
/**
@@ -141,6 +165,16 @@ export default {
141165
options: [
142166
'never'
143167
]
168+
},
169+
{
170+
code: `
171+
/**
172+
* @param foo
173+
*/
174+
function quux () {
175+
176+
}
177+
`
144178
}
145179
]
146180
};

0 commit comments

Comments
 (0)