26
votes

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

This is my tslint.json file:

{
  "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
  }
}
3
If either answer helped, can you please mark one as accepted? (or comment if you'd like clarification)ecraig12345

3 Answers

17
votes

tslint-react is 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.


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)

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

2
votes

Include the dependency in the package.json

This is package.json and its working for me.

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

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