<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Janek Ozga on Medium]]></title>
        <description><![CDATA[Stories by Janek Ozga on Medium]]></description>
        <link>https://medium.com/@janekkkk?source=rss-a42a907f1615------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*xVkUc83eWIWGw4uA.jpg</url>
            <title>Stories by Janek Ozga on Medium</title>
            <link>https://medium.com/@janekkkk?source=rss-a42a907f1615------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 09:09:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@janekkkk/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Prettier linting]]></title>
            <link>https://medium.com/@janekkkk/prettier-linting-c2aa755e583b?source=rss-a42a907f1615------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2aa755e583b</guid>
            <category><![CDATA[eslint]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding-style]]></category>
            <dc:creator><![CDATA[Janek Ozga]]></dc:creator>
            <pubDate>Wed, 29 Nov 2017 13:53:43 GMT</pubDate>
            <atom:updated>2018-03-01T18:46:50.905Z</atom:updated>
            <content:encoded><![CDATA[<h4>With ESLint, Prettier and Husky</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n_AHPX0MrFPveTqDft9VpQ.jpeg" /><figcaption>(photo by <a href="https://unsplash.com/photos/pj-BrFZ9eAA">Pan Xiaozhen</a>)</figcaption></figure><p>Recently I’ve been getting into code quality tools as I’ve just started my graduation internship project. I wanted to save my findings for future reference but also share it with my new colleagues and the rest of the world.</p><p>Imagine a world where when you commit your files with Git, it will automatically find issues in your code, fix those issues and afterwards add those fixes to your commit. If this sounds nice to you, keep on reading.</p><h3>Linting</h3><blockquote>Linting is the process of running a program that will analyze code for potential errors.</blockquote><p>Or in human terms: linters are coding tools to show you what you are doing wrong.</p><p>Especially when you are developing in a team, it’s always smart to have a predefined code style. It will:</p><ul><li>Make your code more readable and maintainable</li><li>Help find bugs</li><li>Save you and your team headaches</li></ul><h4>Installing ESLint</h4><p>First install <a href="https://eslint.org/">ESLint</a> globally. <em>I’m using </em><a href="https://yarnpkg.com/en/"><em>Yarn</em></a><em> as package manager but </em><a href="https://www.npmjs.com/">npm</a><em> </em>$ npm install -g eslint <em>is fine as well. If you want to know why you should choose Yarn over npm </em><a href="https://www.sitepoint.com/yarn-vs-npm/"><em>read this article</em></a><em> and </em><a href="https://shift.infinite.red/npm-vs-yarn-cheat-sheet-8755b092e5cc"><em>this cheat sheet</em></a><em>. TL;DR, it’s way faster and the CLI makes more sense.</em></p><pre>$ yarn global add eslint</pre><p>Afterwards create a configuration file using the CLI tool. I like to use a common and popular style, so I chose for <a href="https://standardjs.com/">Standard</a>.</p><pre>$ eslint --init</pre><p>Now add some codestyle errors to your code and run ESLint on your Javascript files! <em>The /**/*.js is a recursive glob pattern. If you don’t know what it can do, </em><a href="https://github.com/isaacs/node-glob#glob-primer"><em>check this out</em></a><em>.</em></p><pre>$ eslint src/**/*.js --color --format stylish</pre><p>ESLint will output something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hY2AEF-skVuoB5np0i8QGA.png" /></figure><h3>Formatting</h3><p>All right, now we’ve found all the things that are wrong with your code, but fixing these simple things feels tedious. Well, have I got a treat for you…</p><p>Prettier is a command line code formatter. It will fix all those issues ESLint throws at us. Running it manually is all right but running it automatically when you run your linter is way more awesome.</p><p><em>It’s also possible to run Prettier and/or ESLint with your </em><a href="https://prettier.io/docs/en/editors.html#docsNav"><em>editor/IDE</em></a><em> if that’s more your thing.</em></p><h4>Installing Prettier</h4><p>Cool, first let’s get Prettier up and running.</p><pre>$ yarn global add prettier</pre><h3>Tung Nguyen on Twitter</h3><p>Finally, a no-semicolon-er could use #Prettier in his project 😍😍😍 #javascript #preact. For #TypeScript, I&#39;m fine with @code&#39;s built-in fmt. https://t.co/JHTI2YLRyX</p><p>Running it via the CLI like this $ prettier src/**/*.js is counter productive and it doesn’t have the same style rules as we set in .eslintrc. Let’s fix that by running it via ESLint. First, install the <a href="https://github.com/sheerun/prettier-standard">prettier-standard</a> and it’s dependencies to ensure the same codestyle.</p><pre>$ yarn add prettier-standard eslint-config-prettier eslint-config-standard eslint-config-prettier-standard --dev</pre><p>Secondly, update your .eslintrc file.</p><pre>{<br>  &quot;extends&quot;: [&quot;prettier-standard&quot;],<br>  &quot;plugins&quot;: [&quot;prettier&quot;],<br>  &quot;rules&quot;: {<br>    &quot;prettier/prettier&quot;: &quot;error&quot;<br>  }<br>}</pre><p>To run it, let’s make a Yarn script for the linter so we won’t have to memorize it every time. Open up your package.json and add the following block.</p><pre>{<br>  &quot;scripts&quot;: { <br>    &quot;format&quot;: &quot;eslint src/**/*.js --fix&quot;<br>  }<br>}</pre><p>If you now run $ yarn format it will automatically run what we just added to the scripts object. Neat, right?</p><p>So now you still have to run your linter manually, like a pleb. Well, I got your back.</p><h3>Git hooks</h3><p><a href="https://git-scm.com/book/gr/v2/Customizing-Git-Git-Hooks">Git hooks</a> will make it so that when you trigger Git with actions such as commit, merge, push, publish, it will execute whatever you tell it to. In our case lint our files and fix the issues it found. Normally it’s a real hassle to set up but Husky makes it real easy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*mdZjft7-tLL9sCvu-IH-Cg.jpeg" /><figcaption>This won’t happen in our case :D</figcaption></figure><p>Let’s install <a href="https://github.com/typicode/husky">Husky </a>(Git hooks made easy) and <a href="https://github.com/okonet/lint-staged#why">lint-staged</a> (to lint the files you want to commit).</p><pre>yarn add husky lint-staged --dev</pre><p>And update your package.json.</p><pre>{<br>  &quot;scripts&quot;: {<br>    &quot;format&quot;: &quot;eslint src/**/*.js --fix&quot;,<br>    &quot;precommit&quot;: &quot;lint-staged&quot; <br>  },<br>  &quot;lint-staged&quot;: {<br>    &quot;src/**/*.js&quot;: [<br>      &quot;eslint --fix&quot;,<br>      &quot;git add&quot;<br>    ]<br>  }<br>}</pre><p>All done! Whenever you add files to staging and try to commit those files they will first be linted by ESLint, afterwards the pesky errors will automatically be fixed by Prettier and added to the staging area.</p><p><em>You can find the result on my </em><a href="https://github.com/janekkkk/prettier-linting"><em>GitHub repository</em></a><em>.</em></p><p>Happy coding :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2aa755e583b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>