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?
1 Answer
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"]
}
}
-
thanks. I think I have an older version. It doesn't have eslint by default as mentioned in that other post Commented Nov 6, 2020 at 6:43
-
Eslint comes in all versions, read the post it has an eslint Commented Nov 6, 2020 at 6:44