bun icon indicating copy to clipboard operation
bun copied to clipboard

Bun implementing a Formatter and Linter

Open SamueleBarbiera opened this issue 1 year ago • 35 comments

What is the problem this feature would solve?

instead of installing eslint or prettier (or even rome) used for linting and formatting purposes why not implement it

What is the feature you are proposing to solve the problem?

to have a way more performant dev exp. and even on the ci

What alternatives have you considered?

No response

SamueleBarbiera avatar Mar 01 '23 08:03 SamueleBarbiera

now, there are other priorities but thanks for this feature request

xHyroM avatar Mar 01 '23 13:03 xHyroM

The eslint alternative would be the real killer tool to make me want to adopt bun.

I want a cli tool that I can use to replace eslint ; prettier; esbuild ; pnpm ; ava etc. A single CLI tool to control them all ( minus tsc which warrants not rewriting ).

Having a lint tool would be a huge boon for local development.

Raynos avatar Sep 08 '23 21:09 Raynos

This would be great, ➕1

qhariN avatar Sep 08 '23 21:09 qhariN

Would be interesting to see how far we can do in cleaning up the roots of our projects when using bun without additional user complexity (like vite --config config/vite.config.js for example).

A boilerplatey eslint/prettier/vite project looks like:

image

as my entrypoint is an html file with <script src="src/main.ts"></script> so I use bun run vite and that build script to build main and move index and replace it with the hashes main filename.

I'm pretty happy rn tho, each tool has its ways to move/specify a config file path and bun, largely, doesn't have any config, so I can move any build scripts whever.

snewell92 avatar Sep 09 '23 13:09 snewell92

Bun should provide a formatter. I know its not priority, but it should have. The only thing we should consider when implementing it is to make it opnionated and universal, just like go fmt:

image

I think everyone can agree that this was a right decision for golang, no more debates on where spaces or tabs should be used. We just run bun format and our code follow a standard we can find on ALL bun projects out there...

arthurfiorette avatar Sep 11 '23 01:09 arthurfiorette

Looking for same, found this request. Since bun is trying to solve all issues in js ecosystem this will a great addon, as most of recent languages are providing same kind of tooling to make dev life easier.

malviys avatar Sep 16 '23 13:09 malviys

I highly recommend to use: https://biomejs.dev/ . It based on rust 💯 and the installation via bunx is available.

approached avatar Sep 22 '23 12:09 approached

I highly recommend to use: https://biomejs.dev/ . It based on rust 💯 and the installation via bunx is available.

For users who didn't know, that is basically the rebrand of Rome as mentioned in their blog post: https://biomejs.dev/blog/annoucing-biome/

Biome is designed to eventually replace Babel, ESLint, webpack, Prettier, Jest, and others.

they seem to have very similar goals as Bun 😆

ghiscoding avatar Oct 14 '23 07:10 ghiscoding

I highly recommend to use: https://biomejs.dev/ . It based on rust 💯 and the installation via bunx is available.

This is just another Prettier and ESLint. If I'm going to use this, I should just use Prettier and ESLint. All I need is the official internal tools of Bun.

x6ax6b avatar Nov 03 '23 03:11 x6ax6b

Formatter shouldn't be opinionated because it's not a new language like go. It will prevent many teams from switching. Allow lots of customization so it works with any existing code so people can use bun instead of external tool.

cdtut avatar Nov 15 '23 22:11 cdtut

This is just another Prettier and ESLint. If I'm going to use this, I should just use Prettier and ESLint. All I need is the official internal tools of Bun.

I completely disagree what you are saying. BiomeJS is super fast and built outside of the JS land, which makes it super fast and more prone to be implemented by Bun. And creating a formatter and linter is a project of its own, there's not way bun will have funds and time to do it by themselves, adopting a open source project is the only solution.

Formatter shouldn't be opinionated because it's not a new language like go. It will prevent many teams from switching. Allow lots of customization so it works with any existing code so people can use bun instead of external tool.

But bun is a new tech, teams will have to adopt it manually anyways...

arthurfiorette avatar Nov 16 '23 01:11 arthurfiorette

But bun is a new tech, teams will have to adopt it manually anyways...

But javascript isn't a new tech.

Bun is a replacement for node.js. Teams won't change their runtime if they are forced to change their style for existing code.

cdtut avatar Nov 16 '23 01:11 cdtut

Bun is a replacement for node.js. Teams won't change their runtime if they are forced to change their style for existing code.

They will not be forced, ONLY if they also want to change their internal linting/style system to a standardized one by removing their prettier/eslint/... to bun, then yes.

arthurfiorette avatar Nov 16 '23 01:11 arthurfiorette

They will not be forced, ONLY if they also want to change their internal linting/style system to a standardized one by removing their prettier/eslint/... to bun, then yes.

Or can make configurable so teams can decide on their own format and still benefit from bun tools. Benefit is standardization within a repo with the tool formatting the code according to settings for that repo. Bun developers don't need to tell you exactly how your code should look only that it follows the settings you chose.

cdtut avatar Dec 04 '23 05:12 cdtut

Just tried Biome rn. It rocks, even if it is still way too early.

I think it is not required to reinvent it.

gustaveWPM avatar Dec 12 '23 10:12 gustaveWPM

I'm now using deno's formatter (deno fmt) alongside bun.

borisdiakur avatar Dec 21 '23 15:12 borisdiakur

I'm now using deno's formatter (deno fmt) alongside bun.

@borisdiakur I am also interested to use deno's formatter and linter for my bun project, could you please provide a tip on how do I do it? Like, what do I need to install and configure to get it working? thank you.

Barzi-Ahmed avatar Jan 01 '24 20:01 Barzi-Ahmed

I'm now using deno's formatter (deno fmt) alongside bun.

@borisdiakur I am also interested to use deno's formatter and linter for my bun project, could you please provide a tip on how do I do it? Like, what do I need to install and configure to get it working? thank you.

i think you just need deno, nothing more, nothing less

xHyroM avatar Jan 02 '24 10:01 xHyroM

I do tend to use deno fmt frequently for .js and .json files. But I use deno, bun, and node regularly, and try to write code that runs in all three of those runtimes, at least, if possible including tjs (txiki.js) and qjs (QuickJS). So it's not uncommnon for me to use deno for fmt, bun for build(), tjs for a TCP server that runs for 13 MB RSS versus bun at 43 MB RSS.

Here's a Chromium extension to implement formatting when Chromium removed the formatter from DevTools https://github.com/guest271314/devtools_panel_code_formatter. js-beautify from a CDN as a single .js file is 72.6 KB. Chromium subsequently relanded the built-in formatter in Sources/Snippets panel.

Using bunx install -g <formatter> works, too.

guest271314 avatar Jan 10 '24 07:01 guest271314

@borisdiakur I'm now using deno's formatter (deno fmt) alongside bun.

@Barzi-Ahmed @borisdiakur I am also interested to use deno's formatter and linter for my bun project, could you please provide a tip on how do I do it? Like, what do I need to install and configure to get it working? thank you.

@xHyroM i think you just need deno, nothing more, nothing less

Yep, and the VS Code extension, settings, and config to make it behave the way would want, so you wouldn't have to install and configure eslint, stylistic, prettier, biome, and whatnot. See @alertbox/docsify-footer for a variant of minimal setup.

Ideally, we'd be able to just do bun fmt and bun lint or some variation of it.

kosperera avatar Mar 04 '24 21:03 kosperera

@kosperera Never tried VS Code. I generally use a basic text editor. If I want an IDE all Chromium based browsers, e.g., Chrome, Brave, Edge are shipped with a built-in IDE in DevTools Snippets. deno fmt works. Just be careful with larger files. Could cause deno to panic, or freeze the entire system.

guest271314 avatar Mar 04 '24 22:03 guest271314

@borisdiakur I'm now using deno's formatter (deno fmt) alongside bun.

@Barzi-Ahmed @borisdiakur I am also interested to use deno's formatter and linter for my bun project, could you please provide a tip on how do I do it? Like, what do I need to install and configure to get it working? thank you.

@xHyroM i think you just need deno, nothing more, nothing less

Yep, and the VS Code extension, settings, and config to make it behave the way would want, so you wouldn't have to install and configure eslint, stylistic, prettier, biome, and whatnot. See @alertbox/docsify-footer for a variant of minimal setup.

Ideally, we'd be able to just do bun fmt and bun lint or some variation of it.

Hmm... No i discarded Deno Linter and Deno formatter, because I use Astro now and they neither lint nor format .astro files. Might go back to prettier and eslint.

Maybe it will be useful for nextjs projects as its just standard tsx, not specific file like .astro.

Also, I wanted to say that I've changed my mind, it is good for Bun project to NOT implement a formatter or linter, because I'm sure it might harm the project, the scope of project is already too wide (transpiler, unit test, bundler, etc). So i want them to focus on what's on the table, also more windows and nodejs compatibility.

Barzi-Ahmed avatar Mar 05 '24 09:03 Barzi-Ahmed

I build a few in-company cli tooling with deno and love the experience of having an opinionated way to do everything all the way to formatting and linting with the runtime.

I certainly respect people loving their eslint and prettier setup and I sure setup those things for many years.

But for me it's just another thing that is fine out of the box. I don't care if I use airbnb or google for linting. I just need a consistent default way and have less config files and be done with it.

I'm suspecting lots of people are in the same situation so I'm all for an integrated experience. And if you still want a .prettierrc then go nuts. 😄👍

GerbenRampaart avatar Mar 23 '24 06:03 GerbenRampaart

Be careful with this. Deno's deno fmt can freeze the entire machine when the file is greater than an unknown arbitrary length.

guest271314 avatar Mar 23 '24 16:03 guest271314

I also use deno fmt for bun... Actually I use helix cli editor (it's amazing) with this language config, to format on save... and its blazingly fast! Very comfortable. And it's not a hack... its even one of the recommendations on the helix git wiki to use deno fmt

## ~/.config/helix/languages.toml
[[language]]
name = "typescript"
indent = { tab-width = 4, unit = "    " } # to match the formater before auto-save
formatter = { command = 'deno', args = [  "fmt",  "-",  "--ext",  "ts",  "--indent-width",  "4", ] }
auto-format = true

But yeah, it would be nice if I could run bun lint out of the box. Or if bun had a language server that doesn't flag bun imports like tests as non-existent (currently using the recommended "typescript-language-server"). But detail. In general it's amazing how well bun fits in the default TS setup I already had and its very fast and comfortable to write.

janos-r avatar Apr 01 '24 23:04 janos-r

I highly recommend to use: https://biomejs.dev/ . It based on rust 💯 and the installation via bunx is available.

For users who didn't know, that is basically the rebrand of Rome as mentioned in their blog post: https://biomejs.dev/blog/annoucing-biome/

Biome is designed to eventually replace Babel, ESLint, webpack, Prettier, Jest, and others.

they seem to have very similar goals as Bun 😆

It would appear the biome website was refreshed and now only mention Formatting and Linting, but no test/bundling/transpiling. Seems like a more reduced scope compared to the original vision for Rome, which bun basically has delivered all other areas of in the meantime. Using biome and bun together is such a bliss compared to what i had before. Bun might be able to outdo biome on performance, but anyone moving from eslint/prettier to biome will already be blown away by the perf, so might be a hard sell.

birkskyum avatar Apr 05 '24 22:04 birkskyum

@birkskyum Hmm, nice, they even specify how to use it with helix (the only editor they mention there directly, lol) https://github.com/biomejs/biome/blob/main/editors/helix/manual.md I knew it in the past but forgot what specific formatter deno is using under the hood, somebody told me before, but I wonder if Biome is using the same formatter or if they really built their own?! For now, I will stay with the deno formater, I am glad that it is easy to update and that its installed properly as a binary, not as a global npm package. But I will keep biome in mind. It's nice they also provide a linter that integrates nicely.

janos-r avatar Apr 07 '24 10:04 janos-r

@janos-r

I knew it in the past but forgot what specific formatter deno is using under the hood

Seems like under the hood deno fmt is using https://dprint.dev/

birkskyum avatar Apr 07 '24 13:04 birkskyum

Keep in mind nothing is stopping any programmer from using bun, deno, and node, and other JavaScript/TypeScript engines/runtimes at the same time. Use deno for lint, fmt, import map support, full-duplex streaming, compiling to a standalone executable with denort to ~78 MB. Use bun for faster reading STDIN, writing to STDOUT, plugin, bun install, and so forth.

guest271314 avatar Apr 07 '24 13:04 guest271314

https://dprint.dev/

Ah yeah! dPrint! When it formats on crtl+s press, it is such a dramatic user experience improvement from prettier, it's night and day. That makes me hesitant to go back to npm packages (even though its biome) to do this, hehe. I wonder what biome used.

janos-r avatar Apr 07 '24 22:04 janos-r