Tslint: no-unnecessary-qualifier reports qualifier as being in scope when it is not

Created on 27 Mar 2017  ยท  6Comments  ยท  Source: palantir/tslint

Bug Report

  • __TSLint version__: 4.5.1
  • __TypeScript version__: 2.2.1
  • __Running TSLint via__: CLI

TypeScript code being linted

//foo.ts
namespace Foo
{
    export class SomeClass
    {
    }
}

//bar.ts
namespace Bar
{
    export var someVar = new Foo.SomeClass();
}

with tslint.json configuration:

{
    "rules":
    {
        "no-unnecessary-qualifier": true
    }
}

Actual behavior

tslint reports:
bar.ts[3, 27]: Qualifier is unnecessary since 'Foo' is in scope.

Expected behavior

No warning should be emitted, as Foo is not in scope and removing the qualifier will produce code that will not compile.

Note that the two namespaces must be in separate files and the first namespaces declared in those files. Placing a namespace above either Foo or Bar makes the warning go away.

tslint command: tslint -c tslint.json --type-check --project tsconfig.json

tsconfig.json:

{
    "files": [
        "foo.ts",
        "bar.ts"
    ]
}
Medium P3 Bug ๐ŸŒน R.I.P. ๐ŸŒน

Most helpful comment

I have a similar issue but in a slightly different context and the latest version of tslint (v5.10.0) is reporting the error:

export enum FooEnum
{
   FIRST = 0,
   LAST = 1,
   INVALID = 2,
}

export namespace FooEnum
{
   export function isEnumValid (value: FooEnum): boolean
   {
      return value !== FooEnum.INVALID;
   }
}

All 6 comments

I have a similar issue but in a slightly different context and the latest version of tslint (v5.10.0) is reporting the error:

export enum FooEnum
{
   FIRST = 0,
   LAST = 1,
   INVALID = 2,
}

export namespace FooEnum
{
   export function isEnumValid (value: FooEnum): boolean
   {
      return value !== FooEnum.INVALID;
   }
}

Same invalid error with enum and namespace here.

The original code (foo.ts, bar.ts) is no longer an issue, but manu-st's FooEnum still does.

Still having this issue with FooEnum using [email protected]

๐Ÿ’€ _It's time!_ ๐Ÿ’€

TSLint is deprecated and no longer accepting pull requests other than security fixes. See #4534. โ˜ ๏ธ
We recommend you instead use typescript-eslint to lint your TypeScript code with ESLint. โœ…

๐Ÿ‘‹ It was a pleasure open sourcing with you!

๐Ÿค– Beep boop! ๐Ÿ‘‰ TSLint is deprecated ๐Ÿ‘ˆ _(#4534)_ and you should switch to typescript-eslint! ๐Ÿค–

๐Ÿ”’ This issue is being locked to prevent further unnecessary discussions. Thank you! ๐Ÿ‘‹

Was this page helpful?
0 / 5 - 0 ratings