Find the Bug the Linter Missed

Your first pull request is merged, and npm run lint is happy with every file in the project. That makes the second issue, “Show a closing-soon notice on the home page,” look like a quick one. The previous developer already wrote closingSoonNotice() in src/lib/closing-soon.js, and ESLint checked it, so it looks like all that’s left is to put it on the page.

In this lesson, you’ll try the function before you use it, find a bug that a clean lint report let through, and see how your formatter hid it from the linter. Then you’ll fix it in a pull request that you update with a second push. Start where every pull request starts now, on a fresh branch.

Try the Notice Before You Use It

Your laptop’s main already has the merged ESLint and Prettier work from the last lesson, so branch off it for the new issue:

Language: Shell
$ git switch -c closing-soon-notice
Switched to a new branch 'closing-soon-notice'

The notice should appear only in the store’s last hour, so the home page could take until this evening to show whether it works. Instead, you can call the function from the terminal with a fixed date and time. Read this command before you run it:

Language: Shell
$ node --input-type=module -e '
import { closingSoonNotice } from "./src/lib/closing-soon.js";
const evening = new Date(2026, 11, 1, 20, 30);
console.log(JSON.stringify(closingSoonNotice(evening, 60)));
'

node --input-type=module -e runs the code between the quotes as an ES module, so it can import from your project. The date is Tuesday, December 1, at 8:30 p.m. Date counts months from zero, so 11 is December. The store closes at 9 p.m. on Tuesdays, and 60 asks for the notice in the last 60 minutes.

JSON.stringify() puts quotes around the result, so an empty string shows up as "" rather than a blank line. ESLint found no problems in this file, so what do you expect the Node command to print? Make your prediction, then run the command and open the answer below.

Language: Shell
""

Node prints an empty string half an hour before closing. Open src/lib/closing-soon.js and read line 7:

Language: JavaScript
  if ((today.closed = !today.closed)) {

That’s a single =, an assignment, not a comparison. On an open day, today.closed is undefined, so !today.closed is true. The line stores true in today.closed, and the if then sees true and returns "", so the notice never appears on a day the store is open.

If you expected the notice, then you trusted the linter, and that’s perfectly reasonable. ESLint has a rule for exactly this mistake, and it’s in the recommended set you’re using. So why didn’t it say anything?

See Why ESLint Stayed Quiet

To find out, look at how line 7 changed on its way into main. Your branch starts at the squash commit from your first pull request, so HEAD is that commit, and git show with a path shows only that file’s part of it:

Language: Shell
$ git show HEAD -- src/lib/closing-soon.js
...
 export function closingSoonNotice(date, leadMinutes) {
-    const today = hoursFor(date)
-  let minutesLeft
-    if (today.closed = !today.closed) {
-        return ""
-    }
...
+  const today = hoursFor(date);
+  if ((today.closed = !today.closed)) {
+    return "";
+  }
...

The output is shortened here. The previous developer wrote one pair of parentheses, and the line came out of your first pull request with two. Your two fixes didn’t touch it, so the second pair came from Prettier, in the reformat commit.

Prettier wraps an assignment inside a condition in extra parentheses, so a reader can see it’s there.

You can watch what that does to ESLint in the editor. In closing-soon.js, delete one of the two pairs of parentheses on line 7, so it reads if (today.closed = !today.closed) {, but don’t save yet. A red squiggle appears under the assignment because the ESLint extension checks the file as you type. Hover over it, and the message reads Expected a conditional expression and instead saw an assignment., followed by eslint(no-cond-assign).

Now save. Format on save puts the second pair of parentheses back, and the squiggle disappears.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.