在打字稿文件上启用Eslint [英] Enabling Eslint on typescript files

查看:90
本文介绍了在打字稿文件上启用Eslint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在webstorm附加菜单设置中,有一个附加附加选项字段。
在此添加:

On webstorm eslint setting, there is an "extra eslint options" field. In this, I added:

--ext .ts

来自eslint 文档,该文档应允许eslint处理自定义文件扩展名,在本例中为.ts文件。
这什么都不做。我的语法错误吗?无论如何要在.ts文件上启用Eslint,也许从.eslintrc文件中启用?

from the eslint documentation which is supposed to allow eslint to work on custom file extension, in this case .ts files. This does nothing. Is my syntax wrong ? Anyway to enable Eslint on .ts files, maybe from the .eslintrc file ?

推荐答案

-ext 允许使用自定义javascript扩展名,您不能通过将其他文件扩展名传递给ESLint来强制ESLint用于JavaScript以外的语言。

--ext allows using custom javascript extensions, you can't force ESLint to work for languages other than JavaScript by passing a different file extension to it.

您可以尝试使用 typescript-eslint-parser 为Typescript启用ESLint-它允许构建一个来自打字稿代码的语法树,可以传递给ESLint进行查询。

You can try using typescript-eslint-parser to enable ESLint for Typescript - it allows building a syntax tree from typescript code that can be passed to ESLint for linting.

但是我建议使用打字稿夹棉机检查TypeScript代码。例如,您可以尝试 TSLint

But I'd suggest using Typescript linters for inspecting TypeScript code. You can try TSLint, for example.

更新:自2017.1.3起,WebStorm支持ESLint + typescript-eslint-parser;您只需要安装 typescript 插件和 typescript-eslint-parser 并相应地修改ESLint配置:

Update: since 2017.1.3, WebStorm supports ESLint + typescript-eslint-parser; you just need to install both typescript plugin and typescript-eslint-parser and modify your ESLint config accordingly:

"parser": "typescript-eslint-parser",
"plugins": ["typescript"]

这篇关于在打字稿文件上启用Eslint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆