<?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[C-Hive - Medium]]></title>
        <description><![CDATA[Busy making software - Medium]]></description>
        <link>https://medium.com/c-hive?source=rss----10464ee4ad68---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>C-Hive - Medium</title>
            <link>https://medium.com/c-hive?source=rss----10464ee4ad68---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 00:42:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/c-hive" 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 to setup ESLint, Prettier, and Babel for your React project]]></title>
            <link>https://medium.com/c-hive/how-to-setup-eslint-prettier-and-babel-for-your-react-project-1f5e15a56b7b?source=rss----10464ee4ad68---4</link>
            <guid isPermaLink="false">https://medium.com/p/1f5e15a56b7b</guid>
            <category><![CDATA[eslint]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[prettier]]></category>
            <category><![CDATA[babel]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Kapolcs Nagy]]></dc:creator>
            <pubDate>Tue, 17 Dec 2019 15:04:52 GMT</pubDate>
            <atom:updated>2019-12-23T23:42:39.229Z</atom:updated>
            <content:encoded><![CDATA[<p>Building high-quality apps these days is hard.</p><p>That’s why nowadays, there are many tools that allow us to write quality code and make sure our apps don’t break. You may think of testing tools like <a href="https://jestjs.io/">Jest</a> at first, but before even writing a test, you can prevent many head-scratching situations.</p><p>In this article, we will overview the process, how I set up these tools for a React project. First of all, you need to install Prettier.</p><h3>Prettier</h3><p>For using this tool you need to install Prettier:</p><pre>npm install -D prettier</pre><p>Now you have Prettier installed and from now with a little config, your code will be always consistent. I’m sure many of you were work on projects where some files have tabs, some spaces, or have a trailing comma and others don’t…</p><p>Prettier is a project which takes all the conversation out of context and it standardizes to a predefined style. So everyone will be on the same format.</p><p>I actually, really don’t care about how is my code looks like as long as it’s well-formatted and consistent. The great thing Prettier does this for us.</p><h4>Configurate Prettier</h4><p>You can run from the command line as an npm script:</p><pre>&quot;scripts&quot;: {<br>    &quot;format&quot;: &quot;prettier \&quot;src/**/*.{js,html}\&quot; --write&quot;,clicks&#39;))<br>}</pre><p>Or install the <a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode">plugin</a> and just add to your vscode config this two lines (without my comments):</p><pre>“editor.formatOnSave”: true, <em>// enable a formatter to format on save</em><br>“prettier.requireConfig”: true,    <em>// prettier only run if installed</em></pre><p>And create a file in the project root directory named <em>.prettierrc</em> with an empty object {} in it (it means you will use the default settings).</p><p>And that’s it Prettier is installed in your project. And now if you press ctr+s Prettier will run so you can focus more on your code.</p><p>Now we need another tool called linter. It is different from Prettier because Prettier is very mechanical, like how is this file formatted, or where should I put return, etc. but it doesn’t care about what the code actually does. This is the linter’s task.</p><h3>Bare minimum ESLint config</h3><p>Now install ESLint which is a code linter:</p><pre>npm install -D eslint eslint-config-prettier</pre><p>We need the <em>eslint-config-prettier</em> package too, because there is an overlap between Prettier and ESLint, and we need to tell ESLint to leave the mechanical part to Prettier.</p><p>Create .eslintrc.json config file in the project root:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/688f591978abca236cbb901e828af6dc/href">https://medium.com/media/688f591978abca236cbb901e828af6dc/href</a></iframe><p>(I leave a comment every line ends where I think need some guidance.)</p><p>The most important part is the <a href="https://eslint.org/docs/rules/"><em>eslint:recommended</em></a> which is the bare minimum. Everything in <em>eslint:recommended</em> what is recommended for everyone to run all the time. We can use other rule sets such as <a href="https://www.npmjs.com/package/eslint-config-airbnb"><em>airbnb</em></a>, but it will force us to write code in a specific way, so that is more opinionated.</p><p>If you want to see ESLint hints on hover, just install this <a href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint">vscode eslint plugin</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ckWxE4b3zxi1bgZoJFFxOw.jpeg" /></figure><h3>ESLint, Babel config for almost every React project</h3><p>The previous was the basic standard setup for ESLint, but we need to go further to make sure ESLint understands React correctly. For that, we need to install a few other tools:</p><pre>npm i -D babel-eslint eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react</pre><p><em>babel-eslint</em>: the babel compiler out the box doesn’t understand React super well, that’s why we install this plugin</p><p><em>eslint-plugin-import</em>: give new rules for importing, and exporting things, just to have a good habit about that kind of stuff</p><p><em>eslint-plugin-jsx-a11y</em>: this will help with no brainer things for accessibility (like don’t make div clickable, etc.)</p><p><em>eslint-plugin-react</em>: help us some additional React rules we need</p><p>And change the .eslintrc.json to the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b05d722db0b6ed0056d28fb91ba951ae/href">https://medium.com/media/b05d722db0b6ed0056d28fb91ba951ae/href</a></iframe><p>At this point, we could tell this is the ESLint config for almost every React project needs. And don’t forget, the most important you don’t question anything what is in <em>eslint:recommended </em>because everything it said pretty standard rules in JS community.</p><p><a href="https://github.com/nkapolcs/eslint-config-for-react">nkapolcs/eslint-config-for-react</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f5e15a56b7b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/c-hive/how-to-setup-eslint-prettier-and-babel-for-your-react-project-1f5e15a56b7b">How to setup ESLint, Prettier, and Babel for your React project</a> was originally published in <a href="https://medium.com/c-hive">C-Hive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React — unit testing HOC’s wrapped component]]></title>
            <link>https://medium.com/c-hive/test-hocs-wrapped-component-with-jest-and-enzyme-e9155f80a217?source=rss----10464ee4ad68---4</link>
            <guid isPermaLink="false">https://medium.com/p/e9155f80a217</guid>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[higher-order-components]]></category>
            <category><![CDATA[enzyme]]></category>
            <dc:creator><![CDATA[Zsolt Gömöri]]></dc:creator>
            <pubDate>Sun, 11 Nov 2018 19:31:15 GMT</pubDate>
            <atom:updated>2019-03-07T08:35:34.745Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*IML6o3MkyNg9Wl99gfUxAg.png" /><figcaption>React — unit testing HOC’s wrapped component</figcaption></figure><h3>React — unit testing HOC’s wrapped component</h3><p>Unit testing components in <strong>React</strong> is very important despite the fact that it can sometimes be extremely disconcerting — I assume that you’ve already experienced the feeling of struggling with a single component that can’t be tested with ease. The latter clause is especially true when the component is wrapped with a HOC.</p><p>First and foremost, let’s just scratch the surface a little bit and try to understand what happens behind the scenes.</p><blockquote>Whenever a component — that is expected to be tested — is wrapped with a HOC, there isn’t any way to access that with a simple shallow rendering — I hear the folks saying you can use mount rendering, but this might cause unexpected behaviors due to the rendering of the whole tree. <strong>Instead, you should go a level deeper so that grab the appropriate component from there.</strong></blockquote><p><strong>Solution</strong></p><p>After investigating a bunch of other similar issues, I found the relevant one that was mentioned in this <a href="https://github.com/airbnb/enzyme/issues/711#issuecomment-362318809">GitHub</a> issue.</p><p>The following solution is achieved by using Jest and Enzyme.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6af876818a7b940386bed1adf6cbeafd/href">https://medium.com/media/6af876818a7b940386bed1adf6cbeafd/href</a></iframe><p>Feel free to hit me up on <a href="https://twitter.com/zsgomori">Twitter</a> and also leave any kind of questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9155f80a217" width="1" height="1" alt=""><hr><p><a href="https://medium.com/c-hive/test-hocs-wrapped-component-with-jest-and-enzyme-e9155f80a217">React — unit testing HOC’s wrapped component</a> was originally published in <a href="https://medium.com/c-hive">C-Hive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solving Rake DB tasks with dotenv executed twice in dev environment]]></title>
            <link>https://medium.com/c-hive/solving-rake-db-tasks-with-dotenv-executed-twice-in-dev-environment-4b1cb447d325?source=rss----10464ee4ad68---4</link>
            <guid isPermaLink="false">https://medium.com/p/4b1cb447d325</guid>
            <category><![CDATA[rubygems]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Csaba Apagyi]]></dc:creator>
            <pubDate>Sun, 04 Nov 2018 01:06:14 GMT</pubDate>
            <atom:updated>2018-11-04T01:27:08.733Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*8tn9srporV1GUoKlzfpLFQ.png" /></figure><p>Have you ever ran into this?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff9a231f570c8d7e83865171742acdf3/href">https://medium.com/media/ff9a231f570c8d7e83865171742acdf3/href</a></iframe><p>Or perhaps an EnvironmentMismatchError?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93c98aec53e36cc871044558b1266309/href">https://medium.com/media/93c98aec53e36cc871044558b1266309/href</a></iframe><p>If you kept reading chances are you’re using dotenv and ran into the magical feature of Rake DB tasks being executed in both dev and test envs when invoked in dev env (<a href="https://github.com/rails/rails/blob/v5.1.5/activerecord/lib/active_record/tasks/database_tasks.rb#L300">see</a>).</p><p>The issue, as explained on <a href="http://www.zhuwu.me/blog/posts/rake-db-tasks-always-runs-twice-in-development-environment">Zhu Wu’s blog</a>, is that the <em>smart</em> environment change doesn’t take possible environment variable change into account and rather uses the DB config which was preloaded in dev env. E.g. if you have database: &lt;%= ENV[&#39;DATABASE_NAME&#39;] %&gt; in your DB config, the new value of that variable in test env will not be reloaded. I since created a detailed <a href="https://github.com/rails/rails/issues/32926">issue in Rails</a> listing some further implications and an example project for reproducing the issue.</p><p>What’s the solution? There’s a couple.</p><p>The least intrusive is probably to use different env vars such as TEST_DATABASE_NAME and DEV_DATABASE_NAME in which case the tasks would work as expected. That’s clearly counter-intuitive though.</p><p>You could get rid of the double-execution by using custom DB tasks. You can write them yourself or use gems such as <a href="https://github.com/ioquatix/activerecord-migrations">activerecord-migrations</a> (referenced in this <a href="https://github.com/rails/rails/issues/27299#issuecomment-266386876">related issue</a>).</p><p>Or finally, you could fix Rake DB tasks’ behaviour so that they work as expected: execute for both dev and test envs and properly initialize the environments. This is what I did in the gem <a href="https://github.com/thisismydesign/dotenv_rails_db_tasks_fix">dotenv_rails_db_tasks_fix</a>. It monkey patches a method called each_current_configuration in ActiveRecord::Tasks::DatabaseTasks which is responsible for this whole mess (<a href="https://github.com/rails/rails/blob/v5.1.5/activerecord/lib/active_record/tasks/database_tasks.rb#L298-L307">see</a>). When switching environments it reloads env vars and DB config properly. Monkey pathing is discouraged but here I only do it in development environment so I consider this safe to use.</p><p>If you’re facing the same issue give these options a try and spare future developers the confusion that surrounds this whole topic.</p><p>You can find things I care about on <a href="https://twitter.com/csaba_apagyi">Twitter</a>, <a href="https://medium.com/@csaba.apagyi">Medium</a> and <a href="https://github.com/thisismydesign">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b1cb447d325" width="1" height="1" alt=""><hr><p><a href="https://medium.com/c-hive/solving-rake-db-tasks-with-dotenv-executed-twice-in-dev-environment-4b1cb447d325">Solving Rake DB tasks with dotenv executed twice in dev environment</a> was originally published in <a href="https://medium.com/c-hive">C-Hive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to RuboCop parallel auto-correct]]></title>
            <link>https://medium.com/c-hive/how-to-rubocop-parallel-auto-correct-8d4b68a22d8b?source=rss----10464ee4ad68---4</link>
            <guid isPermaLink="false">https://medium.com/p/8d4b68a22d8b</guid>
            <category><![CDATA[parallel-computing]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[rubocop]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Csaba Apagyi]]></dc:creator>
            <pubDate>Sun, 04 Nov 2018 01:04:13 GMT</pubDate>
            <atom:updated>2018-11-08T14:03:23.972Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*BCXfQm8bnCzgSBbggJa0Pw.png" /></figure><p>Parallel is fast, auto-correct is useful. Have you ever tried them together with the reasonable expectation that it works?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc0cc4d5e4303d2495566570e4dc7fb1/href">https://medium.com/media/fc0cc4d5e4303d2495566570e4dc7fb1/href</a></iframe><p>Oh. To be fair it probably makes sense that auto-correct doesn’t work on multiple threads.</p><p>Since I already had a <a href="https://github.com/thisismydesign/autowow">small framework to automate work processes</a> I could implement this functionality nicely in literally <a href="https://github.com/thisismydesign/autowow/blob/1ee4a6918f478bfb4fca91917c8d57b3d96513a5/lib/autowow/features/gem.rb#L33-L43">10 lines</a>: all I had to do is grab the offending files from the output of rubocop --parallel and feed them to rubocop --auto-correct. It’s in the gem called autotwow(as in [auto]mated [w]ay [o]f [w]orking) and can be used as:</p><p>gem install autowow</p><p>autowow rubocop_parallel_autocorrect / aw rpa</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9636e39cd25e0ccba020e243351d434f/href">https://medium.com/media/9636e39cd25e0ccba020e243351d434f/href</a></iframe><p>To make it even more simple &amp; faster one could do the same thing using the rubocop gem’s API (unfortunately non-public), or I’m sure some bash masters can do a simple one-liner.</p><p>If you’re interested check out other features of <a href="https://github.com/thisismydesign/autowow">autowow</a> too such as <a href="https://github.com/thisismydesign/autowow#add-upstream">adding upstream remote to forks via the GitHub API</a> or <a href="https://github.com/thisismydesign/autowow#clear-branches">clearing unused branches</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d4b68a22d8b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/c-hive/how-to-rubocop-parallel-auto-correct-8d4b68a22d8b">How to RuboCop parallel auto-correct</a> was originally published in <a href="https://medium.com/c-hive">C-Hive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ruby: how to use self.included meaningfully]]></title>
            <link>https://medium.com/c-hive/ruby-how-to-use-self-included-meaningfully-c57d426fc192?source=rss----10464ee4ad68---4</link>
            <guid isPermaLink="false">https://medium.com/p/c57d426fc192</guid>
            <category><![CDATA[metaprogramming]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Csaba Apagyi]]></dc:creator>
            <pubDate>Sun, 04 Nov 2018 00:31:28 GMT</pubDate>
            <atom:updated>2018-11-04T00:58:53.656Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*cPGR-G6F89BcpaU9GjzBYw.png" /></figure><p>My <a href="https://github.com/thisismydesign/easy_logging">use case</a> was to provide the same functionality on instance and class level upon include. By default include only adds instance methods and extend only adds class methods. Of course you could do both but that just doesn’t look DRY…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/919658f9091dba0917bfea102c8b6f90/href">https://medium.com/media/919658f9091dba0917bfea102c8b6f90/href</a></iframe><p>… right? It is especially ugly to give the instructions to the users of your module to do both.</p><h3>A common idiom</h3><p>Looking for the solution I stumbled upon self.included <a href="http://www.railstips.org/blog/archives/2009/05/15/include-vs-extend-in-ruby/">mentioned as “A common idiom”</a> for this case. As per <a href="https://ruby-doc.org/core-2.4.1/Module.html#method-i-included">ruby-doc</a> it is a “Callback invoked whenever the receiver is included in another module or class”.</p><p>Messing around with it you can do the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab3bbfc195505839905ed66df08595d8/href">https://medium.com/media/ab3bbfc195505839905ed66df08595d8/href</a></iframe><p>Which will create class_method in the class where it’s included. Or to fit my use case and add all methods as class methods:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae558fbc6530b59dc6a3c000fc95cce3/href">https://medium.com/media/ae558fbc6530b59dc6a3c000fc95cce3/href</a></iframe><p>Which will do an extend as well upon include.</p><p>There’s also a similar <a href="https://ruby-doc.org/core-2.4.1/Module.html#method-i-extended">callback for extend</a> by the by way: self.extended.</p><h3>How to make it better</h3><p>So we have a solution but is it the best one? The first time it took me a while to figure out how it works. Callbacks of this kind are bad in the sense that they describe <em>when</em> they will be executed and NOT <em>what</em> they will do. I wish we could rename the callback to CreateClassMethodsUponInclude but unfortunately that’s not possible.</p><p>So let’s do almost that! We know that it has a fixed name and must be in a module. The module of course can have a custom name and can later be included wherever we want to have this logic. That’s great! We can have something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4c337356f90b7567a41861638d592da/href">https://medium.com/media/e4c337356f90b7567a41861638d592da/href</a></iframe><p>Well that’s pretty descriptive. OK. But what should happen when we include CreateClassMethodsUponInclude? It should create the self.included that does what we want. We can achieve that using some more meta-magic.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e27702c7a31dec192f08804b794eb82/href">https://medium.com/media/9e27702c7a31dec192f08804b794eb82/href</a></iframe><p>Go ahead and copy it into your console.</p><h3>What did we gain?</h3><p>The actual implementation might not be pretty but no one has to look at it again because we wrapped it into a module that is <strong>meaningful</strong> and <strong>reusable</strong>. Using the CreateClassMethodsUponInclude module no-one will have any excessive thinking to do while reading or writing this piece of logic.</p><p>This module is part of the free and open source <a href="https://github.com/thisismydesign/reflection_utils">reflection-utils</a> gem. While it’s only one actual use case I think this design pattern is worth following for similar problems.</p><p><em>Originally published at my old blog on June 26, 2017.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c57d426fc192" width="1" height="1" alt=""><hr><p><a href="https://medium.com/c-hive/ruby-how-to-use-self-included-meaningfully-c57d426fc192">Ruby: how to use self.included meaningfully</a> was originally published in <a href="https://medium.com/c-hive">C-Hive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>