This video is available to students only

Enforcing consistent patterns and syntax is an important part of maintaining a component library. Code linting tools help enforce consistent code formatting and ensure that important code-quality rules are being followed.

In this lesson we will be adding Prettier and ESLint to our codebase.

Prettier#

Prettier is a code formatter with support for most types of files. It focuses on ensuring that our codebase follows consistent formatting rules, like max line length and consistent comma usage. Let's install it with the following command:

Prettier comes with an opinionated set of default style rules. For our library we will override the singleQuote configuration by creating a .prettierrc file at the root of the repository.

Next, let's add a new NPM script to format our files. Modify our package.json to include a new format script:

Run the new script to format our codebase.

ESLint#

ESLint is a static analysis tool that allows us to ensure that our code follows specific code-quality rules. By including additional ESLint plugins we are able to reduce potential React and TypeScript bugs.

We will be using the following plugins in our library:

Start a new discussion. All notification go to the author.