File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 34
34
"mocha" : " ^6.1.4" ,
35
35
"nyc" : " ^14.1.1" ,
36
36
"semantic-release" : " ^15.13.17" ,
37
+ "sinon" : " ^7.3.2" ,
37
38
"typescript" : " ^3.5.2"
38
39
},
39
40
"engines" : {
Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ const getJSDocComment = function (sourceCode, node) {
70
70
return findJSDocComment ( parent . parent ) ;
71
71
72
72
case 'ArrowFunctionExpression' :
73
+ case 'ObjectExpression' :
73
74
case 'FunctionExpression' :
74
75
if (
75
76
parent . type !== 'CallExpression' &&
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments