<?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 Dominik Ferber on Medium]]></title>
        <description><![CDATA[Stories by Dominik Ferber on Medium]]></description>
        <link>https://medium.com/@dferber90?source=rss-5f79bc607ab9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*MTPqn8a9MxLikmbsJm907Q.jpeg</url>
            <title>Stories by Dominik Ferber on Medium</title>
            <link>https://medium.com/@dferber90?source=rss-5f79bc607ab9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 02:49:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dferber90/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[Release your features with confidence]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://frontend-digest.com/next-js-feature-flags-in-5-minutes-c0fa6822b3b8?source=rss-5f79bc607ab9------2"><img src="https://cdn-images-1.medium.com/max/2600/0*4kR0k8t2MEhxxzq9" width="6000"></a></p><p class="medium-feed-snippet">Next.js: Feature Flags in 5 Minutes</p><p class="medium-feed-link"><a href="https://frontend-digest.com/next-js-feature-flags-in-5-minutes-c0fa6822b3b8?source=rss-5f79bc607ab9------2">Continue reading on Frontend Digest »</a></p></div>]]></description>
            <link>https://frontend-digest.com/next-js-feature-flags-in-5-minutes-c0fa6822b3b8?source=rss-5f79bc607ab9------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0fa6822b3b8</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ab-testing]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[feature-flags]]></category>
            <dc:creator><![CDATA[Dominik Ferber]]></dc:creator>
            <pubDate>Sat, 18 Dec 2021 12:44:45 GMT</pubDate>
            <atom:updated>2022-09-12T08:22:44.934Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Using Playwright to test Next.js applications]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://frontend-digest.com/using-playwright-to-test-next-js-applications-80a767540091?source=rss-5f79bc607ab9------2"><img src="https://cdn-images-1.medium.com/max/2600/0*Afw_dGlMFm6lYY3u" width="6000"></a></p><p class="medium-feed-snippet">My favourite new testing setup with the best mocking ever and visual regression testing.</p><p class="medium-feed-link"><a href="https://frontend-digest.com/using-playwright-to-test-next-js-applications-80a767540091?source=rss-5f79bc607ab9------2">Continue reading on Frontend Digest »</a></p></div>]]></description>
            <link>https://frontend-digest.com/using-playwright-to-test-next-js-applications-80a767540091?source=rss-5f79bc607ab9------2</link>
            <guid isPermaLink="false">https://medium.com/p/80a767540091</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Dominik Ferber]]></dc:creator>
            <pubDate>Sun, 13 Jun 2021 11:34:08 GMT</pubDate>
            <atom:updated>2022-02-01T14:14:35.531Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Using Feature Flags in Next.js]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://frontend-digest.com/using-feature-flags-in-next-js-c5c8d0795a2?source=rss-5f79bc607ab9------2"><img src="https://cdn-images-1.medium.com/max/2600/0*icmkoI1zz-Obsj0K" width="6720"></a></p><p class="medium-feed-snippet">How to use Feature Flags to test drive features in production before releasing them to everyone. Includes lots of happy dogs!</p><p class="medium-feed-link"><a href="https://frontend-digest.com/using-feature-flags-in-next-js-c5c8d0795a2?source=rss-5f79bc607ab9------2">Continue reading on Frontend Digest »</a></p></div>]]></description>
            <link>https://frontend-digest.com/using-feature-flags-in-next-js-c5c8d0795a2?source=rss-5f79bc607ab9------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5c8d0795a2</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Dominik Ferber]]></dc:creator>
            <pubDate>Mon, 21 Sep 2020 11:22:08 GMT</pubDate>
            <atom:updated>2022-09-12T12:22:54.919Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How to speed up your getServerSideProps]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://frontend-digest.com/efficient-data-fetching-in-next-js-a7214f088b23?source=rss-5f79bc607ab9------2"><img src="https://cdn-images-1.medium.com/max/2600/0*mww3G127j1MKarCu" width="5184"></a></p><p class="medium-feed-snippet">Efficient data fetching in Next.js</p><p class="medium-feed-link"><a href="https://frontend-digest.com/efficient-data-fetching-in-next-js-a7214f088b23?source=rss-5f79bc607ab9------2">Continue reading on Frontend Digest »</a></p></div>]]></description>
            <link>https://frontend-digest.com/efficient-data-fetching-in-next-js-a7214f088b23?source=rss-5f79bc607ab9------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7214f088b23</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Dominik Ferber]]></dc:creator>
            <pubDate>Mon, 18 May 2020 09:31:22 GMT</pubDate>
            <atom:updated>2020-09-11T05:26:19.150Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Environment Variables in Next.js]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://frontend-digest.com/environment-variables-in-next-js-9a272f0bf655?source=rss-5f79bc607ab9------2"><img src="https://cdn-images-1.medium.com/max/2600/0*Ju_aenjrGZ9cuK0N" width="5472"></a></p><p class="medium-feed-snippet">How to set them up for development and production</p><p class="medium-feed-link"><a href="https://frontend-digest.com/environment-variables-in-next-js-9a272f0bf655?source=rss-5f79bc607ab9------2">Continue reading on Frontend Digest »</a></p></div>]]></description>
            <link>https://frontend-digest.com/environment-variables-in-next-js-9a272f0bf655?source=rss-5f79bc607ab9------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a272f0bf655</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[vercel]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Dominik Ferber]]></dc:creator>
            <pubDate>Wed, 06 May 2020 12:45:48 GMT</pubDate>
            <atom:updated>2021-06-09T16:43:45.920Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Authentication in Next.js using Amazon Cognito]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://frontend-digest.com/authentication-in-next-js-using-amazon-cognito-f30efed6a24f?source=rss-5f79bc607ab9------2"><img src="https://cdn-images-1.medium.com/max/2600/0*okZyzIWwn9t7fE2u" width="6000"></a></p><p class="medium-feed-snippet">Learn how to set up authentication in Next.js using Amazon Cognito as a user directory. Supports server-side rendering and sync..</p><p class="medium-feed-link"><a href="https://frontend-digest.com/authentication-in-next-js-using-amazon-cognito-f30efed6a24f?source=rss-5f79bc607ab9------2">Continue reading on Frontend Digest »</a></p></div>]]></description>
            <link>https://frontend-digest.com/authentication-in-next-js-using-amazon-cognito-f30efed6a24f?source=rss-5f79bc607ab9------2</link>
            <guid isPermaLink="false">https://medium.com/p/f30efed6a24f</guid>
            <category><![CDATA[aws-cognito]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Dominik Ferber]]></dc:creator>
            <pubDate>Thu, 30 Apr 2020 12:11:22 GMT</pubDate>
            <atom:updated>2021-12-09T05:50:17.684Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[A really cool new exploration in CSS-in-JS land that I’m keeping my eyes on]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://frontend-digest.com/a-really-cool-new-exploration-in-css-in-js-land-that-im-keeping-my-eyes-on-76d4b0c479d4?source=rss-5f79bc607ab9------2"><img src="https://cdn-images-1.medium.com/max/2600/0*Rf3GcYvgX25x7Fml" width="6016"></a></p><p class="medium-feed-snippet">Let&#x2019;s take a look at Compiled. It aims to provide the familiar CSS-in-JS authoring experience but without the runtime cost.</p><p class="medium-feed-link"><a href="https://frontend-digest.com/a-really-cool-new-exploration-in-css-in-js-land-that-im-keeping-my-eyes-on-76d4b0c479d4?source=rss-5f79bc607ab9------2">Continue reading on Frontend Digest »</a></p></div>]]></description>
            <link>https://frontend-digest.com/a-really-cool-new-exploration-in-css-in-js-land-that-im-keeping-my-eyes-on-76d4b0c479d4?source=rss-5f79bc607ab9------2</link>
            <guid isPermaLink="false">https://medium.com/p/76d4b0c479d4</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[css-in-js]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Dominik Ferber]]></dc:creator>
            <pubDate>Fri, 17 Apr 2020 08:34:50 GMT</pubDate>
            <atom:updated>2020-04-17T08:34:50.925Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Test a Render Prop!]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">aka the missing paragraphs of &#x201C;Use a Render Prop!&#x201D;</p><p class="medium-feed-link"><a href="https://medium.com/@dferber90/test-a-render-prop-6a44e02f4c39?source=rss-5f79bc607ab9------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@dferber90/test-a-render-prop-6a44e02f4c39?source=rss-5f79bc607ab9------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a44e02f4c39</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[enzyme]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Dominik Ferber]]></dc:creator>
            <pubDate>Fri, 25 May 2018 14:09:20 GMT</pubDate>
            <atom:updated>2018-12-16T18:31:02.279Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Enabling assets for Server-Side Rendering in Webpack]]></title>
            <link>https://medium.com/@dferber90/enabling-assets-for-server-side-rendering-in-webpack-a843a5ebeb0c?source=rss-5f79bc607ab9------2</link>
            <guid isPermaLink="false">https://medium.com/p/a843a5ebeb0c</guid>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Dominik Ferber]]></dc:creator>
            <pubDate>Sat, 09 Apr 2016 09:28:53 GMT</pubDate>
            <atom:updated>2016-07-27T07:27:53.570Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>Notice: </em></strong><em>A lot has changed since this article was written. </em><strong><em>file-loader</em></strong><em> and </em><strong><em>url-loader</em></strong><em> support not-emitting-files themselves now, so</em><strong><em> fake-file-loader</em></strong><em> and </em><strong><em>fake-url-loader</em></strong><em> are deprecated. </em><strong><em>fake-style-loader</em></strong><em> can be replaced by using </em><strong><em>css-loader/locals</em></strong><em> as explained in </em><a href="https://github.com/dferber90/fake-style-loader/issues/3"><em>fake-style-loader#3</em></a><em>. So, do not use the </em><strong><em>fake</em></strong><em> module family anymore. It is recommended to use </em><strong><em>css-loader</em></strong><em>, </em><strong><em>file-loader</em></strong><em> and </em><strong><em>url-loader</em></strong><em> directly instead.</em></p><p><em>It’s still worth reading the article to familiarize yourself with the concepts.</em></p><p>Webpack is commonly used to build the client bundle of web applications. To improve perceived load times, web applications may render on the server. Ideally the code for the components used by the web app should be shared by the code generating the client and server bundle. Commonly, two separate Webpack configurations are used to achieve this, where each imported dependency of a component is interpreted differently depending on whether Webpack currently creates the client or server bundle.</p><p>When importing an image from a component, Webpack typically emits the image to the assets and resolves the import with the URL to the emitted file. This is also true for other assets like CSS files and fonts. If we’d now simply add the same configuration for the server bundle, <strong>Webpack would emit the files twice, possibly resulting in different URLs</strong>. This is more work and increases the build time unnecessarily. The markup generated during SSR could then possibly differ from the markup generated by the browser because of the different URLs, and React would complain.</p><p>Another exception is the style-loader, which attaches the imported style sheets to the DOM. When rendering on the server, there is no DOM so an exception occurs.</p><p>One existing solution is <a href="https://github.com/halt-hammerzeit/webpack-isomorphic-tools">webpack-isomorphic-tools</a>, but I found this very hard to set up although it seems to have a lot of power. I couldn’t get it to work properly and eventually gave up.</p><h4>Solution</h4><p>There is a flag called <em>emitFile</em> in <em>file-loader. </em>When enabled, <em>file-loader </em>will skip the emission of the asset and simply return the generated file name. Since <em>url-loader</em> uses <em>file-loader</em> behind the scenes, the same flag can be used there. So you’d use your regular file-loader for the client bundle and append <em>emitFile=false </em>in the server Webpack configuration. This solves the problem for static assets.</p><p>However, this does not yet work for styles.</p><h4>Introducing fake-style-loader</h4><p><em>fake-style-loader </em>enables loading CSS modules on the server. It returns the names of the generated identifiers and further enables access to the underlying CSS so it can be served inline (or extracted to a file).</p><p><a href="https://www.npmjs.com/package/fake-style-loader">https://www.npmjs.com/package/fake-style-loader</a></p><p>From webpack’s <em>style-loader</em> documentation:</p><blockquote>When using <a href="https://github.com/webpack/css-loader#local-scope">local scope CSS</a> the module exports the generated identifiers</blockquote><blockquote>var style = require(&quot;style!css!./file.css&quot;);<br>style.placeholder1 === &quot;z849f98ca812bc0d099a43e0f90184&quot;</blockquote><p>To enable loading CSS modules on the server, we don’t need the <em>attach style-tags-to-DOM</em> magic style-loader does, because there is no DOM. Instead, we simply need to know the names of the identifiers.</p><p>The intention is to use the regular <em>style-loader</em> for the client-side bundle and the <em>fake-style-loader </em>for the server bundle. Now there will only be one emitted file, but the exported URLs will be available to both bundles. Just like with <em>file-loader</em> and the <em>url-loader. </em>Here’s an example of two Webpack configurations:</p><pre><em>// regular style-loader for client bundle<br></em>{ test<strong>:</strong> /\.css<strong>$</strong>/, loader<strong>:</strong> &#39;<strong>style</strong>!css?modules&#39; },</pre><pre><em>// fake-loader for server bundle<br></em>{ test<strong>:</strong> /\.css<strong>$</strong>/, loader<strong>:</strong> &#39;<strong>fake-style</strong>!css?modules&#39; }</pre><p><strong>Note</strong>: <em>The fake-style-loader currently works in combination with the css-loader in </em><strong><em>modules</em></strong><em> mode only. It doesn’t make sense to use it in non-modules mode because there would be no return value.</em></p><p><em>fake-style-loader</em> has another capability. It exports the CSS source code as the <em>source</em> property. This is useful for SSR, when you want to inline the initial CSS code.</p><pre>var styles <strong>=</strong> require(&#39;./some-file.css&#39;)</pre><pre>console.log(styles)</pre><pre><em>// returns<br>// {<br>//   // the regular classnames of css-modules<br>//   heading: &#39;.XYZABC123&#39;,<br>//   </em><strong><em>...<br></em></strong><em>//<br>//   // the special source</em> property containing the original CSS<em><br>//   </em><strong><em>source</em></strong><em>: </em><strong><em>&#39;.heading { color: blue; }&#39;</em></strong><em><br>// }</em></pre><p>To see all of this in action, check out my <a href="https://github.com/dferber90/webapp"><em>webapp</em></a> project, specifically these files:</p><ul><li><a href="https://github.com/dferber90/webapp/blob/6acf948081a30bf4ea1907f5dc90f3c1e91bf90a/bundling/webpack.config.dev.client.js#L47-L50">webpack.config.dev.client.js</a></li><li><a href="https://github.com/dferber90/webapp/blob/6acf948081a30bf4ea1907f5dc90f3c1e91bf90a/bundling/webpack.config.dev.server.js#L42-L45">webpack.config.dev.server.js</a></li><li><a href="https://github.com/dferber90/webapp/blob/6acf948081a30bf4ea1907f5dc90f3c1e91bf90a/modules/components/Footer.js#L2">Example of component importing CSS</a>, and exporting the source in <a href="https://github.com/dferber90/webapp/blob/6acf948081a30bf4ea1907f5dc90f3c1e91bf90a/modules/components/Footer.js#L10">line</a> 10.</li></ul><p>I hope <em>fake-style-loader</em> and the other modules with emission turned off are as helpful for you as they were for me. I’ve created the loader 4 months ago and put off writing about it for a long time. It still lacks documentation, but I hope by writing this article things clear up.</p><p>Further, <a href="https://github.com/dferber90/webapp">webapp</a> should be a good starting point.</p><p>Happy Server-Side Rendering :)</p><p><strong><em>Note</em></strong><em>: Previously it was not possible to turn off asset emission in file-loader and url-loader. This was introduced only recently in </em><a href="https://github.com/webpack/file-loader/pull/74"><em>#74</em></a><em>. Back then I created </em><a href="https://github.com/dferber90/fake-file-loader"><em>fake-file-loader</em></a><em> and </em><a href="https://github.com/dferber90/fake-url-loader"><em>fake-url-loader</em></a><em>. These are considered deprecated now since it’s possible out of the box now :) It is also recommended to use </em><strong><em>css-loader/locals </em></strong><em>instead of fake-style-loader. See </em><a href="https://github.com/dferber90/fake-style-loader/issues/3"><em>fake-style-loader#3</em></a><em> for more information.</em></p><h4>Further reading:</h4><ul><li><a href="http://jlongster.com/Backend-Apps-with-Webpack--Part-I">http://jlongster.com/Backend-Apps-with-Webpack--Part-I</a></li><li><a href="http://jlongster.com/Backend-Apps-with-Webpack--Part-II">http://jlongster.com/Backend-Apps-with-Webpack--Part-II</a></li><li><a href="http://jlongster.com/Backend-Apps-with-Webpack--Part-III">http://jlongster.com/Backend-Apps-with-Webpack--Part-III</a></li><li><a href="https://www.youtube.com/watch?v=zR1lOuyQEt8">https://www.youtube.com/watch?v=zR1lOuyQEt8</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a843a5ebeb0c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linting Meteor Applications]]></title>
            <link>https://medium.com/@dferber90/linting-meteor-8f229ebc7942?source=rss-5f79bc607ab9------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f229ebc7942</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[eslint]]></category>
            <category><![CDATA[meteor]]></category>
            <dc:creator><![CDATA[Dominik Ferber]]></dc:creator>
            <pubDate>Wed, 09 Mar 2016 20:24:38 GMT</pubDate>
            <atom:updated>2016-03-16T08:30:23.083Z</atom:updated>
            <content:encoded><![CDATA[<h4>Getting immediate feedback and ensuring consistent code style</h4><p><em>This article will introduce you to code linting. It shows how linters are useful, how to set them up and how to integrate them into Meteor projects, Continuous Integration and your editor. It also introduces </em><a href="https://github.com/dferber90/eslint-plugin-meteor"><em>ESLint-plugin-Meteor</em></a><em>, a tool I created specifically for linting Meteor projects.</em></p><p>Meteor 1.2 was released a while ago. One of its new features is <em>meteor lint</em>. You can try it out by running the following commands in any Meteor 1.2 project.</p><pre>$ meteor add jshint<br>$ meteor lint</pre><p><em>jshint</em> is a new Atmosphere package by the Meteor Development Group. <em>jshint</em> wraps the npm module <a href="http://jshint.com/">JSHint</a>, the static code analysis tool. <em>jshint </em>works together with <em>meteor lint</em> to check your project for issues. Here’s what that looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*PZgnkwAvzlcWrCMHprPpPA.gif" /><figcaption>Linting a fresh project with `meteor lint`</figcaption></figure><h3>Wait, wasn’t there an error?</h3><p>Yep, there was. <em>jshint </em>warned about the undefined variables <em>Session</em> and <em>Template</em>. JSHint thinks these variables are undefined because it doesn’t know anything about Meteor and its implicit globals.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*l5pvk743nksnrPaYeAyaTA.png" /><figcaption>jshint reporting some errors</figcaption></figure><p>Linters are designed to be able to lint any file given that files source-code, some rules and some options.</p><h4>Rules</h4><p>Rules tell the linter what it should check for. Rules can have different aspects: There are rules that 1) warn of possible errors, 2) make sure best practices are followed or 3) warn about stylistic issues.</p><h4>Options</h4><p>Options can tell the linter about the environment the file is in. Is this file going to run in the browser? Or on node? Is it a Meteor file? Should it support JSX? This matters because it determines whether the given file is valid or not. For example, using <em>window.location</em> would be an error in node, but not in the browser. Options can also tell the linter about globals defined in other files, like <em>Session</em> and <em>Template.</em></p><p>Great! So now we simply add <em>Template</em> and <em>Session</em> as globals to the options and the linter will succeed, right? Well, it would.</p><h2>But,</h2><p><em>Session</em> is actually only valid on the client. If the file is running on the server it would throw an error, even though the linter told us it would be okay. That’s bad because the linter is not doing its job! But that is our fault because we gave the linter wrong information by defining <em>Session</em> as a global. What we really need are globals on a per-file basis. And since Meteor runs some files on the server and some on the client, the different environments have to be taken into context as well. But even on a universal file, <em>Session</em> wouln’t be allowed within a <em>if (Meteor.isServer)</em> block. This gets complicated really fast.</p><p>Meteor Development group thought of this. <em>jshint</em> actually uses the new <a href="https://github.com/meteor/meteor/wiki/Build-Plugins-API">Build Plugins API</a>. As you may have seen in the first gif, <em>meteor lint</em> actually builds your app before running <em>jshint</em>. It does this to determine all the globals that are going to be available to every file being linted. <em>jshint</em> could now mark all global variables as defined before running the linter. This enables linting the whole project without defining all the globals manually. That’s amazing, right?</p><h2>No,</h2><p>the point of linting is to get immediate feedback during development. Building the whole project before getting any response takes too long. That’s why MDG runs the lint build plugins along with your app during development.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*R_Qc6qiX9-N1_IG6fTGJ5Q.gif" /><figcaption>When the code is changed, the linter runs in the build process.</figcaption></figure><p>Notice that the same file is linted twice, once in the context of a server and once in the context of the browser. This is necessary because Meteor shares some files between these environments.</p><p>The recording above shows the linter running on every file save.<br>That’s amazing, right?</p><h2>No.</h2><p>Having to go to the terminal after every saved change is cumbersome. Even having to save the file before getting feedback is too much work.<br><em>We want feedback. And we want it immediately.</em></p><p>There’s no way we’re going to get immediate feedback if the whole app has to be rebuilt every time we change something. Luckily, this is a solved problem. The proven way is to ensure every file can be linted on its own. This works by using ES6 modules instead of having functions and variables magically available through the global namespace.</p><p>In ES2015 great care was taken to make modules statically analyzable. By defining imports explicitly, it is possible to lint any file without building the whole app first. This is what enables the immediate feedback.</p><h2>So?</h2><p>Check out the recording below. It shows me typing some code in my editor. And I get <strong><em>immediate</em></strong> feedback, right there. And it even knows about Meteor’s API 🎉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*RbGYxaN2Mzc_tV7oH1xyKA.gif" /><figcaption>Immediate feedback</figcaption></figure><p>The code tries to use <em>Template.bar.rendered </em>which is deprecated in favor of <em>Template.bar.onRendered</em>. The rule <em>meteor/no-blaze-lifecycle-assignments</em> warns us about this, right in the editor and even before saving the file. In fact the linter is so fast it even warned while typing <em>Template.bar.</em></p><h4>How to achieve this?</h4><p>This is done by not relying on an Isobuild plugin (like <em>jshint</em>) and using <a href="http://eslint.org/">ESLint</a> directly instead. ESLint is a very extensible linter. Almost everything can be plugged into ESLint. Integrations for every major editor exist which display reported errors during development. ESLint enables you to <a href="https://medium.com/@dan_abramov/lint-like-it-s-2015-6987d44c5b48">lint like it’s 2015</a><em>… so you’re a year behind if you’re not using it yet </em>😀</p><p>To actually benefit from the amazing things linters offer, developers will have to set up their editors and projects accordingly. So, here’s how to do it.</p><h3>Setting up the editor</h3><p><em>This section is going to show the instructions for Atom, but ESLint is integrated into many other editors as well: </em><a href="http://eslint.org/docs/user-guide/integrations.html#editors"><em>Available Editor Integrations</em></a><em>.<br>The only catch is that you have to make sure the editor uses the locally installed ESLint (from “./node_modules”) instead of its own or a globally installed one.</em></p><p>Let’s start by adding the packages <strong>linter</strong> and <strong>linter-eslint</strong>. You can use the command-line to install packages with Atom’s package manager.</p><pre>$ apm install linter<br>$ apm install linter-eslint</pre><p>Alternatively, you can do so using the UI. Now, restart Atom, open the project and you’re almost good to go! Next, ESLint needs to be enabled in the project.</p><h3>Setting up the project</h3><h4>Installing packages</h4><p>Make sure you have <a href="https://docs.npmjs.com/getting-started/what-is-npm">installed npm</a>. At the root of your Meteor project, run the following commands. You can simply go with the default values for everything <em>npm init</em> asks you about.</p><pre>$ npm init --yes<br>$ npm install eslint --save-dev</pre><p>This will initialize npm in your project by creating <em>package.json</em>. This is the control file for npm. The second line installs ESLint. The <em>save-dev</em> option tells npm to save <em>eslint</em> as a development dependency in <em>package.json</em>. This enables anybody collaborating on the project with you to simply do <em>npm install</em> after cloning your repository and they’ll have ESLint available at the same version.</p><p><em>Note: Since these npm modules are not used within the Meteor application, this will work without meteorhacks:npm and also with versions before Meteor 1.3. <br>We install the modules as dev-dependencies for the same reason, so they don’t end up in the Meteor bundle. Since we’re not using “meteor lint” this even works with projects below 1.2.</em></p><p>You will get the following warnings after <em>npm install eslint -save-dev</em>.</p><pre>$ npm WARN EPACKAGEJSON meteor-project@1.0.0 No description<br>$ npm WARN EPACKAGEJSON meteor-project@1.0.0 No repository field.</pre><p>That’s because having a <em>package.json</em> file in your Meteor project makes that folder a npm package. Packages must have certain fields filled out in their <em>package.json. </em>You can get rid of this warning by adding <em>private: true</em> to your <em>package.json. </em>This tells npm to never publish this folder to npm, so you can’t share your private source code by running <em>npm publish </em>accidentally. Now that the package is declared as private, the warnings will disappear as well, because private packages don’t need to have these fields filled out. Run the following commands to add another package.</p><pre>$ npm install eslint-plugin-meteor --save-dev</pre><p>This installs <em>eslint-plugin-meteor, </em>a plugin for ESLint I created. It provides rules specifically for Meteor. This will make ESLint aware of the Meteor API.</p><p>Great, ESLint has now been installed to <em>node_modules/eslint</em>. It can be run with this command:</p><pre>$ node_modules/eslint/bin/eslint.js</pre><p>But this is a little bit hard to remember. Npm scripts export the executables, so their commands can reference them without the full path. Add the following to your <em>package.json</em></p><pre>&quot;scripts&quot;: {<br>  &quot;lint&quot;: &quot;eslint .&quot;<br>}</pre><p>Now, you can lint the project with</p><pre>$ npm run lint</pre><p>Any script defined in <em>package.json</em> runs shell commands. Modules installed into <em>node_modules</em> (like <em>eslint</em>) will be available without referring to them through their long path. Having all of the development dependencies installed at a fixed version through npm and using them through npm ensures a consistent development environment in teams. It also ensures the Continuous Integration uses the same version of packages, because the CI can simply run <em>npm install</em> before testing the project.</p><h4>Configuring ESLint</h4><p>Now, ESLint needs to be told about the plugin and your project. Create a dot-file called “<em>.eslintrc.json”</em> at the root of the project and add the contents below.</p><h4>Enabling ES2015</h4><p>If your project uses ES6, ESLint has to be told about that. Otherwise it will fail with a <em>Parsing Error.</em></p><pre>{<br>  &quot;parserOptions&quot;: {<br>    &quot;ecmaVersion&quot;: 6,<br>    &quot;sourceType&quot;: &quot;module&quot;<br>  }<br>}</pre><h4>Adding some rules</h4><p>Finally, add some rules for the project. Let’s forbid the use of semicolons as an example. All available rules of ESLint can be found <a href="http://eslint.org/docs/rules/">here</a>.</p><pre>{<br>  &quot;rules&quot;: {<br>    &quot;semi&quot;: [2, &quot;never&quot;]<br>  }<br>}</pre><p>Every rule can be configured to one of three modes:</p><ul><li>“off” or 0 — turn the rule off</li><li>“warn” or 1 — turn the rule on as a warning (doesn’t affect exit code)</li><li>“error” or 2 — turn the rule on as an error (exit code is 1 when triggered)</li></ul><p>The <em>semi</em> rule further accepts another option <em>“never” </em>which tells it to never allow semicolons. It could also be switched to <em>“always” </em>to enforce usage of semicolons everywhere.</p><p>The complete options for rules are explained <a href="http://eslint.org/docs/user-guide/configuring#configuring-rules">in the ESLint documentation</a>.</p><h4>Adding the Meteor environment</h4><p>There is a rule called <a href="http://eslint.org/docs/rules/no-undef">no-undef</a> which warns whenever the code tries to access an undefined variable. Since ESLint doesn’t know about Meteor’s API by default, it would throw an error when we’re using <em>Meteor.user() </em>or any other Meteor global<em>. W</em>e’ll have to tell ESLint about all these globals. This could be done like this:</p><pre>{<br>  &quot;rules&quot;: {<br>    &quot;no-undef&quot;: [2]<br>  },<br> <strong> </strong>&quot;globals&quot;: {<br>    &quot;Meteor&quot;: false,<br>    &quot;Session&quot;: false,<br>    // and so on..<br>  }<br>}</pre><p>Because it’s tedious to tell ESLint about all the variables, ESLint comes with <a href="http://eslint.org/docs/user-guide/configuring#specifying-environments">environments</a> which are predefined sets of globals. The Meteor environment can be enabled like this:</p><pre>{<br>  &quot;env&quot;: {<br>    meteor&quot;: true<br>  }<br>}</pre><p>Because Meteor code can run in the browser and on node, we should enable these environments as well:</p><pre>{<br>  &quot;env&quot;: {<br>    &quot;meteor&quot;: true<strong>,<br>    </strong>&quot;node&quot;: true,<br>    &quot;browser&quot;: true<br>  }<br>}</pre><p><em>Meteor</em> and <em>Session</em> can now be removed from the <em>globals</em>, because they will be provided through the <em>meteor</em> environment. Now the linter will know about all the predefined globals your application could use. If you create a custom collection, you’d add it as to <em>globals</em> like we did with <em>Meteor</em> and <em>Session</em> above.</p><p><em>Note: Since ESLint isn’t aware of Meteor’s conventions of which file is going to run on the client or the server, it won’t warn when client-only variables are used on the server and vice versa, e.g. Session on the server. I tried to work around this in the first version of ESLint-plugin-Meteor, but it turned out to introduce a lot of complexity and configuration overhead for mistakes which are very unlikely to happen. So I dropped it again in ESLint-plugin-Meteor v2.</em></p><h4>Adding Meteor specific rules</h4><p>Rules built specifically for Meteor are enabled through <em>eslint-plugin-meteor. </em>First, the plugin itself has to be enabled in <em>.eslintrc</em>, then individual rules can be turned on.</p><pre>{<br>  &quot;plugins&quot;: [&quot;<strong>meteor</strong>&quot;],<br>  &quot;rules&quot;: {<br>    &quot;<strong>meteor</strong>/no-template-lifecycle-assignment&quot;: 2<br>  }<br>}</pre><p>Here, <em>meteor</em> refers to <em>eslint-plugin-meteor. </em>This is a shorthand which can be used for all ESLint plugins, for example <em>react</em> would refer to <em>eslint-plugin-react</em>.</p><p>The rule above warns when the deprecated method of assigning template lifecycle callbacks is used, so the following will fail:</p><pre>Template.foo.rendered = function () {}</pre><p>When changing it to the new syntax, the error disappears:</p><pre>Template.foo.onRendered(function () {})</pre><p>This example shows how Meteor specific rules for ESLint can warn of deprecated APIs. You can check out all available rules of <em>eslint-plugin-meteor</em> <a href="https://github.com/dferber90/eslint-plugin-meteor">here</a>.</p><p>ESLint-plugin-Meteor comes with a recommended set of rules. To use that preset, add it as an extension.</p><pre>{<br>  &quot;plugins&quot;: [&quot;meteor&quot;],<br>  &quot;extends&quot;: [&quot;plugin:meteor/recommended&quot;]<br>}</pre><p><em>Note: Using extends for rules of plugins will only work with ESLint v2 and newer.</em></p><h4>Enabling Continuous Integration</h4><p>A popular way to test projects is using npm’s <em>test</em> script. The special <em>pretest script </em>will run before any tests are executed<em>. </em>This is the ideal place to run the linter.</p><pre>{<br>  &quot;scripts&quot;: {<br>    &quot;lint&quot;: eslint .&quot;<br>    &quot;pretest&quot;: &quot;npm run lint&quot;,<br>    &quot;test&quot;: &quot;&lt;your test command&gt;&quot;<br>  }<br>}</pre><p>Now, all your CI has to do is execute <em>npm tests</em> and you’re good to go!<br>An example of this can be seen <a href="https://github.com/dferber90/todos/blob/66521e37241e4e30c311e54ee82546e28ec12a7f/package.json#L2-L6">here</a>.</p><h2>ESLint-plugin-Meteor</h2><p>The <a href="http://guide.meteor.com/">Meteor Guide</a> has been released recently. It offers best practices for Meteor projects. The linter is a perfect place to ensure you are following them, like <a href="https://github.com/dferber90/eslint-plugin-meteor/blob/master/docs/rules/no-session.md">not using <em>Session</em></a><em>, </em><a href="https://github.com/dferber90/eslint-plugin-meteor/blob/master/docs/rules/audit-argument-checks.md">auditing arguments</a>, <a href="https://github.com/dferber90/eslint-plugin-meteor/blob/master/docs/rules/template-names.md">having all template names in camel-case</a> and <a href="https://github.com/dferber90/eslint-plugin-meteor/tree/master/docs/rules">many more</a>.</p><p>If you want to learn more about the ECMAScript specification, compilers and open source, then you should contribute by implementing some rules. I’ll try my best to help you contribute your own rule to ESLint-plugin-Meteor. Simply open an issue stating you want to help, and I’ll get in touch.</p><h3>Example configuration</h3><p>I have created a gist containing the bare minimum files I’d recommend as a base for your project. It uses ESLint with ESLint-plugin-Meteor. It is built on top of AirBnB’s <a href="https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb">JavaScript style guide</a>.</p><p>ESLint supports configuration files in different formats. Up until now, JSON was used. This gist uses YAML since it’s more readable for configuration files. Every time you add an Atmosphere package, tell ESLint about its exported globals by adding them to <em>.eslintrc.yml</em>. The same goes for collections.</p><p><a href="https://gist.github.com/dferber90/1055222bc02358d03a40">Check the gist out</a>.</p><p><em>I also sent two PRs to popular repos showing off how to integrate ESLint-plugin-Meteor: </em><a href="https://github.com/meteor/todos/pull/88"><em>meteor/todos</em></a><em> and </em><a href="https://github.com/wekan/wekan/pull/540"><em>wekan/wekan</em></a><em>.</em></p><h2>meteor lint?</h2><p>As you may have noticed, the project is actually never using <em>meteor lint</em>.</p><p>Is <em>meteor lint</em> still useful then? That question is better rephrased as <em>Are Isobuild Lint Packages still useful?</em>, because <em>meteor lint</em> does little beside running them. A proper linting package can be very useful. It would not make use of any of the magic provided by Isobuild (global variables, known architecture). It has to adhere to this restriction to support consistent linting results with the editor. Anything that is valid in your editor should be valid in <em>meteor lint</em>, and vice versa. <br>The true value of a proper atmosphere-based linting package is that it could define a code standard the whole community can follow by simply running</p><pre>$ meteor add <em>whoever-creates-it</em>:standard</pre><p>This <em>standard</em> package could define a common code style, much like <a href="https://github.com/feross/standard">standard</a> by <a href="https://twitter.com/@feross">@feross</a> does in the npm world.</p><h3>Working around Meteor’s missing module support</h3><p><a href="http://c2.com/cgi/wiki?GlobalVariablesAreBad">Globals are bad</a>. Unfortunately Meteor uses them a lot.<br>Meteor does not support ES6 modules yet, so the code has to be made statically analyzable another way. To do this, hints could be given to the linter through comments and configuration. This results in a lot of configuration work for little benefit. When Meteor will finally support modules in 1.3, most of these hints can be removed and everything will continue to work.</p><h3>Setting up your teammates</h3><p>After one of your colleagues clones the git project, he only needs to run <em>npm install</em> and npm will install all the packages listed in <em>packages.json, </em>including the linter. When the teammate has set up his editor correctly, he’s good to go :-)</p><h2>Wrapping up</h2><p>Linting is awesome. To keep it awesome, we should not rely on Isobuild magic as it will slow down feedback cycles and breaks existing tooling in editors. Instead of creating complex tools that understand Meteor, the Meteor code should be simplified so it can be understood by existing tools. The tooling support for JavaScript is great and using Meteor should not break it.</p><p>Having a linter in your editor will shorten your feedback-cycles drastically. Having a linter run in your Continuous Integration will ensure code quality stays top-notch and reduce errors.</p><p>Happy Linting!</p><p><em>If you don’t want to miss updates for ESLint-plugin-Meteor, follow </em><a href="http://twitter.com/@dferber90"><em>@dferber90</em></a><em> on Twitter. I tweet about Javascript, Meteor and new web technologies.</em></p><p><em>Sidenote: This article was originally written almost 6 months ago. ESLint-plugin-Meteor has since been undergoing heavy changes and its focus shifted on best-practices instead of ensuring correct Meteor API usage. ESLint-plugin-Meteor previously tried to determine where files are going to run (client, server, both) and provide hints based on that information. This lead to a lot of complexity and broke some editor integration, while offering little benefit. It now focuses on making sure best-practices are being followed.</em></p><p><em>ESLint itself had a major release which broke this plugin originally, and Meteor 1.3’s package support was announced which would have made the original version of this plugin even more complicated. Development of this plugin was paused until things settled down. Now that they have, ESLint-plugin-Meteor has been adapted to the changes and it’s more useful than ever :-)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f229ebc7942" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>