What is producing "Invalid option for project: true" when running 'tslint --project' on a React project?
Asked Answered
C

1

5

I'm trying to set up tslint to work on a small sample React/Typescript project, following a tutorial online. When I either run yarn lint or simply enter tslint --project in the terminal, I keep getting the error

Invalid option for project: true

I've done a lot of googling, and I can't find what I'm doing wrong.

My tslint.json is

{
  "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
  }
}

and my 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"
  }
}

It may be I've messed up the package.json in converting this from the original eslint version, but I am lost at this point. Any help much appreciated.

Claudio answered 27/8, 2019 at 18:36 Comment(5)
--project needs a param, i think thats for telling it where to get your tsconfig.json file. Something like tslint --project ./some/path/tsconfig.jsonFutilitarian
@JohnRuddell -- That seemed to have worked. But the tslint docs say 'By default, TSLint looks for a configuration file named tslint.json in the directory of the file being linted and, if not found, searches ancestor directories.', and I'm running the command in the same directory as the tslint.json file....Claudio
yea, so in other words, dont pass --project you're incorrectly calling it. just run tslint. If you do pass the project flag then give it a path as well :)Futilitarian
@JohnRuddell -- tslint by itself gives me No files specified. Use --project to lint a project folder.. But tslint --project '.' worksClaudio
lol, like I was saying, either dont pass it (sounds like u need to from that error), or if you do pass it, use it correctly :). Looks like the tsconfig.json file is at the current directory you're running tslint off of. glad that works!Futilitarian
C
6

The trick is that one needs to specify the directory where one is (ts)linting. Thus if you're in the root of your project,

tslint --project '.'

does the trick.

Claudio answered 27/8, 2019 at 18:46 Comment(2)
Thanks , this worked . Error message should say "cannot find project folder" or something more helpful.Gen
I'm getting Invalid option for project: '.'Seminal

© 2022 - 2024 — McMap. All rights reserved.