Skip to content

Commit 52a8c0e

Browse files
authored
Merge pull request #240 from brettz9/check-examples
Change behavior of check-examples to also check classes
2 parents 2690806 + 090b08e commit 52a8c0e

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/iterateJsdoc.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,18 @@ export default (iterator, opts = {}) => {
371371
});
372372
};
373373

374-
if (opts.returns) {
374+
if (typeof opts.returns === 'function') {
375375
return opts.returns(context, sourceCode, checkJsdoc);
376376
}
377377

378+
if (Array.isArray(opts.returns)) {
379+
return opts.returns.reduce((obj, prop) => {
380+
obj[prop] = checkJsdoc;
381+
382+
return obj;
383+
}, {});
384+
}
385+
378386
return {
379387
ArrowFunctionExpression: checkJsdoc,
380388
FunctionDeclaration: checkJsdoc,

src/rules/checkExamples.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,9 @@ export default iterateJsdoc(({
188188
);
189189
});
190190
});
191-
});
191+
}, {returns: [
192+
'ArrowFunctionExpression',
193+
'ClassDeclaration',
194+
'FunctionDeclaration',
195+
'FunctionExpression'
196+
]});

test/rules/assertions/checkExamples.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,35 @@ export default {
3131
}
3232
}
3333
},
34+
{
35+
code: `
36+
/**
37+
* @example alert('hello')
38+
*/
39+
class quux {
40+
41+
}
42+
`,
43+
errors: [
44+
{
45+
message: '@example error (no-alert): Unexpected alert.'
46+
},
47+
{
48+
message: '@example error (semi): Missing semicolon.'
49+
}
50+
],
51+
settings: {
52+
jsdoc: {
53+
baseConfig: {
54+
rules: {
55+
'no-alert': 2,
56+
semi: ['error', 'always']
57+
}
58+
},
59+
eslintrcForExamples: false
60+
}
61+
}
62+
},
3463
{
3564
code: `
3665
/**

0 commit comments

Comments
 (0)