Tslint: 'use strict' not allowed in top-level modules when no-unused-expression is enabled

Created on 12 Apr 2016  路  5Comments  路  Source: palantir/tslint

Bug Report

  • TSLint version: 3.7.3
  • TypeScript version: 1.8.9
  • Running TSLint via: CLI

    TypeScript code being linted

namespace StrictTest {
    'use strict';
    export class StrictClass {
        test() {
            console.log('test');
        }
    }
}

with tslint.json:

{
  "rules": {
    "no-unused-expression": true,
    "use-strict": [true, "check-module"]
  }
}

Actual behavior

Strict.ts[2, 5]: expected an assignment or function call

'use strict' expression triggers no-unused-expression violation

Expected behavior

'use strict' expression should not trigger no-unused-expression violation when placed in top of a module/namespace.
In particular, removing the 'use strict' expression from the above code causes a violation of the use-strict rule with the check-module argument.

P1 Fixed Bug

Most helpful comment

Fixed in the just published v3.7.4

All 5 comments

Let's make sure to add a regression test for this kind of usage in https://github.com/palantir/tslint/blob/master/test/rules/no-unused-expression/test.ts.lint

This is a bug, thanks for the heads-up! I guess then that there are four(?) valid locations for this in TS:

  1. At the top of a file
  2. At the top of a function/arrow function
  3. At the top of a namespace/module
  4. At the top of a class (?)

Looking at the spec I'm not entirely sure on #4, but since classes compile down to a function, might be logical?

Edit: It looks like TS won't even emit a 'use strict;' statement at the top of a class, so #4 shouldn't be allowed.

@jbroni I'll have this fixed and published before end of day today, and most likely much sooner

@JKillian Thank you, I appreciate it!

Fixed in the just published v3.7.4

Was this page helpful?
0 / 5 - 0 ratings