# Eslint: Expected { after 'while' condition

**URL:** https://meta.discourse.org/t/eslint-expected-after-while-condition/236003
**Category:** Development
**Created:** [August 12, 2022, 4:19pm UTC](https://meta.discourse.org/t/eslint-expected-after-while-condition/236003 "2022-08-12T16:19:52Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [August 12, 2022, 4:19pm UTC](https://meta.discourse.org/t/eslint-expected-after-while-condition/236003/1 "2022-08-12T16:19:52Z")

</div>

I forked [Formatting toolbar](https://meta.discourse.org/t/formatting-toolbar/40649) to add some very custom formatting stuff.

It has [discourse-formatting-toolbar/assets/javascripts/lib/discourse-markdown/formatting\_bbcode.js at master · MonDiscourse/discourse-formatting-toolbar · GitHub](https://github.com/MonDiscourse/discourse-formatting-toolbar/blob/master/assets/javascripts/lib/discourse-markdown/formatting_bbcode.js#L1-L6)

My code looks like this:

```javascript
function replaceTitle(text) {
  while (
    text !==
    (text = text.replace(/\[title\](.+?)\[\/title\]/gi, function (match, p) {
      return `<div class="job-title">${p}</div>`;
    }))
  );
  return text;
}

```

But `eslint` complains:

```
    9:3 error Expected { after 'while' condition curly

```

I tried moving that `while` and stuff after it onto a single line (the formatting here is applied by vscode and usually works with the other plugins I manage), but that didn’t help either.

Can someone provide me with a clue?

EDIT: Well, it turns out that I don’t actually need that function, but I would still like to know what the problem is.

---

<div class="post-metadata">

### Author: ![keegan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/keegan/32/383395_2.png) [@keegan](https://meta.discourse.org/u/keegan)
#### Post date: [September 13, 2022, 10:53pm UTC](https://meta.discourse.org/t/eslint-expected-after-while-condition/236003/2 "2022-09-13T22:53:11Z")

</div>

The reason for the eslint warning is that you need curly braces surrounding your `return text`;

That is, it should look like so:

```js
  while (
    text !==
    (text = text.replace(/\[title\](.+?)\[\/title\]/gi, function (match, p) {
      return `<div class="job-title">${p}</div>`;
    }))
  ) {
    return text;
  }

```

Although JavaScript allows for the omission of the curly braces, ESLint enforces the consistent curly brace style.

More details on the `curly` rule here:

> **[Rule Details - curly - ESLint - Pluggable JavaScript Linter](https://eslint.org/docs/latest/rules/curly#rule-details)**
>
> This rule is aimed at preventing bugs and increasing code clarity by ensuring that block statements are wrapped in curly braces. It will warn when it encounters blocks that omit curly braces. | A pluggable and configurable linter tool for identifying...
