【问题标题】:What is producing "Invalid option for project: true" when running 'tslint --project' on a React project?在 React 项目上运行“tslint --project”时,什么会产生“项目的无效选项:true”?
【发布时间】:2019-12-31 23:26:50
【问题描述】:

我正在尝试设置 tslint 以处理一个小型示例 React/Typescript 项目,遵循在线教程。当我运行yarn lint 或只是在终端中输入tslint --project 时,我不断收到错误

项目选项无效:true

我用谷歌搜索了很多,但我找不到我做错了什么。

我的tslint.json

{
  "extends": [
    "tslint:recommended",
    "tslint-react",
    "tslint-config-prettier"
  ],
  "rules": {
    "ordered-imports": false,
    "object-literal-sort-keys": false,
    "no-console": false,
    "jsx-no-lambda": false,
    "member-ordering": false
  }
}

还有我的package.jsonis

{
  "name": "something",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "parcel ./src/index.html",
    "lint": "tslint --project",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/plugin-transform-runtime": "^7.5.5",
    "@babel/preset-env": "^7.5.5",
    "@types/react": "^16.9.2",
    "@types/react-dom": "^16.9.0",
    "babel-preset-react": "^7.0.0-beta.3",
    "parcel-bundler": "^1.12.3",
    "prettier": "^1.18.2",
    "tslint": "^5.19.0",
    "tslint-config-prettier": "^1.18.0",
    "tslint-react": "^4.0.0"
  },
  "dependencies": {
    "@babel/core": "^7.0.0",
    "@emotion/babel-preset-css-prop": "^10.0.14",
    "@emotion/core": "^10.0.16",
    "@emotion/styled": "^10.0.15",
    "axios": "^0.19.0",
    "babel": "^6.23.0",
    "bulma": "^0.7.5",
    "node-sass": "^4.12.0",
    "prop-types": "^15.7.2",
    "react": "^16.9.0",
    "react-dom": "^16.9.0",
    "typescript": "^3.5.3"
  }
}

可能是我把 package.json 从原来的 eslint 版本转换过来时弄乱了,但我现在迷路了。非常感谢任何帮助。

【问题讨论】:

  • --project 需要一个参数,我认为这就是告诉它在哪里获取您的tsconfig.json 文件。类似tslint --project ./some/path/tsconfig.json
  • @JohnRuddell -- 这似乎奏效了。但是 tslint 文档说“默认情况下,TSLint 在被检查的文件的目录中查找名为 tslint.json 的配置文件,如果找不到,则搜索祖先目录。”,我在同一目录中运行该命令作为 tslint.json 文件....
  • 是的,换句话说,不要传递--project,你叫错了。只需运行tslint。如果你确实传递了项目标志,那么也给它一个路径:)
  • @JohnRuddell -- tslint 本身给了我No files specified. Use --project to lint a project folder.。但是tslint --project '.' 有效
  • 大声笑,就像我说的那样,要么不要通过它(听起来你需要从那个错误中解脱出来),或者如果你确实通过了它,请正确使用它:)。看起来 tsconfig.json 文件位于您正在运行 tslint 的当前目录中。很高兴这有效!

标签: reactjs typescript tslint


【解决方案1】:

诀窍是需要指定 (ts) linting 所在的目录。因此,如果您位于项目的根目录中,

tslint --project '.'

成功了。

【讨论】:

  • 谢谢,这行得通。错误消息应该说“找不到项目文件夹”或更有用的内容。
  • 我收到Invalid option for project: '.'
猜你喜欢
  • 2015-09-19
  • 2021-12-20
  • 2020-09-07
  • 2013-06-05
  • 1970-01-01
  • 2017-10-23
  • 2019-05-05
  • 2017-06-02
  • 1970-01-01
相关资源
最近更新 更多