Urgent.News

What's breaking now, across thousands of outlets.

Tech

Enforcing a style rule with a linter that actually fails the build

Background I run a fleet of static sites that publish new content every day, mostly unattended. One of the house style rules is simple: no emoji anywhere in our own copy. That rule is impossible to hold by hand. A single site builds a few hundred HTML files, and emoji can slip into nav icons, button labels, <title> , the RSS feed, or JSON-LD (the JSON-formatted metadata embedded in a page to…

A static site publishing machine has a rule against using emoji in the content. A linter is used to enforce this rule. However, the linter fails the build when it encounters emoji in certain situations. This article discusses how the author solved this problem.

The linter checks each file for the presence of emoji using a regular expression. If an emoji is found, the check fails and stops the publish process. The linter was designed to catch emoji in nav icons, button labels, title, RSS feed, and JSON-LD metadata. However, there were cases where the linter incorrectly flagged content that should not have been flagged.

The first situation was when the linter flagged verbatim quotes from other people. The linter only flagged these quotes if they had a specific HTML attribute. The author rejected this approach because it would allow anyone to add a specific class to their content and bypass the rule.

The second situation was when the linter flagged proper nouns. The linter needed a different unit of exclusion for proper nouns. The author created a list of proper nouns that should not be flagged. If a proper noun was found in the content, the linter would mask it with spaces. This prevented the linter from incorrectly flagging proper nouns.

The third situation was when the linter was not decoding numeric character references before scanning for emoji. The author fixed this by decoding the numeric references first, then masking the emoji. This ensured that the linter only flagged actual emoji and not numeric references that looked like emoji.

The author added a feature to the linter that counted the number of exclusions made. This made it easier to see if the linter was passing because it was excluding too much content. The author also added a feature to the linter that would report any unused allow-list entries. This helped keep the allow-list from growing and becoming an escape hatch.

Overall, the linter successfully enforced the style rule that no emoji should be used in the content. The linter was able to exclude content that should not be flagged and report any exclusions made. This helped ensure that the site was publishing accurate content without any unnecessary flags.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Don't validate the output. Validate that you were allowed to generate it.

Introduction I run a site that collects overseas viewer comments about individual anime episodes, translates them, and publishes them. It updates automatically every day.

  • Check function compares claimed air date with observed date from MyAnimeList (MAL)
  • Five-day tolerance accounts for time zones and streaming delays
  • Early exit if any episode fails air date check to prevent false information generation

The Counter That Counted a Call the Preflight Never Reached

This is a submission for DEV's Summer Bug Smash: Clear the Lineup , powered by Sentry . Project Overview I was working on a small Python component that performs a preflight check and then, if the…

  • Bug fix alters Python component's preflight check behavior
  • Counter now accurately records normal callback invocation
  • Regression test confirms 0 return on preflight exception

Why I Built an Ad-Free Alternative to Untappd

I've used Untappd for years to log the beers I drink. It works. It also drives me a little crazy every time I open it. Between the ads wedged into my feed, the check-in pressure that makes logging a…

  • Author created HopLog as ad-free alternative to Untappd
  • Inspired by Letterboxd's user-friendly design
  • HopLog launched at hoplog-web.vercel.app for preview

More from Sunday 23 August →