I'm banging my head for hours trying to enable linting for a TypeScript project created with create-react-app.
The issue is that the suggested implementation above doesn't add any linting to the newly created project.
So far I've tried:
tslint.json
file on my project with the following config: {
"rules": {
"no-debugger": false,
"no-console": false,
"interface-name": false
},
"linterOptions": {
"exclude": [
"config/**/*.js", "node_modules/**/*.ts", "coverage/lcov-report/*.js"
]
},
"extends": [
"tslint:recommended",
"tslint-react",
"tslint-config-prettier"
]
}
package.json
"scripts": {
"lint": "tslint -c tslint.json src/**/*.{ts,tsx} --fix --format verbose"
}
Then I tried running yarn lint or npm run lint
but no files get ever linted from any of the approaches above
this is my package.json
file:
{
"name": "myapp",
"version": "0.1.0",
"private": true,
"dependencies": {
"@types/jest": "^23.3.11",
"@types/node": "^10.12.18",
"@types/react": "^16.7.18",
"@types/react-dom": "^16.0.11",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-scripts": "2.1.2",
"typescript": "^3.2.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"lint": "tslint -c tslint.json src/**/*.{ts,tsx} --fix --format verbose",
"tslint-check": "tslint-config-prettier-check ./tslint.json"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {
"tslint": "^5.12.0",
"tslint-config-prettier": "^1.17.0",
"tslint-react": "^3.6.0"
}
}
This is the tsconfig.json
auto-generated by npx create-react-app [project-name] --typescript
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve"
},
"include": [
"src"
]
}
Any thoughts?
As of the October 2018, 2.1. 0 release, CRA introduced TypeScript support.
TSLint has been the recommended linter in the past but now TSLint is deprecated and ESLint is taking over its duties.
In your VS Code user or workspace settings, set "typescript. tsserver. log": "terse" . Open a TS file that you believe should have TSLint enabled.
TSLint is an extensible static analysis tool that checks TypeScript code for readability, maintainability, and functionality errors. It is widely supported across modern editors & build systems and can be customized with your own lint rules, configurations, and formatters.
The most popular TypeScript linting library is TSLint. It’s pretty similar to the well-known JavaScript linting libraries. In this post, I’ll describe how to install and configure it. Installing TSLint is simple. Instructions can be found here. After installing, you can run
With the TSLint plugin VSCode will highlight and offer suggestions for typescript issues. Now when you format the file ( Shift-Alt-F) you will be asked which formatter you want as a default formatter. Choose Prettier.
@typescript-eslint/eslint-plugin: provides a good dose of typescript-specific eslint rules This file contains essential typescript rules like noImplicitAny, etc. Now that you have your eslint-typescript symbiosis you might want to enforce the auto-fixing of code formatting.
It can help catch bugs, enforce uniform code style, and prevent overly complex code. If you have used JavaScript linting tools, you might be familiar with libraries such as JSLint, JSHint, or ESLint. The most popular TypeScript linting library is TSLint. It’s pretty similar to the well-known JavaScript linting libraries.
I had to go through the same process figuring how to get TSLint and Pretter to work on a CRA + TypeScript project.
I created this gist with step-by-step instructions on how you can set it up accordingly.
The above solution, in a nutshell, is to make sure that you have the appropriate VSCode extensions installed and the appropriate dependencies in your package.json so your changes get tracked by both TSLint and Prettier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With