<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dylan Vassallo</title>
    <description>The latest articles on DEV Community by Dylan Vassallo (@codewithachmand).</description>
    <link>https://dev.to/codewithachmand</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F641058%2F348743b4-5f5f-4ed0-ac58-723df1d07581.jpg</url>
      <title>DEV Community: Dylan Vassallo</title>
      <link>https://dev.to/codewithachmand</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codewithachmand"/>
    <language>en</language>
    <item>
      <title>Getting Started with Next.js - VSCode, ESLint and Prettier</title>
      <dc:creator>Dylan Vassallo</dc:creator>
      <pubDate>Mon, 31 May 2021 16:49:56 +0000</pubDate>
      <link>https://dev.to/codewithachmand/getting-started-with-next-js-vscode-eslint-and-prettier-3pap</link>
      <guid>https://dev.to/codewithachmand/getting-started-with-next-js-vscode-eslint-and-prettier-3pap</guid>
      <description>&lt;h1&gt;
  
  
  Getting Started with Next.js
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;"Next.js gives you the best developer experience with all the features you need for production: hybrid static &amp;amp; server rendering, TypeScript support, smart bundling, route pre-fetching, and more. No config needed."&lt;/em&gt; - as stated on &lt;a href="https://nextjs.org/" rel="noopener noreferrer"&gt;Next.js home page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why use Next.js?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://nextjs.org/docs/basic-features/image-optimization" rel="noopener noreferrer"&gt;Image Optimisation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nextjs.org/docs/advanced-features/i18n-routing" rel="noopener noreferrer"&gt;Internationalisation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nextjs.org/analytics" rel="noopener noreferrer"&gt;Next.js Analytics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nextjs.org/docs/getting-started" rel="noopener noreferrer"&gt;Zero Config&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nextjs.org/docs/basic-features/data-fetching" rel="noopener noreferrer"&gt;Hybrid: SSG and SSR&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nextjs.org/docs/basic-features/data-fetching#incremental-static-regeneration" rel="noopener noreferrer"&gt;Incremental Static Regeneration&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nextjs.org/docs/basic-features/typescript" rel="noopener noreferrer"&gt;TypeScript Support&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nextjs.org/docs/basic-features/fast-refresh" rel="noopener noreferrer"&gt;Fast Refresh&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nextjs.org/docs/routing/introduction" rel="noopener noreferrer"&gt;File-System Routing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nextjs.org/docs/api-routes/introduction" rel="noopener noreferrer"&gt;API Routes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nextjs.org/docs/basic-features/built-in-css-support" rel="noopener noreferrer"&gt;Built-in CSS Support&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nextjs.org/docs/advanced-features/dynamic-import" rel="noopener noreferrer"&gt;Code-Splitting and Bundling&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setting up Next.js
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Note: We will be using &lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;Visual Studio Code&lt;/a&gt; as a code editor,  but feel free to use any code editor you are most comfortable with when writing code.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;First we need to install some prerequisites:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://yarnpkg.com/" rel="noopener noreferrer"&gt;yarn&lt;/a&gt; - Package Manager, &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also use &lt;a href="https://www.npmjs.com/" rel="noopener noreferrer"&gt;npm&lt;/a&gt; as a package manager. In this guide, we will make use of yarn.&lt;/p&gt;

&lt;p&gt;We then execute the following command to create a new Next.js app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Replace $PROJECT with your project name&lt;/span&gt;
yarn create next-app &lt;span class="nv"&gt;$PROJECT&lt;/span&gt;
&lt;span class="c"&gt;# Or using the TypeScript flag for a TypeScript project&lt;/span&gt;
yarn create next-app &lt;span class="nt"&gt;--typescript&lt;/span&gt; &lt;span class="nv"&gt;$PROJECTNAME&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The previous command will create a basic project. In this newly created project, you will find a file called &lt;code&gt;package.json&lt;/code&gt;. This file consists of metadata information related to the project, for example; scripts, version and dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"$PROJECT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0.1.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"private"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"dev"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"next dev"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; 
        &lt;/span&gt;&lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"next build"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"next start"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"dependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"next"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"10.2.3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"react"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"17.0.2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"react-dom"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"17.0.2"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The scripts section consists of three different scripts, which when we execute using yarn will: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;yarn dev&lt;/code&gt; : Run the application locally&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;yarn build&lt;/code&gt; : Build the application for production&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;yarn start&lt;/code&gt; : Starts the production version of the application&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Liniting using ESLint
&lt;/h2&gt;

&lt;p&gt;We will be using &lt;a href="https://eslint.org/" rel="noopener noreferrer"&gt;ESLint&lt;/a&gt; as a linter. The main reasons for using this tool is that; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It helps us to catch bugs (by statistically analysing code)&lt;/li&gt;
&lt;li&gt;It helps us to write code in a consistent style&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Installing ESLint extenstion on VSCode
&lt;/h3&gt;

&lt;p&gt;Go to the extensions tab (or use CTRL+SHIFT+X), type in &lt;em&gt;‘ESLint’&lt;/em&gt; and click install.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frll8tqc06j6fkm97im29.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frll8tqc06j6fkm97im29.png" alt="ESLint VS Code Extenstion" width="800" height="238"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting up ESLint
&lt;/h3&gt;

&lt;p&gt;To set up ESLint, we need to execute the following command (make sure you're in the root location of the project).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# This will add eslint as a dev dependency. &lt;/span&gt;
&lt;span class="c"&gt;# If open package.json you will see this new dev dependency added &lt;/span&gt;
&lt;span class="c"&gt;# to the project (once executed). &lt;/span&gt;
yarn add eslint &lt;span class="nt"&gt;--dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next step is to configure our linter. We need to run the following command to be able to create a new configuration file for ESLint.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn run eslint &lt;span class="nt"&gt;--init&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After executing the previous command, you will be prompted with a set of questions. In our set up we selected the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;How would you like to use ESLint?&lt;/strong&gt; &lt;em&gt;To check syntax, find problems, and enforce code style&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What types of modules does your project use?&lt;/strong&gt; &lt;em&gt;Javascript modules (import/export)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Which framework does your project use?&lt;/strong&gt; &lt;em&gt;React&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Does your project use TypeScript?&lt;/strong&gt; &lt;em&gt;No&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Where does your code run?&lt;/strong&gt; &lt;em&gt;Browser&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How would you like to define a style for your project?&lt;/strong&gt; &lt;em&gt;Use a popular style guide&lt;/em&gt; &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Which style guide do you want to follow?&lt;/strong&gt; &lt;em&gt;&lt;a href="https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb" rel="noopener noreferrer"&gt;Airbnb&lt;/a&gt; (In this guide we use this style as it is our personal preference)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What format do you want your config file to be in?&lt;/strong&gt; &lt;em&gt;JSON&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;When prompted to install dependencies select ‘yes’.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After answering all the questions, a new file will be created called &lt;code&gt;.eslintrc.json&lt;/code&gt;. This file holds the configuration for our linter. It is worth noting that we can also specify files that should be ignored by ESLint. This could be done by &lt;a href="https://eslint.org/docs/user-guide/configuring/ignoring-code" rel="noopener noreferrer"&gt;creating a &lt;code&gt;.eslintignore&lt;/code&gt; file&lt;/a&gt;. In our projects, we usually ignore the following directories:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# .estlintignore file
.next
dist
node_modules/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;See &lt;a href="https://github.com/airbnb/javascript" rel="noopener noreferrer"&gt;Airbnb JavaScript styling guide&lt;/a&gt; and the &lt;a href="https://eslint.org/docs/user-guide/configuring/#extending-configuration-files" rel="noopener noreferrer"&gt;ESLint configuration docs&lt;/a&gt; for more information.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Well done, we managed to set up ESLint using Airbnb’s JavaScript styling guide to our newly created Next.js project. You could have used another popular styling guide like &lt;a href="https://github.com/google/eslint-config-google#readme" rel="noopener noreferrer"&gt;Google&lt;/a&gt;, &lt;a href="https://github.com/standard/eslint-config-standard" rel="noopener noreferrer"&gt;Standard&lt;/a&gt;, or even create your own to your liking.&lt;/p&gt;

&lt;h2&gt;
  
  
  Formatting using Prettier
&lt;/h2&gt;

&lt;p&gt;We will be using &lt;a href="https://prettier.io/" rel="noopener noreferrer"&gt;Prettier&lt;/a&gt; as a code formatter. The main reason for using a code formatter is that it helps us maintain consistency throughout our codebase.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing Prettier extenstion on VSCode
&lt;/h3&gt;

&lt;p&gt;Go to the extensions tab (or use CTRL+SHIFT+X), type in &lt;em&gt;‘Prettier’&lt;/em&gt; and click install.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu17xrv1q1xgholdce81z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu17xrv1q1xgholdce81z.png" title="Prettier Extenstion" alt="Prettier VS Code Extenstion" width="800" height="225"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Make sure to set &lt;code&gt;"editor.formatOnSave": true&lt;/code&gt; into your user settings in VSCode to autoformat code when saving a file (CTRL+SHIFT+P -&amp;gt; Open Settings (JSON) -&amp;gt; Paste Configuration). &lt;/p&gt;

&lt;h3&gt;
  
  
  Setting up Prettier
&lt;/h3&gt;

&lt;p&gt;To install prettier to our application, we need to execute the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add &lt;span class="nt"&gt;--dev&lt;/span&gt; &lt;span class="nt"&gt;--exact&lt;/span&gt; prettier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next up is to create an empty configuration file for prettier called &lt;code&gt;.prettierrc.json&lt;/code&gt;. The one shown below is the default configuration we mainly use for our apps, but feel free to &lt;a href="https://prettier.io/docs/en/options.html" rel="noopener noreferrer"&gt;set up your own rules&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"singleQuote"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Use&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;single&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;quotes&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;instead&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;of&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;double&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;quotes&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"tabWidth"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;       &lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Number&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;of&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;spaces&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;per&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;indentation&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;level&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"semi"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Print&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;semicolons&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now since some prettier configs may conflict with ESLint, we need to turn off conflicting rules. This can easily be done by &lt;a href="https://github.com/prettier/eslint-config-prettier" rel="noopener noreferrer"&gt;adding &lt;code&gt;eslint-config-prettier&lt;/code&gt;&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add &lt;span class="nt"&gt;--dev&lt;/span&gt; eslint-config-prettier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, add &lt;code&gt;"prettier"&lt;/code&gt; to the "extends" array in your &lt;code&gt;.eslintrc.json&lt;/code&gt; file. Make sure to put it &lt;strong&gt;last,&lt;/strong&gt; so it gets the chance to override other configs. The file should then look like the one below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"env"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"browser"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"es2021"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"extends"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"plugin:react/recommended"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"airbnb"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"prettier"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"parserOptions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"ecmaFeatures"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"jsx"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"ecmaVersion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"sourceType"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"module"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"plugins"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"react"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"rules"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similar to the previous step when configuring ESLint, we may wish to &lt;a href="https://prettier.io/docs/en/ignore.html" rel="noopener noreferrer"&gt;ignore files from being &lt;em&gt;“prettified”&lt;/em&gt; in our app&lt;/a&gt;. To do so, create a new file called &lt;code&gt;.prettierignore&lt;/code&gt;.  &lt;/p&gt;

&lt;p&gt;&lt;em&gt;It is normally advised to base the &lt;code&gt;.prettierignore&lt;/code&gt; on &lt;code&gt;.gitignore&lt;/code&gt; and &lt;code&gt;.eslintignore&lt;/code&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Well done, we managed to set up Prettier to our newly created Next.js project to help us maintain consistency throughout our codebase.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;If you made use of Airbnb’s styling guide, you may notice that some JavaScript files which were created when we executed the &lt;code&gt;create-next-app&lt;/code&gt; command, are highlighted with errors. This is because the code generated by that command does not follow Airbnb’s styling guide conventions. So how do we fix these errors?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Prop spreading is forbidden &lt;a href="https://github.com/yannickcr/eslint-plugin-react/tree/master/docs/rules/jsx-props-no-spreading.md" rel="noopener noreferrer"&gt;react/jsx-props-no-spreading&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Explicitly state what props are to be received by the component.&lt;/em&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;JSX not allowed in files with extension '.js' &lt;a href="https://github.com/yannickcr/eslint-plugin-react/tree/master/docs/rules/jsx-filename-extension.md" rel="noopener noreferrer"&gt;react/jsx-filename-extension&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Change file from '.js' to '.jsx'&lt;/em&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;'React' must be in scope when using JSX &lt;a href="https://github.com/yannickcr/eslint-plugin-react/tree/master/docs/rules/react-in-jsx-scope.md" rel="noopener noreferrer"&gt;react/react-in-jsx-scope&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Add React import to the file &lt;code&gt;import React from 'react';&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Expected indentation of 2 spaces but found 4 &lt;a href="https://eslint.org/docs/rules/indent" rel="noopener noreferrer"&gt;indent&lt;/a&gt;: &lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you followed the previous steps when configuring the prettier extension, save the file and it will auto-format the code. This issue will be solved, as we set the "tabWidth:2" in &lt;code&gt;.prettierrc.json&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As stated previously, see the &lt;a href="https://github.com/airbnb/javascript" rel="noopener noreferrer"&gt;Airbnb styling guide&lt;/a&gt; and &lt;a href="https://github.com/yannickcr/eslint-plugin-react" rel="noopener noreferrer"&gt;react specific linting rules&lt;/a&gt;, to better understand the errors outputted by the linter. You may also want to &lt;a href="https://eslint.org/docs/user-guide/configuring/rules#disabling-rules" rel="noopener noreferrer"&gt;disable specific rules&lt;/a&gt; which are not to your liking or do not follow your coding standards.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Happy Coding! Feel free to leave any feedback.&lt;/strong&gt; &lt;/p&gt;

</description>
      <category>vscode</category>
      <category>nextjs</category>
      <category>javascript</category>
      <category>npm</category>
    </item>
  </channel>
</rss>
