typescript TSLint 在 VS Code 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49785618/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:21:11  来源:igfitidea点击:

TSLint not working in VS Code

typescriptvisual-studio-codelinttslint

提问by ZeroDarkThirty

I added TSLint to my React/TypeScript project using the tslint VSCode extension. I also installed both typescript and tslint globally according to TSLint docs npm install -g tslint typescript

我使用 tslint VSCode 扩展将 TSLint 添加到我的 React/TypeScript 项目中。我还根据 TSLint 文档全局安装了 typescript 和 tslintnpm install -g tslint typescript

This is my tslint.json file:

这是我的 tslint.json 文件:

{
  "extends": ["tslint:latest", "tslint-react"],
  "rules": {
    // override tslint-react rules here
    "jsx-wrap-multiline": false,
    "max-line-length": false,
    "no-implicit-dependencies": [true, "dev"],
    "no-var-requires": false,
    "indent": false
  }
}

回答by ecraig12345

tslint-reactis a tslint extension which has to be installed separately: npm install -g tslint-react. After installing, reload your VS Code window, and linting should work.

tslint-react是一个必须单独安装的 tslint 扩展:npm install -g tslint-react. 安装后,重新加载 VS Code 窗口,linting 应该可以工作了。



How I found the problem: I copied your config file into a project, went to View > Output to check for errors from the tslint process, and saw this. (be sure to select tslint from the dropdown near the top right)

我是如何发现问题的:我将您的配置文件复制到一个项目中,转到“查看”>“输出”以检查 tslint 进程中的错误,然后看到了这一点。(一定要从靠近右上角的下拉菜单中选择 tslint)

Invalid "extends" configuration value - could not require "tslint-react"

无效的“扩展”配置值 - 不能要求“tslint-react”

回答by badarshahzad

Include the dependency in the package.json

在 package.json 中包含依赖项

This is package.json and its working for me.

这是 package.json 并且它对我有用。

{
  "name": "functions",
  "scripts": {
    "lint": "tslint --project tsconfig.json",
    "build": "tsc",
    "serve": "npm run build && firebase serve --only functions",
    "shell": "npm run build && firebase experimental:functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "main": "lib/index.js",
  "dependencies": {
    "firebase-admin": "~5.11.0",
    "firebase-functions": "^1.0.0"
  },
  "devDependencies": {
    "tslint": "^5.8.0",
    "typescript": "^2.5.3"
  },
  "private": true
}

回答by Tharun208

Add the following in package.json lint: tslint --project tslint.jsonfixed the issue for me.

在 package.json 中添加以下内容 lint: tslint --project tslint.json为我解决了这个问题。