Tslint: One-Line Rule error when declaring wildcard ambient modules

Created on 22 Jul 2016  路  15Comments  路  Source: palantir/tslint

Bug Report

  • TSLint version: 3.13.0 and 3.14.0-dev.0
  • TypeScript version: 1.8.10 and 2.0.0
  • Running TSLint via: CLI (with and without NPM), VSCode

    TypeScript code being linted

    declare module "*";

with tslint.json configuration:

"one-line": [
    true,
    "check-open-brace",
    "check-catch",
    "check-else",
    "check-finally",
    "check-whitespace"
],

Actual behavior

if (body.kind === ts.SyntaxKind.ModuleBlock) {
        ^

TypeError: Cannot read property 'kind' of undefined
    at OneLineWalker.visitModuleDeclaration (c:\dev\sandbox\node_modules\tslint\lib\rules\oneLineRule.js:163:17)
    at OneLineWalker.SyntaxWalker.visitNode (c:\dev\sandbox\node_modules\tslint\lib\language\walker\syntaxWalker.js:366:22)
    at c:\dev\sandbox\node_modules\tslint\lib\language\walker\syntaxWalker.js:459:63
    at visitEachNode (c:\dev\sandbox\node_modules\typescript\lib\typescript.js:7959:30)
    at Object.forEachChild (c:\dev\sandbox\node_modules\typescript\lib\typescript.js:8117:24)
    at OneLineWalker.SyntaxWalker.walkChildren (c:\dev\sandbox\node_modules\tslint\lib\language\walker\syntaxWalker.js:459:12)
    at OneLineWalker.SyntaxWalker.visitSourceFile (c:\dev\sandbox\node_modules\tslint\lib\language\walker\syntaxWalker.js:190:14)
    at OneLineWalker.SyntaxWalker.visitNode (c:\dev\sandbox\node_modules\tslint\lib\language\walker\syntaxWalker.js:414:22)
    at OneLineWalker.SyntaxWalker.walk (c:\dev\sandbox\node_modules\tslint\lib\language\walker\syntaxWalker.js:7:14)
    at Rule.AbstractRule.applyWithWalker (c:\dev\sandbox\node_modules\tslint\lib\language\rule\abstractRule.js:19:16)
    at Rule.apply (c:\dev\sandbox\node_modules\tslint\lib\rules\oneLineRule.js:21:21)

Expected behavior

To not error.

Easy Fixed Bug

Most helpful comment

hey folks, sorry for the pain around this bug. I'll cut a new release on the next branch which you can depend on to get the latest TSLint fixes.

All 15 comments

It looks like TypeScript only just recently added wildcard support to ambient module declaration in June to TypeScript 2.0.0. See TypeScript Issue#6615.

Also relevant from their What's New In TypeScript 2.0 wiki entry:

WildChard module names can be even more useful when migrating from an un-typed code base. Combined with Shorthand ambient module declarations, a set of modules can be easily declared as any.

Example

declare module "myLibrary/*";

Should be fairly straightforward to check for this new syntax and not visit the non-existent module block in OneLineWalker if anyone wants to send a bugfix PR.

Was this resolved by #1429 and can be closed?

@macklinu the changes in the commit from #1429 do, indeed, resolve this issue.

Did this get any release? I'm having this bug in 3.15.1

I am getting similar with Webstorm trying to declare a module:

declare module "test";

INFO - avascript.linter.tslint.TsLint - TsLint inner error. TsLint version: 3.15.1

TypeError: Cannot read property 'kind' of undefined

Thanks @arlair I did not see that issue.

What is the reason that a line like

/* tslint:disable */
declare module "test";

before the declare module doesn't work? I am in a situation where this would be the only solution until 4.0 is released, but I'm having no luck.

hey folks, sorry for the pain around this bug. I'll cut a new release on the next branch which you can depend on to get the latest TSLint fixes.

Having the same problem and // tslint:disable-next-line does not work either.

v4.0.0-dev.0 is available now (npm install tslint@next), can you try that?

@adidahiya Yes that works!

Work! Thanks! :)

npm install tslint@next helps me

Was this page helpful?
0 / 5 - 0 ratings