Skip to content

Commit 16b0288

Browse files
fa93hwsbrettz9
authored andcommitted
fix(eslint): Add object expression in getJSDocComment
1 parent 383a557 commit 16b0288

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"mocha": "^6.1.4",
3535
"nyc": "^14.1.1",
3636
"semantic-release": "^15.13.17",
37+
"sinon": "^7.3.2",
3738
"typescript": "^3.5.2"
3839
},
3940
"engines": {

src/eslint/getJSDocComment.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const getJSDocComment = function (sourceCode, node) {
7070
return findJSDocComment(parent.parent);
7171

7272
case 'ArrowFunctionExpression':
73+
case 'ObjectExpression':
7374
case 'FunctionExpression':
7475
if (
7576
parent.type !== 'CallExpression' &&

test/eslint/getJSDocComment.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {Linter} from 'eslint/lib/linter';
2+
import {assert} from 'chai';
3+
import sinon from 'sinon';
4+
import getJSDocComment from '../../src/eslint/getJSDocComment';
5+
6+
describe('getJSDocComment', () => {
7+
const linter = new Linter();
8+
it('should get JSDoc comment for node when the node is an ObjectExpression', () => {
9+
const code = [
10+
'/** Desc*/',
11+
'const A = {',
12+
'}'
13+
].join('\n');
14+
15+
const assertJSDoc = function (node) {
16+
const sourceCode = linter.getSourceCode();
17+
const jsdoc = getJSDocComment(sourceCode, node);
18+
19+
assert.strictEqual(jsdoc.type, 'Block');
20+
assert.strictEqual(jsdoc.value, '* Desc');
21+
};
22+
23+
const spy = sinon.spy(assertJSDoc);
24+
25+
linter.defineRule('checker', () => {
26+
return {ObjectExpression: spy};
27+
});
28+
linter.verify(code, {
29+
parserOptions: {ecmaVersion: 6},
30+
rules: {checker: 'error'}
31+
});
32+
assert.isTrue(spy.calledOnce, 'Event handler should be called.');
33+
});
34+
});

0 commit comments

Comments
 (0)