eslint-plugin-import: TypeError: Cannot read property 'some' of undefined when `ast.comments` is missing on the AST

https://github.com/benmosher/eslint-plugin-import/blob/1377f55bc3d003519a74a89b048e11b20d53990e/src/ExportMap.js#L333

ExportMap.parse = function (path, content, context) {
  // ...

  // attempt to collect module doc
  ast.comments.some(c => {

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 29 (20 by maintainers)

Commits related to this issue

Most upvoted comments

Would really like to see this published. This error makes the whole experience of linting in editor like VSCode completely broken because plugin exceptions end up as alerts. So any time I save and linter runs, i get exceptions. Had to disable linting for .tsx files all together for now.

@piecyk The thing is that the parserOptions in eslint-plugin-import (eslint-module-utils) get extended with the attachComment option, and not with comment option. https://github.com/benmosher/eslint-plugin-import/blob/d92ef4365b55495dbcce8677f5cbfd08d023440a/utils/parse.js#L22-L23

You’re saying typescript-eslint-parser does not use the attachComment option, rather it requires comment option instead. So there is an incompatibility between different eslint parsers which has to be fixed.

babel-eslint provides both: https://github.com/babel/babel-eslint/blob/37f9242fc6979fdd90e22dd26ef5b1ca7905b486/test/babel-eslint.js#L78-L79 to espree which documents them as follows:

    // create a top-level comments array containing all comments
    comment: false,

    // attach comments to the closest relevant node as leadingComments and trailingComments
    attachComment: false,

@ljharb Definitely! But I have no filePath where I need it yet to get the file extension from (this https://github.com/benmosher/eslint-plugin-import/issues/839 solves it, but it’s not released yet so I cannot install it as a dependency).