Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to lint entire folder using tslint

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 the same for tslint - i am getting an error Error: EISDIR: illegal operation on a directory. In their examples on the site - they show how to validate single file, which is not the case usually.

Is that possible to validate my project without extra things like gulp-tslint, just from the command line?

like image 914
ValeriiVasin Avatar asked Apr 06 '16 10:04

ValeriiVasin


People also ask

How do I run a lint on a specific folder?

To lint files of other types or files stored in specific folders, use glob patterns to update the default pattern. To lint files from a specific folder, replace {**/*,*} with <path to the folder>* . As a result, the file linting. coffee will be linted while no_linting.

Is TSLint deprecated?

TSLint has been the recommended linter in the past but now TSLint is deprecated and ESLint is taking over its duties.

Should I use TSLint or ESLint?

I suggest do not use TsLint because it's deprecated and EsLint have more linting features than TsLint . Show activity on this post. TSLint can only be used for TypeScript, while ESLint supports both JavaScript and TypeScript. It is likely, within a large project that you may use both JavaScript and TypeScript.


2 Answers

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)' 
like image 155
JKillian Avatar answered Sep 21 '22 04:09

JKillian


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.

like image 38
Matt Browne Avatar answered Sep 22 '22 04:09

Matt Browne