Looking for a JavaScript Formatter That Can Exclude Specific Sections

0
8
Asked By CodeNinja42 On

Hey everyone! I'm on the hunt for a JavaScript formatter that lets me skip certain sections of code. While I'm not too picky about the formatting style itself, the ability to exclude sections is a must-have, which rules out using Prettier.

For context, here's an example of a section I'd want to keep unformatted:

```javascript
class Foo {
...
// stop-formatting
get lines() { return this.#lines.length }
get col() { return this.#x + 1 }
get row() { return this.#y + 1 }
get done() { return this.#y >= this.#lines.length }
get eol() { return this.#x >= this.current_line.length }
// resume-formatting
}
```

Any suggestions would be appreciated!

3 Answers

Answered By JavaScriptWhiz99 On

Prettier only supports a 'range' ignore in markdown, and it doesn’t let you skip sections for formatting. I’ve heard of Biome, which has range suppressions, but it’s only for linting, not formatting.

A workaround could be to add an 'ignore' comment right above your `class Foo` to skip formatting there.

LinterLover23 -

I didn't know about Biome! I'll check it out as a linter, even if it won't help with formatting.

Answered By SyntaxGuru77 On

I might be confused here, but Prettier does let you ignore code via comments. Check out their official documentation for ignoring code. Is that not working for your case?

CodeNinja42 -

Nope, it doesn't work for my JavaScript setup.

Answered By CuriousCoder88 On

Can you maybe use arrow functions for this? Or is that not applicable within classes? I'm not totally sure how that works.

TechSavant202 -

Unfortunately, arrow functions would bind `this` to the class and not the instance. Also, you'd end up creating duplicate functions on each instance instead of having them on the prototype. But don't take my word for it; it’s worth a check.

CodeNinja42 -

I’m not sure either. It would be cool if it worked like that!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.