[64, 1]: space indentation expected
[15, 27]: Missing semicolon
[109, 36]: missing whitespace
[111, 24]: missing whitespace
[70, 1]: Consecutive blank lines are forbidden
I keep getting warnings like these from TSLint. There are huge amount of warnings, and it will be very difficult to fix it manually.
I was looking for a way which can auto-fix most of the warnings.
You can use the --fix
option of TSLint to automatically fix most warnings. This might look something like this in a common use case:
tslint --fix -c ./config/tslint.json 'src/**/*{.ts,.tsx}'
Keep in mind that this will overwrite your source code. While this is safe 99.9% of the time, I recommend the following workflow:
--fix
flag like aboveThis way, you'll never be taken surprise by a rogue autocorrection gone wrong.
tslint --fix --project ./tsconfig.json
这是自动修复所有错误是根文件夹
使用@angular/cli 你可以使用ng lint --fix
May be this could help some one looking for autoFix on save!
we can make tslint warnings to get autofixed on save. To do this, go to tslint.json file and add the below settings. [Note: This setting works with latest TSLint and not the deprecated one].
"source.fixAll.tslint": true
After updating this, go to any file and try giving some spaces and it shows tslint warning message as "trailing whitespace" and when you save (Ctrl + S), this warning will get disappear. Though it appears manually, we usually tend to try saving the file once edited and by that time it will get fixed automatically.
Happy coding!
If you using webpack . You can use tslint-loader:
Add this to webpack module rules:
{
test: /\.ts$/,
loader: 'tslint-loader',
enforce: 'pre',
options: {
fix: true
}
}
Read more here: tslint-loader
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.