在 React 项目上运行 'tslint --project' 时,什么会产生“项目的无效选项:true”?

IT技术 reactjs typescript tslint
2021-04-28 20:04:33

我正在尝试按照在线教程设置 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.json

{
  "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版本转换时搞砸了,但此时我迷路了。非常感谢任何帮助。

1个回答

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

tslint --project '.'

诀窍。