- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在 Visual Studio 2017 中创建了一个 Web 应用程序并安装了依赖项。
package.json:
{
"version": "1.0.0",
"name": "asp.net",
"private": true,
"devDependencies": {
"@typescript-eslint/parser": "1.7.0",
"eslint": "5.16.0",
"typescript": "3.4.5"
}
}
我已经使用最新的最佳实践为 TypeScript 设置了 ESLint,即 @typescript-eslint/parser
。
.eslintrc:
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"extends": [ "eslint:recommended" ]
},
"rules": {
"quotes": [ "error", "double" ]
}
}
(注意需要双引号的规则。)
我创建了两个文件,test_js.js
和 test_ts.ts
,内容相同:
var x = 'Hello, world';
但是只有JS文件显示引号lint错误:
为什么 Visual Studio 不检查我的 TypeScript 文件?
(交叉发布在 Visual Studio 开发人员社区:https://developercommunity.visualstudio.com/content/problem/552855/why-doesnt-visual-studio-2017-use-eslint-on-typesc.html)
最佳答案
更新:
VS现在does things well .请不要做我在下面做的事。升级 VS 并以正确的方式做事。
原答案:
我已经建立了一个临时的解决方法。
Visual Studio 2017 似乎尊重 tsconfig.json 中提供的 TSLint 设置。不幸的是,它还不接受 ESLint 的 TypeScript 规则。因此,如果我想在 VS 编辑器中检查 TypeScript,我必须使用旧的 tslint.json 样式配置。
tsconfig.json:
{
"compilerOptions": {
"plugins": [
{"name": "typescript-tslint-plugin"}
],
"target": "es5"
},
"exclude": [
"node_modules"
]
}
tslint.json:
{
"rules": {
"quotemark": [true, "double"]
}
}
为了面向 future (当 ESLint 最终吸收 TSLint 时),我希望我的构建过程使用 ESLint。
.michael-eslintrc(我将其命名为这样 VS 就不会使用此配置来检查 JS 文件):
{
"plugins": [
"@typescript-eslint/tslint"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"extends": [ "eslint:recommended" ],
"project": "tsconfig.json",
"sourceType": "module"
},
"rules": {
"@typescript-eslint/tslint/config": [
"warn",
{
"lintFile": "tslint.json"
}
]
}
}
这设置了我需要的所有依赖项。
package.json:
{
"version": "1.0.0",
"name": "asp.net",
"private": true,
"devDependencies": {
"@typescript-eslint/parser": "1.7.0",
"@typescript-eslint/eslint-plugin-tslint": "1.7.0",
"eslint": "5.16.0",
"tslint": "5.16.0",
"typescript": "3.4.5",
"typescript-tslint-plugin": "0.3.1"
}
}
我已将 Webpack 配置为使用此 ESLint 配置进行 linting。所以 Visual Studio 和 Webpack 最终使用相同的 tslint.json 配置,但它们通过不同的路径达到相同的行为。
此解决方法有几个缺点:
关于typescript - 为什么 Visual Studio 2017 不在 TypeScript 文件上使用 ESLint?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55911040/
我遵循文档中的说明 https://www.gatsbyjs.org/docs/eslint/ ,并想覆盖其中一条规则,但不影响其他规则,我所做的是创建一个 .eslintrc.js 文件。 这是文件
是否可以覆盖 TSLINT (tslint.json) 中特定文件的规则,就像沿着这些行的配置一样: "overrides": [{ "files": [ "*.spec.js" ], "ru
我一直试图让 ESLint 在 VS Code 中处理一个新的 Angular 项目,但它无法加载“@typescript-eslint/eslint-plugin”。在过去的 3 个小时里,我一直在
我在某个文件夹中有一些文件,而这些文件来自供应商,因此我无法控制它们。我想为该目录和所有子文件夹中的所有文件禁用 eslint。 最佳答案 您可以添加 .eslintignore在项目根目录下,和.g
我第一次尝试使用汇总,但我不明白为什么会出现此错误: TypeError: eslint is not a function 我之前安装了 rollup (v1.1.0) 然后 eslint npm
我正在尝试使用预提交 Hook 在提交发生之前检测 eslint 错误。我正在使用 husky 和 lint-staged。但它对 src 中的所有文件运行 lint 命令,而不是仅对暂存文件运行
我不确定我正在使用的东西是否存在错误,或者我是否只是在这里设置了错误,但是我在运行 eslint src --fix 关于“eslint-plugin-@typescript-eslint” 我已经指
我正在按照说明从 here 设置 ESLint . ESLint 失败并显示以下消息: $ npm run lint > IACS@1.0.0 lint /some/path/sscce-typesc
我正在使用 airbnb-eslint 和 babel-plugin-module-resolver。我在使用别名导入的每个 js 文件中都收到此错误。 { "extends": ["plugi
我正在将我的项目从 tslint 重新配置为 eslint。我可以手动运行 eslint,但 webpack 无法运行并显示以下错误消息: Module build failed (from /pat
我正在尝试使用 svelte 制作一个应用程序来试用它。 我想设置 prettier 和 eslint,我安装了这些依赖项和 Svelte for VS Code 的扩展。 "dependenci
我正在寻找一个规则来对齐所有 =在任务上。 像这样的事情将是积极的: var foo = 12; var barfoo = 21; var barfoobar = 22; 像这样的事
设置后eslint并在忽略列表中添加一些文件,每次运行 eslint 时,它都会生成有关被忽略文件的警告: /path/to/file/name.min.js 0:0 warning Fil
是否可以将 ESLint 配置为仅将规则应用于名称与特定模式匹配的文件?我知道在目录中可以有单独的规则表,但如果结构如下: app | |- module1 | |- module1.js |
有没有办法禁用文件夹的特定规则?例如,我不希望 test 文件夹中的所有测试文件都包含必需的 JSDoc 注释。有办法做到这一点吗? 最佳答案 要从 eslint 规则中忽略某些文件夹,我们可以在根目
缩进规则似乎无法禁用;如何(在配置设置中)禁用此规则?谢谢。 最佳答案 将规则设置为 "off"在你的配置中是这样的: "rules": { "indent": "off" } 您可以在 the
ESLint 有 dot-location允许决定您是否愿意的规则 object. property 或者 object .property 当打破点时(我更喜欢后者)。 但是,我找不到确保点与对象具
这些库之间有什么区别? babel-eslint [ github.com/babel/babel-eslint ] eslint-plugin-babel [github.com/babel/esl
我想把 Prettier 和 ESLint 一起用,但是一个接一个用就遇到了一些冲突。我看到有这三个包似乎允许它们串联使用: prettier-eslint eslint-plugin-prettie
我正在尝试使用React.js和TypeScrip在ASP.NET核心MVC项目中启用eslint linting,并且正在努力修复上面的错误。。我使用的是Visual Studio2022社区版17
我是一名优秀的程序员,十分优秀!