【问题标题】:TSLint not working in VS CodeTSLint 在 VS 代码中不起作用
【发布时间】:2018-09-21 23:04:20
【问题描述】:

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

这是我的 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
  }
}

【问题讨论】:

  • 如果任一答案有帮助,您能否将其中一个标记为已接受? (或评论,如果你想澄清)

标签: typescript visual-studio-code lint tslint


【解决方案1】:

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


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

【讨论】:

  • 感谢分享输出 tslint 技巧。在那里发现了一个问题并修复了我的tslint.json
  • 我在输出中没有 tslint 选项。
【解决方案2】:

在 package.json 中包含依赖

这是 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
}

【讨论】:

  • 不适合我,安装了tslint,还有tslint.json
【解决方案3】:

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

【讨论】:

    猜你喜欢
    • 2019-06-23
    • 2018-02-07
    • 1970-01-01
    • 2019-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-05
    • 1970-01-01
    相关资源
    最近更新 更多