Skip to content

Commit

Permalink
fix(eslint): Add object expression in getJSDocComment
Browse files Browse the repository at this point in the history
  • Loading branch information
fa93hws authored and brettz9 committed Jun 26, 2019
1 parent 383a557 commit 16b0288
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -34,6 +34,7 @@
"mocha": "^6.1.4",
"nyc": "^14.1.1",
"semantic-release": "^15.13.17",
"sinon": "^7.3.2",
"typescript": "^3.5.2"
},
"engines": {
Expand Down
1 change: 1 addition & 0 deletions src/eslint/getJSDocComment.js
Expand Up @@ -70,6 +70,7 @@ const getJSDocComment = function (sourceCode, node) {
return findJSDocComment(parent.parent);

case 'ArrowFunctionExpression':
case 'ObjectExpression':
case 'FunctionExpression':
if (
parent.type !== 'CallExpression' &&
Expand Down
34 changes: 34 additions & 0 deletions test/eslint/getJSDocComment.js
@@ -0,0 +1,34 @@
import {Linter} from 'eslint/lib/linter';
import {assert} from 'chai';
import sinon from 'sinon';
import getJSDocComment from '../../src/eslint/getJSDocComment';

describe('getJSDocComment', () => {
const linter = new Linter();
it('should get JSDoc comment for node when the node is an ObjectExpression', () => {
const code = [
'/** Desc*/',
'const A = {',
'}'
].join('\n');

const assertJSDoc = function (node) {
const sourceCode = linter.getSourceCode();
const jsdoc = getJSDocComment(sourceCode, node);

assert.strictEqual(jsdoc.type, 'Block');
assert.strictEqual(jsdoc.value, '* Desc');
};

const spy = sinon.spy(assertJSDoc);

linter.defineRule('checker', () => {
return {ObjectExpression: spy};
});
linter.verify(code, {
parserOptions: {ecmaVersion: 6},
rules: {checker: 'error'}
});
assert.isTrue(spy.calledOnce, 'Event handler should be called.');
});
});

0 comments on commit 16b0288

Please sign in to comment.