Tslint: Running tslint with glob from npm script doesn't find files.

Created on 6 Apr 2016  路  7Comments  路  Source: palantir/tslint

Bug Report (delete this for feature requests)

  • TSLint version: 3.7.1
  • TypeScript version: 1.8.9>
  • Running TSLint via: CLI and npm script

    TypeScript code being linted

var a = 1

with tslint.json:

{
    "rules": {
        "semicolon": [true, "always"]
    }
}

Actual behavior

filipe.silva@DESKTOP-7ND6T3R MINGW64 /e/sandbox/tslint-test
$ ls
package.json  test.ts  tslint.json

filipe.silva@DESKTOP-7ND6T3R MINGW64 /e/sandbox/tslint-test
$ cat package.json
{
  "scripts": {
    "lint": "tslint './**/*.ts'"
  }
}

filipe.silva@DESKTOP-7ND6T3R MINGW64 /e/sandbox/tslint-test
$ tslint './**/*.ts'
test.ts[1, 10]: missing semicolon

filipe.silva@DESKTOP-7ND6T3R MINGW64 /e/sandbox/tslint-test
$ npm run lint

> @ lint E:\sandbox\tslint-test
> tslint './**/*.ts'


filipe.silva@DESKTOP-7ND6T3R MINGW64 /e/sandbox/tslint-test
$

Expected behavior

Running tslint via CLI or npm script should yield the same errors.

If I had to bet, I'd say it's related to resolving the path for globs, but have no idea how that is being done in tslint.

External Bug

Most helpful comment

@mysticatea found the real issue: https://github.com/eslint/eslint/issues/5796#issuecomment-206717297!

It's the single quotes. In windows, arguments for npm scripts must use double quotes instead of single quotes.

All 7 comments

First, this is a great bug report! Thanks for the clear and concise report.

I tested your scenario on my machine (I added the --force option just to make the output nicer, didn't change the results) and couldn't duplicate your bug (I'm on OSX):

npm run lint

> @ lint /Users/jkillian/projects/secondary/bug-tslint
> tslint --force './**/*.ts'

test.ts[1, 10]: missing semicolon

This leads me to think it's a Windows/MINGW issue occurring here. Here's something to try that might help us debug:

  1. Change your NPM script so you can debug it with node-inspector: "lint": "node-debug tslint './**/*.ts'"
  2. Set a breakpoint in the lib/tslint-cli.js file where the glob.sync command is.
  3. At this point, see what process.cwd() returns. Also see what the actual glob.sync command is returning.
  4. Compare the results when you run tslint via command line with node-debug tslint './**/*.ts' and with your npm script.

Can you let me know what results you get when doing this?

Heya, thanks for the swift response!

I tried using node-inspector (didn't know if it btw, thank you!) and here is the result for npm run lint:

image

And the result for cli node-debug tslint './**/*.ts':

image

So if I'm reading this correctly, the issue is on glob itself, or perhaps config for it?

I reproduced this issue on the glob repo, with a simpler example: https://github.com/isaacs/node-glob/issues/257

Seems like you're on the right track to getting this figured out. I'll watch that issue and we'll bump any dependencies on glob if needed down the road.

Roger, thanks for the help!

@mysticatea found the real issue: https://github.com/eslint/eslint/issues/5796#issuecomment-206717297!

It's the single quotes. In windows, arguments for npm scripts must use double quotes instead of single quotes.

Ha, who would've guessed. Glad to know the fix though, who knows down the road when a similar bug will pop up for somebody.

Was this page helpful?
0 / 5 - 0 ratings