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
};

test/rules/assertions/requireJsdoc.js

Lines changed: 73 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@ export default {
1717
}
1818
]
1919
},
20+
{
21+
code: `
22+
function quux (foo) {
23+
24+
}`,
25+
errors: [
26+
{
27+
line: 2,
28+
message: 'Missing JSDoc comment.'
29+
}
30+
],
31+
settings: {
32+
jsdoc: {
33+
exemptEmptyFunctions: true
34+
}
35+
}
36+
},
2037
{
2138
code: 'function myFunction() {}',
2239
errors: [{
@@ -972,17 +989,17 @@ export default {
972989
{
973990
code:
974991
`/**
975-
* Description for A.
976-
*/
977-
export default class App extends Component {
978-
/**
979-
* Description for constructor.
980-
* @param {object[]} xs - xs
981-
*/
982-
constructor(xs) {
983-
this.a = xs;
984-
}
985-
}`,
992+
* Description for A.
993+
*/
994+
export default class App extends Component {
995+
/**
996+
* Description for constructor.
997+
* @param {object[]} xs - xs
998+
*/
999+
constructor(xs) {
1000+
this.a = xs;
1001+
}
1002+
}`,
9861003
options: [{
9871004
require: {
9881005
ClassDeclaration: true,
@@ -997,17 +1014,17 @@ export default {
9971014
{
9981015
code:
9991016
`/**
1000-
* Description for A.
1017+
* Description for A.
1018+
*/
1019+
export class App extends Component {
1020+
/**
1021+
* Description for constructor.
1022+
* @param {object[]} xs - xs
10011023
*/
1002-
export class App extends Component {
1003-
/**
1004-
* Description for constructor.
1005-
* @param {object[]} xs - xs
1006-
*/
1007-
constructor(xs) {
1008-
this.a = xs;
1009-
}
1010-
}`,
1024+
constructor(xs) {
1025+
this.a = xs;
1026+
}
1027+
}`,
10111028
options: [{
10121029
require: {
10131030
ClassDeclaration: true,
@@ -1022,10 +1039,10 @@ export default {
10221039
{
10231040
code:
10241041
`class A {
1025-
constructor(xs) {
1026-
this.a = xs;
1027-
}
1028-
}`,
1042+
constructor(xs) {
1043+
this.a = xs;
1044+
}
1045+
}`,
10291046
options: [{
10301047
require: {
10311048
ClassDeclaration: false,
@@ -1039,7 +1056,7 @@ export default {
10391056
{
10401057
code:
10411058
`/**
1042-
Function doing something
1059+
* Function doing something
10431060
*/
10441061
var myFunction = () => {}`,
10451062
options: [{
@@ -1051,6 +1068,36 @@ export default {
10511068
ecmaVersion: 6
10521069
}
10531070
},
1071+
{
1072+
code:
1073+
`/**
1074+
* Function doing something
1075+
*/
1076+
var myFunction = function () {}`,
1077+
options: [{
1078+
require: {
1079+
ArrowFunctionExpression: true
1080+
}
1081+
}],
1082+
parserOptions: {
1083+
ecmaVersion: 6
1084+
}
1085+
},
1086+
{
1087+
code:
1088+
`/**
1089+
* Function doing something
1090+
*/
1091+
var myFunction = () => {}`,
1092+
options: [{
1093+
require: {
1094+
ArrowFunctionExpression: false
1095+
}
1096+
}],
1097+
parserOptions: {
1098+
ecmaVersion: 6
1099+
}
1100+
},
10541101
{
10551102
code:
10561103
`/**

test/rules/assertions/requireReturns.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,24 @@ export default {
232232
parserOptions: {
233233
ecmaVersion: 8
234234
}
235+
},
236+
{
237+
code: `
238+
/**
239+
* @returns {undefined}
240+
* @returns {void}
241+
*/
242+
function quux (foo) {
243+
244+
return foo;
245+
}
246+
`,
247+
errors: [
248+
{
249+
line: 2,
250+
message: 'Found more than one @returns declaration.'
251+
}
252+
]
235253
}
236254
],
237255
valid: [

0 commit comments

Comments
 (0)