microsoft/tslint-microsoft-contrib

export-name: crashes with "Cannot read property 'elements' of undefined"

maschino opened this issue · 2 comments

Bug Report

The linting rule export-name crashes if there's a file containing only one export * from './Foobar'.

  • tslint-microsoft-contrib version: 6.0.0
  • TSLint version: 5.11.0
  • TypeScript version: 3.1.6
  • Running TSLint via: (pick one) CLI npx tslint --project .

TypeScript code being linted

export * from './ValidationWrapper';

with tslint.json configuration:

{
  "extends": ["tslint-eaa-contrib"],
  "linterOptions": {
    "exclude": [
      "config/**"
    ]
  }
}

(It's basically our own ruleset which enables / disables some rules, including from the tslint-microsoft-contrib package)

Actual behavior

npx tslint --project .
The 'export-name' rule threw an error in 'c:/Source/react-ocean-forms/src/components/withValidation/ValidationWrapper/index.ts':
TypeError: Cannot read property 'elements' of undefined
    at getExportsFromStatement (c:\Source\react-ocean-forms\node_modules\tslint-microsoft-contrib\exportNameRule.js:97:27)
    at ExportNameWalker.visitSourceFile (c:\Source\react-ocean-forms\node_modules\tslint-microsoft-contrib\exportNameRule.js:112:35)
    at ExportNameWalker.SyntaxWalker.visitNode (c:\Source\react-ocean-forms\node_modules\tslint\lib\language\walker\syntaxWalker.js:482:22)
    at ExportNameWalker.SyntaxWalker.walk (c:\Source\react-ocean-forms\node_modules\tslint\lib\language\walker\syntaxWalker.js:24:14)
    at Rule.AbstractRule.applyWithWalker (c:\Source\react-ocean-forms\node_modules\tslint\lib\language\rule\abstractRule.js:31:16)
    at Rule.apply (c:\Source\react-ocean-forms\node_modules\tslint-microsoft-contrib\exportNameRule.js:27:21)
    at Linter.applyRule (c:\Source\react-ocean-forms\node_modules\tslint\lib\linter.js:197:29)
    at c:\Source\react-ocean-forms\node_modules\tslint\lib\linter.js:139:85
    at Object.flatMap (c:\Source\react-ocean-forms\node_modules\tslint\lib\utils.js:151:29)
    at Linter.getAllFailures (c:\Source\react-ocean-forms\node_modules\tslint\lib\linter.js:139:32)

Expected behavior

Rule should not crash and no linting issue should be found.

It seems that the rule crashes if there's an file with only one export * from './Foobar'. The crash goes away if I have more than one export * from './Foo' per file.

is this fixed? Which version is it fixed in? I did update everything to latest one.

@cyberhck not releases yet. 6.1 is tracked in #788