<?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[Millennial Falcon Technology - Medium]]></title>
        <description><![CDATA[A blog about technology and cool programming paradigms - Medium]]></description>
        <link>https://medium.com/millennial-falcon-technology?source=rss----69a3ea7635eb---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Millennial Falcon Technology - Medium</title>
            <link>https://medium.com/millennial-falcon-technology?source=rss----69a3ea7635eb---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 14:19:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/millennial-falcon-technology" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Reformatting your code base using prettier or eslint without destroying git history]]></title>
            <link>https://medium.com/millennial-falcon-technology/reformatting-your-code-base-using-prettier-or-eslint-without-destroying-git-history-35052f3d853e?source=rss----69a3ea7635eb---4</link>
            <guid isPermaLink="false">https://medium.com/p/35052f3d853e</guid>
            <category><![CDATA[prettier]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Marcus Motill]]></dc:creator>
            <pubDate>Thu, 09 Nov 2017 16:59:02 GMT</pubDate>
            <atom:updated>2018-01-26T15:14:32.343Z</atom:updated>
            <content:encoded><![CDATA[<p>First off I need to thank Elliot Chance for <a href="http://elliot.land/post/reformatting-your-codebase-with-git-filter-branch">his blog post</a> that helped me get this mission off the ground.</p><p>Also, skip to the <strong>How it is done</strong> section if you don’t want to read my story.</p><h3>Background</h3><p>I work for a company that uses node.js (and other frameworks like angular) for the overwhelming majority of our projects. Over the past two years the code has changed lead maintainers a few times from founder to architect 1 to architect 2. With the founder code ranging from “Hello World” level to advanced compiler level code. You can imagine that the format and style of this codebase is far form consistent.</p><p>Enter <a href="https://github.com/prettier/prettier">Prettier</a>. After discovering Prettier while it was still in its unstable period I was itching to add it to our standard workflow. So every <em>new project </em>was set up using the formatter from the start. The only thing stopping me from running Prettier on our existing code was the ever so valuable <strong>git history</strong>.</p><h3>How it is done</h3><h4>git filter-branch</h4><p><a href="https://git-scm.com/docs/git-filter-branch">A tool used for rewriting git history</a> to pretend that something never happened. This is most commonly used for removing large files from git history or if someone accidentally commits a node_modules directory, you can remove it forever. Heres an example of that use case:</p><p>git filter-branch --tree-filter “rm -rf node_modules” -- --all</p><p>So what is this doing?</p><p>Here we are walking every commit from every tree in the git history, deleting the node_modules directory and re-committing. This makes it appear that the author of that commit never added the node_modules directory to begin with. So the silly commit titled Added node_modules will still be there but just be empty in the history.</p><p>So with that understanding we can translate it over to formatting the code. We want to walk every commit, format the code, and then recommit. This will give the illusion in the git history that the author of the commit wrote perfectly formatted code from the start! No more ugly “founder code” (in appearance at least). The command I used was:</p><pre>git filter-branch --tree-filter &#39;\<br>    prettier --no-config --single-quote --tab-width=4\<br>    --print-width=110 --write &quot;**/**.js&quot; || \<br>    echo “Error formatting, possibly invalid JS“&#39; -- --all</pre><p>Lets break it down:</p><p>git filter-branch --tree-filter we have already gone over this.</p><p>prettier run the formatted</p><p>--no-config I used this because someone committed an invalid package.json in the past so needed to be ignored.</p><p>--single-quote --tab-width=4 --print-width=110 my opinionated options</p><p>--write Format the file in place, will change the files!</p><p>&quot;**/**.js&quot; Glob indicated run this on all JS files. More on this later.</p><p>echo &quot;Error formatting, possibly invalid JS&quot; incase someone committed invalid JS in the history this will swallow the error and continue</p><p>--all Do the rewrite on all refs in the git history</p><p>So the above command will work for all of you out there but it is pretty slow for large projects, talking several hours.</p><p>An optimization is:</p><pre>git filter-branch --tree-filter &#39;git show $GIT_COMMIT --name-status\<br>    | grep &quot;^[AM]&quot; | grep &quot;.js$&quot; | cut -f2 | tr &quot;\n&quot; &quot; &quot;\<br>    xargs prettier --no-config --single-quote --tab-width=4\<br>    --print-width=110 --write {} || \<br>    echo “Error formatting, possibly invalid JS“&#39; -- --all</pre><p><strong>Note: This DID NOT work for me but others may have success. Please comment if you see the issue.</strong></p><p>What this does is pipe only the added and modified files for that commit into prettier with xargs. This reduced my run from several hours to about 20 minutes.</p><p>The same can be done with eslint but it is even slower:</p><pre>git filter-branch --tree-filter &#39;\<br>    eslint . --fix || \<br>    echo “Error formatting, possibly invalid JS“&#39; -- --all</pre><h3>Conclusion</h3><p>After you confirmed your code is looking good and your tests are passing, just force push it up to your repo and tell your coworkers to delete the repo locally and re-clone. We did this on <strong>production code </strong>and so far we have not had any issues (knock on wood). Our code is now pretty with a clean history. Thanks Prettier.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35052f3d853e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/millennial-falcon-technology/reformatting-your-code-base-using-prettier-or-eslint-without-destroying-git-history-35052f3d853e">Reformatting your code base using prettier or eslint without destroying git history</a> was originally published in <a href="https://medium.com/millennial-falcon-technology">Millennial Falcon Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript Destructuring Assignment]]></title>
            <link>https://medium.com/millennial-falcon-technology/javascript-destructuring-assignment-ad4ff9973ce9?source=rss----69a3ea7635eb---4</link>
            <guid isPermaLink="false">https://medium.com/p/ad4ff9973ce9</guid>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[es6-in-depth]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Marcus Motill]]></dc:creator>
            <pubDate>Thu, 15 Jun 2017 21:12:30 GMT</pubDate>
            <atom:updated>2017-06-15T21:12:29.694Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m3VYxZTz3R37rvFbwnnEBQ.jpeg" /></figure><p>While destructuring assignment is a new concept in Javascript land it is a tried an true technique in many other programming languages, just by different names. For Example:</p><ul><li>Ruby: parallel assigning</li><li>PHP: listing</li><li>Python: unpacking</li></ul><p>I will only cover a few basic cases for Destructuring assignment here but for more information on this particular topic checkout <a href="http://exploringjs.com/es6/ch_destructuring.html">chapter 10 of exploring JS</a> and <a href="http://mib.im/presentations/bartjs/destructuring/#/">this great slide deck</a>.</p><h4>Example 1, regular old object destructuring:</h4><p>Given a user object:</p><pre>const user = {<br>    name: &#39;Pauly-D&#39;,<br>    age: 25,<br>    shirtSize: &#39;s/m&#39;<br>};</pre><p>The typical way to access and use the properties of this object would be:</p><pre>const name = user.name;<br>const age = user.age;<br>const shirtSize = user.shirtSize;</pre><p>This is fine and all but seems a little verbose and ugly to me. Let us try to destructure this object the ES6 way!</p><pre>const {<br>    name,<br>    age,<br>    shirtSize<br>} = user;</pre><p>And there we have it, we now have 3 variable available in this scope user, age, and shirtSize all derived from the user object.</p><h4>Example 2, renaming:</h4><p>Okay so using the same object as the previous example,</p><pre>const user = {<br>    name: &#39;Pauly-D&#39;,<br>    age: 25,<br>    shirtSize: &#39;s/m&#39;<br>};</pre><p>Lets say we want to use these variables but with a more descriptive name:</p><pre>const {<br>    name: userName,<br>    age: theAge,<br>    shirtSize: size<br>} = user;</pre><p>And just like that we have 3 variables in our scope userName, theAge, and size. Just to be clear we can now use these vars like regular declarations:</p><pre>if (theAge &lt; 30 &amp;&amp; size === &#39;s/m&#39;) {<br>    console.log(&quot;I am hit.&quot;);<br>}</pre><h4>Example 3, accessing nested properties:</h4><p>Lets say that our example object gets a little bit more complicated,</p><pre>const user = {<br>    name: &#39;Pauly-D&#39;,<br>    age: 25,<br>    shirtSize: &#39;s/m&#39;,<br>    state: {<br>        isLoggedIn: true,<br>        profile: {<br>            theme: &#39;dark&#39;,<br>            textSize: &#39;10px&#39;<br>        }<br>    }<br>};</pre><p>but we have gotten hooked on object destructuring and want to keep using it. We can do that!</p><pre>const {<br>    name,<br>    age: userAge,<br>    size: shirtSize,<br>    state: {<br>        profile: {<br>            theme: userTheme,<br>            textSize<br>        }<br>    }<br>} = user;</pre><pre>console.log(userTheme) // prints &#39;dark&#39;<br>console.log(textSize) // prints &#39;10px&#39;</pre><p>The above statement creates 5 new variables name, userAge, userTheme, and textSize. Pretty neat huh? What about null/undefined safety?</p><h4>Example 4, using defaults in destructuring:</h4><p>So what if we are not sure if the user profile object from our example is going to be clean? Like this:</p><pre>const user = {<br>    name: &#39;Pauly-D&#39;,<br>    age: 25,<br>    shirtSize: &#39;s/m&#39;,<br>    state: {<br>        isLoggedIn: true,<br>        profile: undefined<br>    }<br>};</pre><p>We can just do this to protect us with no errors:</p><pre>const {<br>    name,<br>    age: userAge,<br>    size: shirtSize,<br>    state: {<br>        profile: {<br>            theme: userTheme,<br>            textSize<br>        } = {} // psst the magic is happening here<br>    }<br>} = user;</pre><pre>console.log(userTheme); //undefined<br>console.log(textSize); //undefined</pre><p>Default parameter notation can be used at any step in the destructuring:</p><pre>const {<br>    name,<br>    age: userAge,<br>    size: shirtSize,<br>    state: {<br>        profile: {<br>            theme: userTheme = &#39;Mikey&#39;,<br>            textSize = &#39;15px&#39;<br>        } = {}<br>    }<br>} = user;</pre><pre>console.log(userTheme); //&#39;Mikey&#39;<br>console.log(textSize); //&#39;15px&#39;</pre><p>Where else can we use this notation?</p><h4>Example 5, destructuring function parameters:</h4><p>The destructuring syntax is handy and all but can you use it anywhere else? Sure! You can use destructuring syntax pretty much anywhere you declare variables. Here you can see it being used in a function with an object parameter:</p><pre>const user = {<br>    name: &#39;Pauly-D&#39;,<br>    age: 25<br>};</pre><pre>const validateUser = ({ name, age: userAge, shirtSize = &#39;s&#39; }) =&gt; {<br>    console.log(&#39;name&#39;, name);<br>    console.log(&#39;userAge&#39;, userAge);<br>    console.log(&#39;shirtSize&#39;, shirtSize);<br>};</pre><pre>validateUser(user);<br>// logs<br>// name: &#39;Pauly-D&#39;<br>// age: 25<br>// shirtSize: &#39;s&#39;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad4ff9973ce9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/millennial-falcon-technology/javascript-destructuring-assignment-ad4ff9973ce9">Javascript Destructuring Assignment</a> was originally published in <a href="https://medium.com/millennial-falcon-technology">Millennial Falcon Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>