Linting a React app with Nx

Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

Nx already comes with a default TypeScript setup. Although you can opt-out of that and generate plain JS based components, especially in a large setup TypeScript can be beneficial in uncovering potential issues early. To add an extra level, Nx also comes with preconfigured eslint for all the apps and libraries. In this lesson we're going to explore the lint setup and how it can be used.

Instructor: [0:00] Besides of working web server setup, a build setup, test setup, Nx also comes with some ESLint rule already predefined and set up for you.

[0:09] At the very root of the workspace, you see that eslintrc file, which contains the variety of predefined rules which are being considered best practice especially in a monorepo situation or monorepo workspace.

[0:21] If you open up the workspace.json again, and we go to our store project or any project you would like, you will see a lint target set up for us. It has a builder here which comes from a Novell linter package, which will run the linting process and a variety of options here that are being passed in.

[0:38] Again, in order to run the lint command, you can use the nx run command, run store:lint, and it will now lint our project for potential issues.

[0:47] In fact, you can see here in our App.jsx file, we have a problem that the React took useEffect as a missing dependency state. Let's go and see that. If we scroll in, you can also see that the Visual Studio Code correctly detects that rule violation, as we also get that hover state here. The problem is that we use the state variable here, which we don't reference as a dependency.

[1:10] There is a better way to do that. We need to just wrap that state in a function callback. We do something like that, we get the state as a primary in there, we use that, and we manipulate it here. Similarly, we also do it here and also here.

[1:29] If we run the linting rule another time, we should be good and have no errors at all. Awesome, so all files pass our linting. Also, this works for all of the variety of projects which we have in our workspace in the very same way.

egghead
egghead
~ 21 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today