<?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 Tim Oerlemans on Medium]]></title>
        <description><![CDATA[Stories by Tim Oerlemans on Medium]]></description>
        <link>https://medium.com/@timoerlemans?source=rss-818c888c1d5b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*N-hQULlPa1N53dstsFXqUg.png</url>
            <title>Stories by Tim Oerlemans on Medium</title>
            <link>https://medium.com/@timoerlemans?source=rss-818c888c1d5b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 10:59:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@timoerlemans/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[How I learned to write cleaner code using ESLint]]></title>
            <link>https://medium.com/@timoerlemans/how-i-learned-to-write-cleaner-code-using-eslint-11b5c8b0e1b8?source=rss-818c888c1d5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/11b5c8b0e1b8</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[eslint]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[skills-development]]></category>
            <dc:creator><![CDATA[Tim Oerlemans]]></dc:creator>
            <pubDate>Sun, 19 Aug 2018 13:01:01 GMT</pubDate>
            <atom:updated>2018-09-04T23:01:45.955Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*2GO-u0b4s1QoykYHpLVxng.png" /></figure><p>I have been a professional front-end web developer for almost 2.5 years now. I started out using mostly jQuery, but began using vanilla JavaScript more and more instead of jQuery in the months after. A few months ago, at the start of a new project, a senior developer on my team suggested we get rid of jQuery all together for new projects. At first, I was a bit nervous about it, but I realized I would learn vanilla JavaScript faster if I couldn’t use jQuery to fall back to.</p><p>To help us both write consistent and clean code, the senior developer also introduced <a href="https://eslint.org/">ESLint</a> to our projects. We decided to use the <a href="https://github.com/airbnb/javascript">ESLint config from Airbnb</a>.</p><p>Up to this time, I mostly wrote my vanilla JavaScript in the old syntax (ES5). ESLint with the Airbnb config helped me convert my code to the new syntax, which was surprisingly easy.</p><p>For example, previously I would have written this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*Nw4HKokkOWb-2quyyRzOfA.png" /></figure><p>Technically, there isn’t anything wrong with this code. But let’s see what ESLint thinks of it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WR6CvdJyxoLw681RUjW5JA.png" /></figure><p>As you can see, there are quite some things that can be improved. ESLint has the --fix option, which you can use to automatically fix some errors. But let’s do it ourselves, because that’s how we learn faster.</p><p>Let’s start at the top. unexpected var, use let or const instead (no-var) indicates we use var, where it is better to use either let or const. I will not be going into details about the differences between these three, but if you want to read more about it, you can do that <a href="https://medium.com/craft-academy/javascript-variables-should-you-use-let-var-or-const-394f7645c88f">here</a> and <a href="https://wesbos.com/javascript-scoping/">here</a>. Because the variables will not change further in the code, it’s best to use const.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q6RyjWC_x0BsSc4ESC1GsQ.png" /></figure><p>On to the next error: &#39;i&#39; is not defined. This error appears no less than 5 times, but it’s easily fixed by adding a tweaking the for loop a bit, and defining the i variable using let. This eliminates all 5 errors at once.</p><p>In the same for loop, there’s another error. Unary operator &#39;++&#39; used. We can fix this by changing ++i into i += 1, but because we are looping a <a href="https://developer.mozilla.org/en-US/docs/Web/API/NodeList">nodeList</a>, we can also use the forEach method to loop through the nodeList. If you’re not familiar with this method, check out the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach">MDN reference page</a> for more information. To loop through a nodeList using forEach, we can use the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax">spread operator</a>. Our code now looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QdsKtoQqYHXz5Cw1zV3xNQ.png" /></figure><p>As you can see, we don’t need the imageCount constant anymore, because it’s not used in the forEach method, and it also fixes the unary operator &#39;++&#39; used<em> </em>error <em>(Side note: This constant wasn’t necessary to begin with, but I added it for the sake of clarity).</em></p><p>So let’s run ESLint again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0zIDJM5g-WdzyH6ixMUTBA.png" /></figure><p>As you can see, most errors are fixed now, but the refactoring also resulted in a new error (and a warning). Luckily, both the error and warning can be fixed by converting function(i) to an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions">arrow function</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sdayyiyS4a7KkJkvtI_S3Q.png" /></figure><p>Only one error remains: unexpected string concatenation (prefer-template). ES6 introduced <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals">template literals</a>, where you can use variables and strings together using backticks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OrwPfzYUGWkTAZeYthpyiw.png" /></figure><h3>Conclusion</h3><p>Not only did we refactor our old syntax code to ES6 syntax with almost no effort, we also managed to make the code 27% smaller. Of course, this is just a very simple example and there are way more new functions and methods introduced in ES6+ that ESLint doesn’t help you with, but it’s a great start and also a great tool to keep you on edge every single day.</p><p>Do you want to start using ESLint but don’t know where to start? Check out the <a href="https://eslint.org/docs/user-guide/getting-started">Getting Started</a> section on their website or read <a href="https://medium.com/the-node-js-collection/why-and-how-to-use-eslint-in-your-project-742d0bc61ed7">this article</a>. You can also read more about Airbnb’s ESLint config and their JavaScript style guide <a href="https://github.com/airbnb/javascript">here</a>. If you use React, I recommend using <a href="https://www.npmjs.com/package/eslint-config-airbnb">this config</a>, if not, use their <a href="https://www.npmjs.com/package/eslint-config-airbnb-base">base config</a>.</p><h4>More where this came from</h4><p>This story is published in <a href="http://blog.usejournal.com/">Noteworthy</a>, where thousands come every day to learn about the people &amp; ideas shaping the products we love.</p><p>Follow our publication to see more product &amp; design stories featured by the <a href="https://usejournal.com/?utm_source=usejournal.com&amp;utm_medium=blog&amp;utm_campaign=guest_post">Journal</a> team.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11b5c8b0e1b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>