bp

Fun with Ripgrep, part 1

cartoon of doom guy from doom 2016, saying "rip and tear!!!"

Design systems have a tendency to get out of hand if you don't pay close attention. Ever wanted to know how many similarly-named elements you have in your repo? We need to find all tag name instances which start with rh-navigation-, and end with at least two dash-separated words. Why two? Because we already know that we want to have <rh-navigation-primary>, <rh-navigation-secondary>, etc - that's the whole feature, but we don't necessarily want to have similar-sounding, nearly-identical child elements like <rh-navigation-primary-item> and <rh-navigation-secondary-item>. As the wisest of men once said

There is a time and a season for everything under the sun A time to copy, A time to abstract A time to test, A time to do static analysis

etc.

Ripgrep to the rescue! Here's the one-liner I used:

rg -Ior '$1' "<(rh-navigation(-\w+){2,})( .*)?>" | sort | uniq

Breakdown:

And thus, we've discovered all the tag names in our repo which are auxiliary elements to the rh-navigation suite of elements.

Cover image CC BY-NC-SA theeysmaster