Skip to content

Commit

Permalink
Fix import-js#1266, make SourceCode only for no-deprecated rule
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-startsev committed Jan 27, 2019
1 parent 1ec80fa commit d1715d2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/ExportMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ export default class ExportMap {

/**
* parse docs from the first node that has leading comments
* @param {...[type]} nodes [description]
* @param {SourceCode} source parsed source code
* @param {object} docStyleParsers a set of available docs parses
* @return {{doc: object}}
*/
function captureDoc(source, docStyleParsers) {
Expand All @@ -202,9 +203,10 @@ function captureDoc(source, docStyleParsers) {
// 'some' short-circuits on first 'true'
nodes.some(n => {
try {
let commentsBefore = source && source.getCommentsBefore(n)
// n.leadingComments is legacy `attachComments` behavior
let leadingComments = n.leadingComments || source.getCommentsBefore(n)
if (leadingComments.length === 0) return false
let leadingComments = n.leadingComments || commentsBefore
if (!leadingComments || leadingComments.length === 0) return false

for (let name in docStyleParsers) {
const doc = docStyleParsers[name](leadingComments)
Expand Down Expand Up @@ -346,7 +348,7 @@ ExportMap.parse = function (path, content, context) {
docStyleParsers[style] = availableDocStyleParsers[style]
})

const source = makeSourceCode(content, ast)
const source = context.id === 'no-deprecated' ? makeSourceCode(content, ast) : null

// attempt to collect module doc
if (ast.comments) {
Expand Down Expand Up @@ -533,8 +535,9 @@ export function recursivePatternCapture(pattern, callback) {
* don't hold full context object in memory, just grab what we need.
*/
function childContext(path, context) {
const { settings, parserOptions, parserPath } = context
const { id, settings, parserOptions, parserPath } = context
return {
id,
settings,
parserOptions,
parserPath,
Expand Down
4 changes: 3 additions & 1 deletion tests/src/core/getExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('ExportMap', function () {
expect(imports.get('fn'))
.to.have.deep.property('doc.tags[0].title', 'deprecated')
expect(imports.get('fn'))
.to.have.deep.property('doc.tags[0].description', "please use 'x' instead.")
.to.have.deep.property('doc.tags[0].description', 'please use \'x\' instead.')
})

it('works with default imports.', function () {
Expand Down Expand Up @@ -183,6 +183,7 @@ describe('ExportMap', function () {

context('default parser', function () {
jsdocTests({
id: 'no-deprecated',
parserPath: 'espree',
parserOptions: {
sourceType: 'module',
Expand All @@ -194,6 +195,7 @@ describe('ExportMap', function () {

context('babel-eslint', function () {
jsdocTests({
id: 'no-deprecated',
parserPath: 'babel-eslint',
parserOptions: {
sourceType: 'module',
Expand Down
2 changes: 1 addition & 1 deletion tests/src/rules/no-deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ ruleTester.run('no-deprecated', rule, {
],
})

ruleTester.run('no-deprecated: hoisting', rule, {
ruleTester.run('no-deprecated', rule, {
valid: [

test({
Expand Down

0 comments on commit d1715d2

Please sign in to comment.