I mostly use create-react-app to spin up a new React project. A few days ago, I tried Vue for the first time and it has this feature where it basically prevents the app from running if you have unused imports in your code. Is it possible to give the same functionality to create-react-app?
Asked
Active
Viewed 712 times
1 Answers
1
It already enabled by default (in CRA) by eslint
rule no-unused-vars
'value' is defined but never used. (no-unused-vars)eslint
Which works for unused imports, for example this simple code yields a warning:
// 'useState' is defined but never used. (no-unused-vars)eslint
import React, {useState} from "react";
export default function App() {
return <>...</>;
}
If you want to prevent the app from running, change the config to yield an error
instead.
{
...
"rules": {
"no-unused-vars": ["error"]
}
}

Dennis Vash
- 50,196
- 9
- 100
- 118
-
thanks. I think I have an older version. It doesn't have eslint by default as mentioned in that other post – Wern Ancheta Nov 06 '20 at 06:43
-
Eslint comes in all versions, read the post it has an eslint – Dennis Vash Nov 06 '20 at 06:44