<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://antman.dev/feed.xml" rel="self" type="application/atom+xml" /><link href="https://antman.dev/" rel="alternate" type="text/html" /><updated>2026-12-03T20:09:25+00:00</updated><id>https://antman.dev/feed.xml</id><title type="html">antman.dev</title><subtitle>Random ramblings of a scandinavian software person about Ruby, JWTs and the people around the code.</subtitle><author><name>Joakim Antman</name></author><entry><title type="html">No more crossing fingers</title><link href="https://antman.dev/2026/12/03/no-more-crossing-fingers.html" rel="alternate" type="text/html" title="No more crossing fingers" /><published>2026-12-03T17:00:00+00:00</published><updated>2026-12-03T17:00:00+00:00</updated><id>https://antman.dev/2026/12/03/no-more-crossing-fingers</id><content type="html" xml:base="https://antman.dev/2026/12/03/no-more-crossing-fingers.html"><![CDATA[<p>I’ve been in the JWT space for a while now, mostly through the <a href="https://github.com/jwt/ruby-jwt">ruby-jwt</a> gem. The post about the <a href="/2025/06/14/ruby-jwt-3-0-0.html">3.0.0 release</a> ended with “Now just crossing fingers there is no major compatibility problems…”. That was only half a joke.</p>

<h2 id="the-pain">The pain</h2>

<p>Every time ruby-jwt was about to change how it reads tokens the question was the same: what do the other libraries create and what do they accept? Answering that meant installing a bunch of languages and writing small scripts for libraries I had never used or thinking I should but never did.</p>

<h2 id="ai-to-the-rescue">AI to the rescue</h2>

<p>Some kind of automated test suite for this has been on my mind for years. What stopped me was the boring and tedious part, 13 languages means 13 toolchains and build setups. Giving the task to an agent was easy and after a few iteration we have <a href="https://jwtcompat.dev">jwtcompat.dev</a>. A site that collects how JWT/JOSE/JWA libs talk to each others.</p>

<p>Every library signs tokens with the algorithms it supports and verifies what the others signed. On top of that every library gets known attacks, tokens that bend the RFCs and the keys identity providers publish.</p>

<p>I take no credit of the quality of how the different libraries are used and there are probably some flaws.</p>

<h2 id="what-did-it-find">What did it find?</h2>

<p>Good news first, none of the libraries accept the known ways of forging a token, think we already knew that. Then some less clean stuff, for example:</p>

<ul>
  <li>18 of 33 libraries accept a padded signature</li>
  <li>3 accept <code class="language-plaintext highlighter-rouge">"alg":"hs256"</code> even if algorithm names are case-sensitive, ruby-jwt is one of them (<a href="https://github.com/jwt/ruby-jwt/issues/820">#820</a>)</li>
  <li>Yahoo and Intuit still publish 1024-bit RSA keys</li>
</ul>

<p>Most of these are not bugs, more differences worth knowing about.</p>

<p>If your favourite library is missing, <a href="https://github.com/anakinj/jwt-compat">the repo</a> is open for issues and pull requests. Still crossing fingers when releasing, but not as hard anymore.</p>]]></content><author><name>Joakim Antman</name></author><summary type="html"><![CDATA[Testing how 35 JWT libraries get along with each other, every week]]></summary></entry><entry><title type="html">jwt 3.0.0 - a new major version</title><link href="https://antman.dev/2025/06/14/ruby-jwt-3-0-0.html" rel="alternate" type="text/html" title="jwt 3.0.0 - a new major version" /><published>2025-06-14T17:35:00+00:00</published><updated>2025-06-14T17:35:00+00:00</updated><id>https://antman.dev/2025/06/14/ruby-jwt-3-0-0</id><content type="html" xml:base="https://antman.dev/2025/06/14/ruby-jwt-3-0-0.html"><![CDATA[<p>After a bit of silence I finally got around and release a new major version of the  <a href="https://rubygems.org/gems/jwt">ruby-jwt</a> gem. A bunch of deprecated functionality removed. Read more about the details <a href="https://github.com/jwt/ruby-jwt/releases/tag/v3.0.0">from the release</a></p>

<p>Now just crossing fingers there is no major compatibility problems…</p>]]></content><author><name>Joakim Antman</name></author><summary type="html"><![CDATA[The cleanup version]]></summary></entry><entry><title type="html">jwt 2.10.0 and objects for managing tokens</title><link href="https://antman.dev/2024/12/26/ruby-jwt-2-10-0.html" rel="alternate" type="text/html" title="jwt 2.10.0 and objects for managing tokens" /><published>2024-12-26T17:00:00+00:00</published><updated>2024-12-26T17:00:00+00:00</updated><id>https://antman.dev/2024/12/26/ruby-jwt-2-10-0</id><content type="html" xml:base="https://antman.dev/2024/12/26/ruby-jwt-2-10-0.html"><![CDATA[<p>A new version of <a href="https://rubygems.org/gems/jwt">ruby-jwt</a> is out with some new and shiny features. This version also is preparing to get rid of some functionality bloating the Gem.</p>

<h2 id="removing-functionality">Removing functionality</h2>

<p>The plan is that this version is going to be the last one supporting the indirect dependency to rbnacl that powers a few cpypto algorithms (Ed25519 and SHA512256). In the future the SHA512256 algorithm is going to be totally removed as it’s not really an official one. The Ed25519 is moved to the <a href="https://rubygems.org/gems/jwt-eddsa">jwt-eddsa gem</a> with it’s own explicit dependency requirements.</p>

<p>Also there will be a number of other breaking changes, read more about them <a href="https://github.com/jwt/ruby-jwt#upcoming-breaking-changes">here</a>.</p>

<h2 id="objects-for-managing-tokens">Objects for managing tokens</h2>

<p>Over the years the static methods <code class="language-plaintext highlighter-rouge">JWT.encode</code> and <code class="language-plaintext highlighter-rouge">JWT.decode</code> has served us well, but it has been pretty clear that for more advanced use cases the two methods and their parameters have gotten a bit bloated. To preserve backwards compatibility as good as possible the methods are going to stick with us but there is now an alternative way to handle JWT tokens.</p>

<p>Meet the new token classes <code class="language-plaintext highlighter-rouge">JWT::Token</code> and <code class="language-plaintext highlighter-rouge">JWT::EncodedToken</code>. Let’s illustrate the usage with some code samples.</p>

<h3 id="jwttoken-to-sign-and-encode-tokens"><code class="language-plaintext highlighter-rouge">JWT::Token</code> to sign and encode tokens</h3>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>token = JWT::Token.new(payload: { exp: Time.now.to_i + 60,
                                  jti: '1234',
                                  sub: "my-subject" },
                       header: { kid: 'hmac' })
token.sign!(algorithm: 'HS256', key: "secret")
token.jwt # =&gt; "eyJhbGciOiJIUzI1N..."
</code></pre></div></div>

<h3 id="jwtencodedtoken-to-decode-and-verify-tokens"><code class="language-plaintext highlighter-rouge">JWT::EncodedToken</code> to decode and verify tokens</h3>

<p>The class can be used to encode and verify signatures and claims.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>encoded_token = JWT::EncodedToken.new(token.jwt)
encoded_token.verify_signature!(algorithm: 'HS256', key: "secret")
encoded_token.verify_claims!(:exp, :jti)
encoded_token.payload # =&gt; { 'exp'=&gt;1234, 'jti'=&gt;'1234", 'sub'=&gt;'my-subject' }
encoded_token.header # {'kid'=&gt;'hmac', 'alg'=&gt;'HS256'}
</code></pre></div></div>

<p>A bit more advanced example on how to verify a token with a JWK.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>jwk = JWT::JWK.new(OpenSSL::PKey::RSA.generate(2048))

token = JWT::Token.new(payload: { exp: Time.now.to_i + 60 },
                       header: { kid: jwk.kid })

token.sign!(algorithm: 'RS256', key: jwk.keypair)

encoded_token = JWT::EncodedToken.new(token.jwt)

finder = -&gt;(t) { JWT::JWK::KeyFinder.new(jwks: [jwk]).key_for(t.header['kid']) }
encoded_token.verify_signature!(algorithm: 'RS256',
                                key_finder: finder)
encoded_token.verify_claims!(:exp)

trusted_payload = encoded_token.payload
</code></pre></div></div>]]></content><author><name>Joakim Antman</name></author><summary type="html"><![CDATA[JWT::Token and JWT::EncodedToken for your token needs]]></summary></entry><entry><title type="html">Talking to strangers</title><link href="https://antman.dev/2024/02/19/talking-to-strangers.html" rel="alternate" type="text/html" title="Talking to strangers" /><published>2024-02-19T17:11:00+00:00</published><updated>2024-02-19T17:11:00+00:00</updated><id>https://antman.dev/2024/02/19/talking-to-strangers</id><content type="html" xml:base="https://antman.dev/2024/02/19/talking-to-strangers.html"><![CDATA[<h2 id="the-challenge">The challenge</h2>

<p>Been involved in crafting software for some time already, and love discussing about the topic of software development from all kind of directions from the details of bits to team composition and way of working.</p>

<p>Talking with groups of people I know about these topics don’t feel intimidating at all and feel comfortable in that kind of setup, probably a big reason for that is the safe space that we have been able to reach during the years of working together.</p>

<p>At some point I had decided to take the leap towards the unknown and stand in front of total strangers to talk about something I find interesting. Finally saw the chance for that when i stumbled upon a local Ruby meetup and just recently had been focusing on the history of software dependencies from the point of view of the service I’m working with.</p>

<h2 id="the-talk">The talk</h2>

<p>The event was hosted by the fine <a href="https://helsinkiruby.fi/">Helsinki Ruby</a> in a cosy pub in the center of Helsinki.</p>

<p>With the title “Dependencies an asset and a curse”, the talk itself was going to tell the story of how a service had grown into what it is today from a software dependency point of view. Decisions and neglect of dependencies in the past coming back to haunt the team in the future. Main push being a Rails update from version 2.3 to Rails 7 and realizing dependencies are important and needs care.</p>

<p>Not going to go into details about the content, link to the slides and my random notes to myself is linked in the end of this post. Also there is a YouTube recording of me rambling, no idea how that turned out. I cringe if I would need to listen to myself talk.</p>

<h2 id="how-did-it-go">How did it go?</h2>

<p>All in all I’m happy that i had the courage to step up and prepare something. But the execution could have been better. The main learning is that I need to practice way more than I did to have a smoother execution. Also in the end the feeling was the people was more interested in how do you pull off a Rails 2.3 upgrade in 2023 than how important it is to keep dependencies in good shape so you never need to do a big push.</p>

<h2 id="links">Links</h2>

<ul>
  <li><a href="/assets/dependencies_an_asset_and_a_curse/dependencies_an_asset_and_a_curse.html">The slides with notes</a></li>
  <li><a href="https://youtu.be/gYYBhmSFiCE">YouTube recoding</a></li>
</ul>]]></content><author><name>Joakim Antman</name></author><summary type="html"><![CDATA[Stepping out from the comfort zone to talk about things that interest you]]></summary></entry><entry><title type="html">jwt 2.8.0 is out</title><link href="https://antman.dev/2024/02/17/ruby-jwt-2-8-0.html" rel="alternate" type="text/html" title="jwt 2.8.0 is out" /><published>2024-02-17T15:00:00+00:00</published><updated>2024-02-17T15:00:00+00:00</updated><id>https://antman.dev/2024/02/17/ruby-jwt-2-8-0</id><content type="html" xml:base="https://antman.dev/2024/02/17/ruby-jwt-2-8-0.html"><![CDATA[<p>Finally got around to cut a new release for the <a href="https://rubygems.org/gems/jwt">ruby-jwt</a> gem. The version 2.8.0 is fresh out of the oven and a full changelog can be found <a href="https://github.com/jwt/ruby-jwt/blob/v2.8.0/CHANGELOG.md">from here</a>.</p>

<p>Here are three picks on what matters in this release.</p>

<h2 id="preparing-to-deprecate-support-the-hs512256-algorithm">Preparing to deprecate support the HS512256 algorithm</h2>

<p>There has been some confusion about the algorithm called HS512256, and now the first steps to remove it is happening, the main reasoning is that his algorithm is not something that is officially mentioned in any JOSE RFCs and requires the dependency <a href="https://github.com/RubyCrypto/rbnacl">rbnacl</a> to function. Some more details about the confusion of this can be found from <a href="https://github.com/jwt/ruby-jwt/issues/322">this issue</a>.</p>

<p>Also to mention that this is NOT the same algorithm as SHA-512/256 but something <a href="https://doc.libsodium.org/advanced/hmac-sha2#hmac-sha-512-256">a bit different</a>.</p>

<h2 id="preparing-to-stricten-base64-decoding">Preparing to stricten base64 decoding</h2>

<p>Another preparation for change is to stricten the requirements for the base64 encoded tokens.</p>

<p>For example if the token contains some extra whitespaces or trailing spaces a warning is presented, but still decoded:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">irb</span><span class="p">(</span><span class="n">main</span><span class="p">):</span><span class="mo">001</span><span class="p">:</span><span class="mi">0</span><span class="o">&gt;</span> <span class="n">token</span> <span class="o">=</span> <span class="no">JWT</span><span class="p">.</span><span class="nf">encode</span><span class="p">({</span> <span class="n">con</span><span class="ss">:'tent'</span> <span class="p">},</span> <span class="kp">nil</span><span class="p">,</span> <span class="s1">'none'</span><span class="p">)</span>
<span class="o">=&gt;</span> <span class="s2">"eyJhbGciOiJub25lIn0.eyJjb24iOiJ0ZW50In0."</span>
<span class="n">irb</span><span class="p">(</span><span class="n">main</span><span class="p">):</span><span class="mo">002</span><span class="p">:</span><span class="mi">0</span><span class="o">&gt;</span> <span class="no">JWT</span><span class="p">.</span><span class="nf">decode</span><span class="p">(</span><span class="n">token</span> <span class="o">+</span> <span class="s2">"</span><span class="se">\n</span><span class="s2">"</span><span class="p">,</span> <span class="kp">nil</span><span class="p">,</span> <span class="kp">true</span><span class="p">,</span> <span class="ss">algorithm: </span><span class="s1">'none'</span><span class="p">)</span>
<span class="p">[</span><span class="no">DEPRECATION</span><span class="p">]</span> <span class="no">Invalid</span> <span class="n">base64</span> <span class="n">input</span> <span class="n">detected</span><span class="p">,</span> <span class="n">could</span> <span class="n">be</span> <span class="n">because</span> <span class="n">of</span> <span class="n">invalid</span> <span class="n">padding</span><span class="p">,</span> <span class="n">trailing</span> <span class="n">whitespaces</span> <span class="ow">or</span> <span class="n">newline</span> <span class="n">chars</span><span class="o">.</span> <span class="no">Graceful</span> <span class="n">handling</span> <span class="n">of</span> <span class="n">invalid</span> <span class="n">input</span> <span class="n">will</span> <span class="n">be</span> <span class="n">dropped</span> <span class="k">in</span> <span class="n">the</span> <span class="k">next</span> <span class="n">major</span> <span class="n">version</span> <span class="n">of</span> <span class="n">ruby</span><span class="o">-</span><span class="n">jwt</span>
<span class="o">=&gt;</span> <span class="p">[{</span><span class="s2">"con"</span><span class="o">=&gt;</span><span class="s2">"tent"</span><span class="p">},</span> <span class="p">{</span><span class="s2">"alg"</span><span class="o">=&gt;</span><span class="s2">"none"</span><span class="p">}]</span>
</code></pre></div></div>

<p>In future versions this will result in a decoding error.</p>

<h2 id="hmac-algorithms-always-to-use-built-in-openssl-variants">HMAC algorithms always to use built in openssl variants</h2>

<p>Until this release the HMAC implementation to be used would switch if the <a href="https://github.com/RubyCrypto/rbnacl">rbnacl</a> dependency was available. Now the default HMAC features will always be provided by the default OpenSSL implementation.</p>

<p>Also special thanks to <a href="https://github.com/julik">julik</a> for digging into a issue related to coordinate encoding when importing EC keys from JWKs.</p>]]></content><author><name>Joakim Antman</name></author><summary type="html"><![CDATA[Preparing to remove functionality]]></summary></entry><entry><title type="html">Hetzner DNS hosting is free!</title><link href="https://antman.dev/2022/07/07/hetzner-dns.html" rel="alternate" type="text/html" title="Hetzner DNS hosting is free!" /><published>2022-07-07T10:15:00+00:00</published><updated>2022-07-07T10:15:00+00:00</updated><id>https://antman.dev/2022/07/07/hetzner-dns</id><content type="html" xml:base="https://antman.dev/2022/07/07/hetzner-dns.html"><![CDATA[<p>Have been using the Google Cloud managed DNS service for years to host my DNS zones. This week I stumbled on the <a href="https://www.hetzner.com/dns-console">Hetzner DNS Console</a>, what I still don’t believe is that it’s totally free. It’s not that the GCloud DNS service is expensive, have cost me about 1€ a month to host my zones over there.</p>

<p>Have been using Hetzner to host my hobby things for years already, made so much sense to migrate the DNS zones over there also. Saves me a tiny amount of cash also and I can remove my credit card data from my GCloud account.</p>

<p>One thing that I needed to rethink was how the letsencrypt SSL certificates are renewed, had been using the official <a href="https://hub.docker.com/r/certbot/dns-google">certbot/dns-google</a> image to handle all that. Turns out that there is a <a href="https://github.com/BigMichi1/certbot-dns-hetzner">certbot-dns-hetzner</a> plugin for hetzner.</p>

<p>Combined the two into a simple <code class="language-plaintext highlighter-rouge">Dockerfile</code></p>

<div class="language-Dockerfile highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">FROM</span><span class="s"> certbot/certbot</span>
<span class="k">RUN </span>pip <span class="nb">install </span>certbot-dns-hetzner
</code></pre></div></div>

<p>and published it <a href="https://hub.docker.com/r/antmanj/certbot-hetzner">here</a></p>]]></content><author><name>Joakim Antman</name></author><summary type="html"><![CDATA[Why spend money on hosted DNS services.]]></summary></entry><entry><title type="html">From static to dynamic</title><link href="https://antman.dev/2022/06/11/first-post.html" rel="alternate" type="text/html" title="From static to dynamic" /><published>2022-06-11T23:00:00+00:00</published><updated>2022-06-11T23:00:00+00:00</updated><id>https://antman.dev/2022/06/11/first-post</id><content type="html" xml:base="https://antman.dev/2022/06/11/first-post.html"><![CDATA[<p>Im going to do an experiment: try to produce some software related content to this site. Also this is the first blog post I’ve ever written. It’s not long but it’s the first.</p>]]></content><author><name>Joakim Antman</name></author><summary type="html"><![CDATA[First content to this site since it was created also probably the first blog post I've ever written.]]></summary></entry><entry><title type="html">Linting in Ruby - Let the robot do the job</title><link href="https://antman.dev/2022/06/11/rubocop-pre-commit-hook.html" rel="alternate" type="text/html" title="Linting in Ruby - Let the robot do the job" /><published>2022-06-11T21:49:00+00:00</published><updated>2022-06-11T21:49:00+00:00</updated><id>https://antman.dev/2022/06/11/rubocop-pre-commit-hook</id><content type="html" xml:base="https://antman.dev/2022/06/11/rubocop-pre-commit-hook.html"><![CDATA[<p>This article was something I wrote for our team in an internal wiki a few years ago, the code is not pretty but it does the job.</p>

<p>Linting is good, right. Keeps the code consistent and catches trivial mistakes early. The Ruby go-to linter is called <a href="https://github.com/rubocop/rubocop">RuboCop</a>. It’s used in many OSS project as in in-house projects. Some like it and some don’t, on whatever side you are on the usage will often result in commit histories like this:</p>

<figure class="highlight"><pre><code class="language-raw" data-lang="raw">1fd8d091bdf27f5c73c12117e8d751a0445da4c1 fix rubocop issue
b621033f47e9dd515dcdfb472feca28934b73370 Oh c'mon rubocop
37203fa96eb96a3c07e3726c4590ae9d8470f77c Fix rubocop issue
a1b631ba5c0c99c01912705a0b16d069032537a1 And some rubocop fixes</code></pre></figure>

<p>It’s not only cluttering the commit history but many minutes are spent weekly fixing failed CI pipelines because the trivial things RuboCop is whining about. In the worst case running a <code class="language-plaintext highlighter-rouge">rubocop -A</code> will not fix the issue but you need to start changing the implementation (or disabling some RuboCop rules) and when you’re done with the fixes you probably forgot what you actually were doing.</p>

<p>A cure to all this context switching is to commit often and run RuboCop before committing. This article will present a way to automate the linting to every commit you do.</p>

<h2 id="global-git-commit-hook-executing-rubocop-or-any-other-linter-out-there">Global git commit hook executing RuboCop (or any other linter out there)</h2>

<p>Start by creating a folder for your local pre-commit hooks.</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nb">mkdir</span> <span class="nt">-p</span> ~/dot_files/git-hooks</code></pre></figure>

<p>In there create two files.</p>

<p><strong>~/dot_files/git-hooks/pre-commit</strong> The file that git calls every time a commit is about to happen</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="c">#!/bin/bash</span>

<span class="k">for </span>hook <span class="k">in</span> <span class="si">$(</span><span class="nb">dirname</span> <span class="s2">"</span><span class="nv">$0</span><span class="s2">"</span><span class="si">)</span>/pre-commit.<span class="k">*</span>
<span class="k">do
  if</span> <span class="o">[[</span> <span class="nt">-x</span> <span class="s2">"</span><span class="nv">$hook</span><span class="s2">"</span> <span class="o">]]</span>
  <span class="k">then</span>
    <span class="nv">$hook</span> <span class="s2">"</span><span class="nv">$@</span><span class="s2">"</span>
    <span class="nv">status</span><span class="o">=</span><span class="nv">$?</span>
    <span class="nb">exit</span> <span class="nv">$status</span>
  <span class="k">fi
done

</span><span class="nb">exit </span>0</code></pre></figure>

<p><strong>~/dot_files/git-hooks/pre-commit.rubocop</strong> The file that executes RuboCop on all the staged files</p>

<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="c1">#!/usr/bin/env ruby</span>

<span class="k">begin</span>
  <span class="nb">require</span> <span class="s1">'rubocop'</span>
<span class="k">rescue</span>
  <span class="nb">puts</span> <span class="s1">'RuboCop not found, skipping pre-commit hook'</span>
  <span class="nb">exit</span> <span class="mi">0</span>
<span class="k">end</span>

<span class="nb">system</span><span class="p">(</span><span class="s2">"bundle list | grep 'rubocop' &gt; /dev/null"</span><span class="p">)</span>

<span class="k">unless</span> <span class="vg">$CHILD_STATUS</span><span class="p">.</span><span class="nf">to_s</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">].</span><span class="nf">to_i</span> <span class="o">==</span> <span class="mi">0</span>
  <span class="nb">puts</span> <span class="s1">'RuboCop not included in project, skipping pre-commit hook'</span>
  <span class="nb">exit</span> <span class="mi">0</span>
<span class="k">end</span>

<span class="no">EXTENSIONS</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'.rb'</span><span class="p">,</span> <span class="s1">'.rake'</span><span class="p">,</span> <span class="s1">'.gemspec'</span><span class="p">].</span><span class="nf">freeze</span>
<span class="no">FILES</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'Gemfile'</span><span class="p">].</span><span class="nf">freeze</span>
<span class="no">ADDED_OR_MODIFIED</span> <span class="o">=</span> <span class="sr">/A|AM|^M/</span>

<span class="nb">puts</span> <span class="s2">"Running RuboCop on staged '</span><span class="si">#{</span><span class="p">(</span><span class="no">EXTENSIONS</span><span class="o">+</span><span class="no">FILES</span><span class="p">).</span><span class="nf">join</span><span class="p">(</span><span class="s1">' '</span><span class="p">)</span><span class="si">}</span><span class="s2">' files"</span>

<span class="c1"># rubocop:disable Style/MultilineBlockChain</span>
<span class="n">changed_files</span> <span class="o">=</span> <span class="sb">`git status --porcelain`</span><span class="p">.</span><span class="nf">split</span><span class="p">(</span><span class="sr">/\n/</span><span class="p">).</span>
    <span class="nf">select</span> <span class="p">{</span> <span class="o">|</span><span class="n">file_name_with_status</span><span class="o">|</span>
      <span class="n">file_name_with_status</span> <span class="o">=~</span> <span class="no">ADDED_OR_MODIFIED</span>
    <span class="p">}.</span>
    <span class="nf">map</span> <span class="p">{</span> <span class="o">|</span><span class="n">file_name_with_status</span><span class="o">|</span>
      <span class="n">file_name_with_status</span><span class="p">.</span><span class="nf">split</span><span class="p">(</span><span class="s1">' '</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span>
    <span class="p">}.</span>
    <span class="nf">select</span> <span class="p">{</span> <span class="o">|</span><span class="n">file_name</span><span class="o">|</span>
      <span class="no">EXTENSIONS</span><span class="p">.</span><span class="nf">include?</span><span class="p">(</span><span class="no">File</span><span class="p">.</span><span class="nf">extname</span><span class="p">(</span><span class="n">file_name</span><span class="p">))</span> <span class="o">||</span> <span class="no">FILES</span><span class="p">.</span><span class="nf">include?</span><span class="p">(</span><span class="no">File</span><span class="p">.</span><span class="nf">basename</span><span class="p">(</span><span class="n">file_name</span><span class="p">))</span>
    <span class="p">}.</span><span class="nf">join</span><span class="p">(</span><span class="s1">' '</span><span class="p">)</span>
<span class="c1"># rubocop:enable Style/MultilineBlockChain</span>

<span class="nb">system</span><span class="p">(</span><span class="s2">"bundle exec rubocop --force-exclusion </span><span class="si">#{</span><span class="n">changed_files</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> <span class="k">unless</span> <span class="n">changed_files</span><span class="p">.</span><span class="nf">empty?</span>

<span class="nb">exit</span> <span class="vg">$CHILD_STATUS</span><span class="p">.</span><span class="nf">to_s</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">].</span><span class="nf">to_i</span></code></pre></figure>

<p>To allow the hooks to get executed we need to make the files executable</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nb">chmod </span>0755 ~/dot_files/git-hooks/<span class="k">*</span></code></pre></figure>

<p>The last step of the game is to configure a global hooks folder for git</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash">git config <span class="nt">--global</span> core.hooksPath ~/dot_files/git-hooks</code></pre></figure>

<p>Now RuboCop will be executed on the files you changed on each commit. If for some reason you want to commit something that is violating the rules the pre-commit hooks can be skipped with the <code class="language-plaintext highlighter-rouge">--no-verify</code> parameter to the commit command.</p>]]></content><author><name>Joakim Antman</name></author><summary type="html"><![CDATA[Automatic linting with RuboCop everywhere. How to setup the unforgiving Ruby linter RuboCop.]]></summary></entry></feed>