<?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: Lee Jian Howe</title>
    <description>The latest articles on DEV Community by Lee Jian Howe (@leejianhowe).</description>
    <link>https://dev.to/leejianhowe</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%2F613799%2Ff2ce211f-8f07-40ad-8598-24693da4c694.png</url>
      <title>DEV Community: Lee Jian Howe</title>
      <link>https://dev.to/leejianhowe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/leejianhowe"/>
    <language>en</language>
    <item>
      <title>How to setup eslint for react typescript projects</title>
      <dc:creator>Lee Jian Howe</dc:creator>
      <pubDate>Sun, 25 Apr 2021 16:24:06 +0000</pubDate>
      <link>https://dev.to/leejianhowe/how-to-setup-eslint-for-react-typescript-projects-7ji</link>
      <guid>https://dev.to/leejianhowe/how-to-setup-eslint-for-react-typescript-projects-7ji</guid>
      <description>&lt;p&gt;In this article, i am going to show you how i set up basic linting with eslint for react typescript projects. &lt;/p&gt;

&lt;p&gt;There are many articles online regarding setting up eslint for react. It was a real mess and difficult to figure out which settings to use and what packages to install. After sieving through countless articles and resources, i have finally found a setup which covers all the basics in a react project. &lt;/p&gt;

&lt;p&gt;I normally use &lt;code&gt;npx create-react-app [projectname] --template typescript&lt;/code&gt; to start my react project with typescript template. This template installs eslint for you.&lt;/p&gt;

&lt;p&gt;However, if you do not, you will need to install the eslint and typescript package. &lt;code&gt;npm install eslint typescript&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I would recommend installing and setting up eslint for every project instead of using your own global eslint package/settings. Each project might have different requirements. Your .eslintrc file will be configured to the required linting for each of your projects. It ensures consistency in code for all developers working on the project. &lt;/p&gt;




&lt;p&gt;First, in your react project, create a .eslintrc.json file in the root directory.&lt;/p&gt;

&lt;p&gt;Next, in the json file, use the following set up. For more details on configuring eslint, you can find out more from the eslint &lt;a href="https://eslint.org/docs/user-guide/configuring/#extending-configuration-files" rel="noopener noreferrer"&gt;website&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "env": {
    "browser": true,
    "es6": true,
    "jest": true
  },
  "rules": {
    "no-console": "error",
    "import/first": "error",
    "react/prop-types": "off"
  },
  "extends": [
    "react-app",
    "react-app/jest",
    "eslint:recommended",
    "plugin:react/recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:react-hooks/recommended",
    "prettier"
  ],
  "parser": "@typescript-eslint/parser",
  "root": true,
  "plugins": ["react", "@typescript-eslint"],
  "parserOptions": {
    "ecmaVersion": 11,
    "ecmaFeatures": {
      "jsx": true
    },
    "project": "./tsconfig.json"
  },
  "settings": {
    "react": {
      "pragma": "React",
      "version": "detect"
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;So what are the configurations being set?&lt;/p&gt;

&lt;h3&gt;
  
  
  env
&lt;/h3&gt;

&lt;p&gt;Enables the use of global env variables in your code. Enabling the env variables will prevent eslint from giving errors.&lt;/p&gt;

&lt;h3&gt;
  
  
  rules
&lt;/h3&gt;

&lt;p&gt;Configure/enable/disable specific rules from the plugins and configs&lt;/p&gt;

&lt;h3&gt;
  
  
  extends
&lt;/h3&gt;

&lt;p&gt;Extends configuration files from npm packages.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;react-app - Eslint configuration used by create-react-app&lt;/li&gt;
&lt;li&gt;react-app/jest - Eslint configuration used by create-react-app&lt;/li&gt;
&lt;li&gt;eslint:recommended - Eslint recommended configuration by eslint&lt;/li&gt;
&lt;li&gt;plugin:react/recommended - Recommended react linting configs
&lt;a href="https://github.com/yannickcr/eslint-plugin-react" rel="noopener noreferrer"&gt;details&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;plugin:@typescript-eslint/recommended - Turns on rules from TypeScript-specific plugin. &lt;code&gt;npm install --save-dev @typescript-eslint/eslint-plugin&lt;/code&gt; &lt;a href="https://www.npmjs.com/package/@typescript-eslint/eslint-plugin" rel="noopener noreferrer"&gt;details&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;plugin:react-hooks/recommended - Eslint configuration for react-hooks by create-react-app &lt;a href="https://www.npmjs.com/package/eslint-plugin-react-hooks" rel="noopener noreferrer"&gt;details&lt;/a&gt;. Comes installed together with npx create-react-app&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;prettier - Turns off all rules that are unnecessary or might conflict with Prettier. You will need to install this package for you to use it. &lt;code&gt;npm install --save-dev eslint-config-prettier&lt;/code&gt;&lt;br&gt;
&lt;a href="https://github.com/prettier/eslint-config-prettier" rel="noopener noreferrer"&gt;details&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  plugins
&lt;/h3&gt;

&lt;p&gt;Plugins from npm packages which configures and rules&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;react - For eslint-plugin-react&lt;/li&gt;
&lt;li&gt;@typescript-eslint - For parser and extension @typescript-eslint/recommended &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  parser
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use @typescript-eslint/parser for typescript to work with eslint. This allows Eslint to understand TypeScript syntax.
Install typescript-eslint &lt;code&gt;npm install --save-dev @typescript-eslint/parser&lt;/code&gt; &lt;a href="https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/docs/getting-started/linting/README.md" rel="noopener noreferrer"&gt;details&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  parserOptions
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;ecmaVersions - sets the ECMAScript version you want to support for your project&lt;/li&gt;
&lt;li&gt;ecmaFeatures - set jsx to true for React&lt;/li&gt;
&lt;li&gt;project - Tells Eslint where to find the root tsconfig file of your project. If you have multiple tsconfigs in the project, you can define where the tsconfigs are found. &lt;a href="https://www.npmjs.com/package/@typescript-eslint/parser#configuration" rel="noopener noreferrer"&gt;details&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  settings
&lt;/h3&gt;

&lt;p&gt;The settings made here will be shared across all rules for plugins. For eslint-plugin-react, it will require some defaults setttings:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;pragma: "React" - defaults to React&lt;/li&gt;
&lt;li&gt;version: "detect" - auto detects the version of React
&lt;a href="https://eslint.org/docs/user-guide/configuring/configuration-files#adding-shared-settings" rel="noopener noreferrer"&gt;eslint&lt;/a&gt;
&lt;a href="https://github.com/yannickcr/eslint-plugin-react#configuration" rel="noopener noreferrer"&gt;eslint-plugin-react&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Remember to install vscode extension Eslint and Prettier in order for linting and styling to work. With this configuration, you are all set to write in typescript for any React projects.&lt;/p&gt;




&lt;p&gt;You can add or remove plugins/configs which you find more suitable for your style. Enable rules like "no-console" which will give an error when compiling. Good coding practice for preventing unwanted console logs in your app. Or "import/first" where all import modules must come first at the top of the file. Catches any import errors during compilation.&lt;/p&gt;

&lt;p&gt;Hope this article was useful for you. Leave a comment, like or share if you found it useful. 😄&lt;/p&gt;

</description>
      <category>react</category>
      <category>eslint</category>
      <category>typescript</category>
      <category>prettier</category>
    </item>
    <item>
      <title>Hello World</title>
      <dc:creator>Lee Jian Howe</dc:creator>
      <pubDate>Tue, 13 Apr 2021 16:05:57 +0000</pubDate>
      <link>https://dev.to/leejianhowe/hello-world-38pa</link>
      <guid>https://dev.to/leejianhowe/hello-world-38pa</guid>
      <description>&lt;p&gt;Today, I found out about dev. to. &lt;/p&gt;

&lt;p&gt;A great place for tech enthusiasts. It has a great community of developers from different backgrounds. Many articles to read for new developers like myself and for experienced developers to share their knowledge. &lt;/p&gt;

&lt;p&gt;I will share with you my journey in coming from a non-tech background into tech. I think many of you here are in the same shoes as I am. &lt;/p&gt;

&lt;p&gt;Join me in my journey as I share my experiences. hope you like my articles. would love to hear your thoughts and experiences.❤️&lt;/p&gt;

</description>
      <category>inthirtyseconds</category>
    </item>
  </channel>
</rss>
