Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(eslint): Add object expression in getJSDocComment
- Loading branch information
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.'); | ||
}); | ||
}); |