Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

One-Line Rule error when declaring wildcard ambient modules #1425

Closed
nchutchind opened this issue Jul 22, 2016 · 15 comments
Closed

One-Line Rule error when declaring wildcard ambient modules #1425

nchutchind opened this issue Jul 22, 2016 · 15 comments

Comments

@nchutchind
Copy link

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.

@nchutchind
Copy link
Author

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/*";

@adidahiya
Copy link
Contributor

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.

jkillian pushed a commit that referenced this issue Jul 25, 2016
adidahiya pushed a commit that referenced this issue Jul 25, 2016
@macklinu
Copy link

Was this resolved by #1429 and can be closed?

@nchutchind
Copy link
Author

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

@michaeljota
Copy link

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

@arlair
Copy link

arlair commented Oct 3, 2016

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

@arlair
Copy link

arlair commented Oct 3, 2016

Oh, looks like this might be coming in Version 4.
"The changes in #1429 will be available in the next TSLint release, which will be 4.0"

@michaeljota
Copy link

Thanks @arlair I did not see that issue.

@michael-brade
Copy link

michael-brade commented Oct 4, 2016

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.

@adidahiya
Copy link
Contributor

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.

@jonaskello
Copy link
Contributor

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

@adidahiya
Copy link
Contributor

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

@adidahiya adidahiya added this to the TSLint v4.0 milestone Oct 5, 2016
@jonaskello
Copy link
Contributor

@adidahiya Yes that works!

@michaeljota
Copy link

Work! Thanks! :)

@Andrey-Pavlov
Copy link

npm install tslint@next helps me

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants