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

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

Closed
jbroni opened this issue Apr 12, 2016 · 5 comments

Comments

@jbroni
Copy link

jbroni commented Apr 12, 2016

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.

@adidahiya
Copy link
Contributor

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

@jkillian
Copy link
Contributor

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.

@jkillian
Copy link
Contributor

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

@jbroni
Copy link
Author

jbroni commented Apr 12, 2016

@jkillian Thank you, I appreciate it!

@jkillian
Copy link
Contributor

Fixed in the just published v3.7.4

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

3 participants