How to lint entire folder using tslint

后端 未结 3 1452
隐瞒了意图╮
隐瞒了意图╮ 2020-12-24 00:14

Is that possible to lint entire folder using tslint?

Using eslint it is possible to do eslint ./src to validate whole folder.

When i try to do

相关标签:
3条回答
  • 2020-12-24 00:56

    If your project has a tsconfig.json you can aproach --project advange.

    In my case I have a nativescript project wich includes a tsconfig.json at project root, so I have this:

    Note that in the json 'node_modules' and 'platforms' directories are excluded. This means that all files in the project are going to be mapped except 'node_modules' and 'platforms' directories.

    I have added this scripts at my package.json, 'tslint' to log the errors and 'tslint-fix' to fix the errors.

    "scripts": {
        "tslint": "tslint -p tsconfig.json",
        "tslint-fix": "tslint --fix -p tsconfig.json"
    }
    
    0 讨论(0)
  • 2020-12-24 01:05

    You can use a glob to lint multiple files.

    Normally, if you just pass a glob as is, your shell will expand it and pass the resulting files to TSLint. So for example, in bash 4+ with the globstar option enabled, you could do the following to lint all .ts and .tsx files:

    tslint src/**/*.ts{,x}
    

    You're probably better off though using a command that will work consistently across platforms and shells though. For this, you can pass the glob in quotes. When in quotes, the glob will get passed as is to TSLint which will handle it with node-glob. You could then run the following command to get the same results as above:

    tslint 'src/**/*.ts?(x)'
    
    0 讨论(0)
  • 2020-12-24 01:06

    There is now a --project option for this. Example:

    tslint --project .
    

    From the docs:

    -p, --project:

    The path or directory containing a tsconfig.json file that will be used to determine which files will be linted. This flag also enables rules that require the type checker.

    0 讨论(0)
提交回复
热议问题