console.log to victory!

by Keiran O'Leary, Senior Software Engineer

A colleague of mine was investigating a peculiar bug within a separate company's codebase. They needed to observe the bug in staging, and got to the point where console.log was the best/only approach.

However, the deployment pipeline for this repo had a linting step which threw...

Calls to console.log are not allowed (no-console.log)

Pretty fair call… just not ideal when spelunking, and without permissions to update the pipeline's tslint config what to do?


Initial approach

The above situation sparked a wonderful office collaborative challenge of "how can we outsmart/confuse the linter"!

"..how about simply accessing log via a string on console?"

console["log"]("YOU'RE NOT MY SUPERVISOR!!!");

This was however met with...

Object access via string is disallowed (no-string-literals)

Caught again!


Finally

"What about trying to assign a variable to console?"

const braveheart = console;
braveheart.log("FREEEEEDOM!!!")```

Success!

A subsequent solution included simple destructuring...

const { log: forrest } = console;
forrest("Run forrest run!!");

Ultimately it was a few minutes of fun in enjyoing how versatile javascript is. While tslint is incredibly clever, (and it is) there's always a way to outsmart it!

More articles

How do AI Clinical Notes work? - A high level review for clinicians

There has been an explosion in the availability of AI tools that help automatically create clinical notes for doctors and other health practitioners. We give a high level overview of how many of these systems are built to help doctors and other clinicians understand what they are using.

Read more

Comparing and Sorting in Elm

In this short post we will take a peek at how values can be compared and sorted in Elm, with the goal of sorting a List of records using multiple criteria.

Read more

We’d love to accelerate your next project.

Our offices

  • Brisbane
    L2, 303 Coronation Drive
    4064, Brisbane, Australia