Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSLint not hooked into build? #6

Closed
dmoles opened this issue Sep 10, 2019 · 4 comments
Closed

TSLint not hooked into build? #6

dmoles opened this issue Sep 10, 2019 · 4 comments

Comments

@dmoles
Copy link

dmoles commented Sep 10, 2019

The build is passing, but when I run npx tslint --project ., I get:

ERROR: /Users/la-dmoles/Scratch/react-you-do-you/src/__tests__/store/reducer.test.ts:38:13 - Identifier 'state' is never reassigned; use 'const' instead of 'let'.
ERROR: /Users/la-dmoles/Scratch/react-you-do-you/src/__tests__/theme/components/ThemeSwitch.test.tsx:8:68 - Lambdas are forbidden in JSX attributes due to their rendering performance impact
ERROR: /Users/la-dmoles/Scratch/react-you-do-you/src/__tests__/theme/components/ThemeSwitch.test.tsx:8:79 - unused expression, expected an assignment or function call
ERROR: /Users/la-dmoles/Scratch/react-you-do-you/src/__tests__/utils.ts:1:27 - block is empty
ERROR: /Users/la-dmoles/Scratch/react-you-do-you/src/__tests__/utils.ts:4:25 - block is empty
ERROR: /Users/la-dmoles/Scratch/react-you-do-you/src/chat/components/ChatErrors.tsx:36:13 - JSX elements with no children must be self-closing

Is there a way to hook TSLint into the build?

@dmoles
Copy link
Author

dmoles commented Sep 10, 2019

(I'm finding examples that use gulp, but that feels like it might be overkill.)

@dmoles
Copy link
Author

dmoles commented Sep 10, 2019

Here's what I've come up with so far for my own project, based on some other examples I've seen out in the wild (e.g. TSLint itself):

  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "lint": "tslint --project .",
    "prettify": "prettier --write 'src/**/*.{js,jsx,ts,tsx,json,css,scss,md}'",
    "lint-fix": "tslint --project . --fix",
    "coverage": "CI=true react-scripts test --coverage",
    "verify": "npm-run-all lint build coverage"
  },

Then customize the CI config to run the verify script instead of (the default) test, something like:

language: node_js

script:
  - npm run verify

netzwerg added a commit that referenced this issue Sep 11, 2019
- Invoke TSLint
- Invoke tsc to type-check tests (facebook/create-react-app#5626)
netzwerg added a commit that referenced this issue Sep 11, 2019
@netzwerg
Copy link
Owner

Ouch, good catch, thank you! 😬

I integrated tslint into the husky pre-commit hook. While I was at it, I also added type checks of the test files, which always bothered me (facebook/create-react-app#5626).

I did not integrate your verify command because I would like the scripts to work with either npm or yarn, but since everything is documented here now, people can copy/paste as they like and configure their CI accordingly.

@dmoles dmoles closed this as completed Sep 11, 2019
@netzwerg
Copy link
Owner

I noticed that a fresh project created through npx create-react-app --typescript has perfect linting support hooked in. Reading this blog post made me aware that we should get rid of TSLint all together and integrate the rules into ESLint (which supports TS).

@netzwerg netzwerg mentioned this issue Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants