Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bun implementing a Formatter and Linter #2246

Open
SamueleBarbiera opened this issue Mar 1, 2023 · 60 comments
Open

Bun implementing a Formatter and Linter #2246

SamueleBarbiera opened this issue Mar 1, 2023 · 60 comments
Labels
enhancement New feature or request

Comments

@SamueleBarbiera
Copy link

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 SamueleBarbiera added the enhancement New feature or request label Mar 1, 2023
@xhyrom
Copy link
Collaborator

xhyrom commented Mar 1, 2023

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

@Raynos
Copy link

Raynos commented Sep 8, 2023

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.

@qhariN
Copy link
Contributor

qhariN commented Sep 8, 2023

This would be great, ➕1

@snewell92
Copy link

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.

@arthurfiorette
Copy link

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...

@malviys
Copy link

malviys commented Sep 16, 2023

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.

@approached
Copy link

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

@ghiscoding
Copy link

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 😆

@x6ax6b
Copy link

x6ax6b commented Nov 3, 2023

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.

@cdtut
Copy link

cdtut commented Nov 15, 2023

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.

@arthurfiorette
Copy link

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...

@cdtut
Copy link

cdtut commented Nov 16, 2023

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.

@arthurfiorette
Copy link

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.

@cdtut
Copy link

cdtut commented Dec 4, 2023

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.

@gustaveWPM
Copy link

gustaveWPM commented Dec 12, 2023

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

I think it is not required to reinvent it.

@borisdiakur
Copy link

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

@Barzi-Ahmed
Copy link

Barzi-Ahmed commented Jan 1, 2024

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.

@xhyrom
Copy link
Collaborator

xhyrom commented Jan 2, 2024

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

@guest271314

This comment was marked as off-topic.

@kosperera
Copy link

kosperera commented Mar 4, 2024

@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.

@guest271314

This comment was marked as off-topic.

@Barzi-Ahmed
Copy link

@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.

@GerbenRampaart
Copy link

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. 😄👍

@guest271314

This comment was marked as off-topic.

@janos-r
Copy link
Contributor

janos-r commented Apr 1, 2024

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.

@birkskyum
Copy link
Collaborator

birkskyum commented Apr 5, 2024

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.

@janos-r
Copy link
Contributor

janos-r commented Apr 7, 2024

@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.

@birkskyum
Copy link
Collaborator

birkskyum commented Apr 7, 2024

@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/

@guest271314

This comment was marked as off-topic.

@birkskyum
Copy link
Collaborator

There is also oxlint.

@dhoulb
Copy link

dhoulb commented Apr 30, 2024

I see the ecosystem evolving to something like:

  1. Combined formatter/linter/type checker to replace Prettier/Typescript type checking/ESLint/Typescript-ESLint My money is on Biome.

  2. New engine that does running/compiling/bundling to replace Node/Babel/Typescript compile etc. Deno looked good for a while but Bun is probably now the best bet.

So I don't think this is needed in Bun.

@janos-r
Copy link
Contributor

janos-r commented May 1, 2024

I don't understand the excitement for biome yet... but I tried to integrate it into helix with the official manual, tried to install globally with both npm and bun, but somehow formatting doesn't work right now. But will keep an open eye for it. It is surprisingly popular.

update:
Ok, I got it working thanks to this post biomejs/biome#2263
Getting formatting and suggestions inside helix, pretty cool and it's not slow. Biome probably just kicked out deno from my laptop.

@dhoulb
Copy link

dhoulb commented May 14, 2024

@janos-r I think Rome was blocked for a while. What Seb tried to create (a company around the toolchain so he could pay fulltime devs) was a worthy endeavour, but the market couldn't support that and along with their switch from JS to Rust the project got stuck and distracted for while.

But since Rome became Biome it's found a lot of new energy. Linting for CSS is coming soon (which can replace Stylelint in a lot of workflows), and they're working on improving built-in type analysis to (eventually, someday, down the road) replace Typescript too (probably around the same time we get native types in ECMAscript). In maybe 5-7 years it should all slot into place nicely.

I think the main reason to keep these things separate (in addition to a linter being a lot of work) is that while Bun is strongly tied to the JS ecosystem, a formatter/linter like Biome is more fundamentally language agnostic.

@kravetsone
Copy link

@janos-r I think Rome was blocked for a while. What Seb tried to create (a company around the toolchain so he could pay fulltime devs) was a worthy endeavour, but the market couldn't support that and along with their switch from JS to Rust the project got stuck and distracted for while.

But since Rome became Biome it's found a lot of new energy. Linting for CSS is coming soon (which can replace Stylelint in a lot of workflows), and they're working on improving built-in type analysis to (eventually, someday, down the road) replace Typescript too (probably around the same time we get native types in ECMAscript). In maybe 5-7 years it should all slot into place nicely.

I think the main reason to keep these things separate (in addition to a linter being a lot of work) is that while Bun is strongly tied to the JS ecosystem, a formatter/linter like Biome is more fundamentally language agnostic.

I also think that it is not worth implementing linter/formatter in Bun, but officially recommend something like biome or alternatives

Unnecessary work that will be nailed to the Bun

@brunogrcsada
Copy link

js: eslint, prettier, oxlint, biome, standard js, jshint, sonarts

meanwhile go: go fmt

@vegerot
Copy link

vegerot commented Jul 17, 2024

js: eslint, prettier, oxlint, biome, standard js, jshint, sonarts

meanwhile go: go fmt

Don't forget deno fmt ;)

@huseeiin
Copy link
Contributor

js: eslint, prettier, oxlint, biome, standard js, jshint, sonarts
meanwhile go: go fmt

Don't forget deno fmt ;)

and dprint xd

@birkskyum
Copy link
Collaborator

birkskyum commented Aug 17, 2024

I think the main reason to keep these things separate (in addition to a linter being a lot of work) is that while Bun is strongly tied to the JS ecosystem, a formatter/linter like Biome is more fundamentally language agnostic.

@dhoulb Biome website says: Biome is a fast formatter for JavaScript, TypeScript, JSX, TSX and JSON that scores 97% compatibility with Prettier,

Even if CSS is added to Biome, to me that does look a lot like the JS/Web ecosystem. I don't know if the ambition for Biome is to go beyond that though, but it looks like a CSS parser is part of the Bun roadmap too, so the overlap in scope appear quite large at least for now. Not fully convinced yet that one is more fundamentally language agnostic than the other.

@guest271314

This comment was marked as off-topic.

@guest271314

This comment was marked as off-topic.

@guest271314

This comment was marked as off-topic.

@janos-r
Copy link
Contributor

janos-r commented Aug 23, 2024

Cf. deno fmt now supports HTML, CSS, YAML, and more

Damn! Html was the last thing I still used prettier for. Now for formatting I will be all on deno (it is so much faster). For TS biome, and for svelte, the sveltserver lsp already defaults formatting to prettier under the hood, so maybe I will tweak helix to also use deno to format svelte...

@guest271314

This comment was marked as off-topic.

@guest271314

This comment was marked as off-topic.

@janos-r
Copy link
Contributor

janos-r commented Aug 23, 2024

Did you miss the code here #2246 (comment)?

I did see the

$ bun build fmt.js --no-bundle | bun -e 'Bun.write(Bun.file("fmt.js"), await Bun.file("/dev/stdin").text())'

comment, but... that looks like some unreadable hack. That is nowhere near some official bun format support. Not to mention that there were official comments above saying that bun is not in the business of formatting stuff and people should use biome or deno for formatting. Nothing wrong with that.

@guest271314

This comment was marked as off-topic.

@guest271314

This comment was marked as off-topic.

@Clemintina
Copy link

Clemintina commented Sep 22, 2024

Although I don't have experience with real world enterprise projects, a configuration file like bun.config.ts could potentially allow you to specify the formatter you want to use. For example:

export default {
	// other properties.
	formatter:'bun', // prettier, eslint, etc
        // configuration for other linters
	formatterConfig: {
		// eslint, prettier configuration here
	}
}

While this approach will lead to a heavily nested file, it could resolve issues related to portability and the reduction of multiple configuration files in the project root. This structure could also enable importing settings from other files or repositories, making the configuration both cleaner and more portable. Additionally, it offers the customisability some users in the comments seemed to want, while still allowing Bun to promote a standardised style for developers who prefer to fully commit to the Bun ecosystem.

@notramo
Copy link

notramo commented Oct 2, 2024

While reading this thread, I noticed that some commenters mentioned Biome is still in early stage.

This is no longer the case, it improved a lot in the latest few releases. It's already production-ready (which can't be said for Bun yet).

@huseeiin
Copy link
Contributor

huseeiin commented Oct 7, 2024

i think oxc's eslint-compatible (albeit not fully yet) linter is promising. i prefer that over biome or bun creating a new linter. they took the same path bun took to node compatibility.

@DoKoB0512
Copy link

They can also port OXC's Linter and Formatter just like lightningcss

@huseeiin
Copy link
Contributor

They can also port OXC's Linter and Formatter just like lightningcss

can you even develop rules for oxc or deno's linter? if no, they will never compete with eslint unfortunately

@guest271314

This comment was marked as off-topic.

@huseeiin
Copy link
Contributor

can you even develop rules for oxc or deno's linter?

Yes.

E.g., Add seperate no-process-global lint rule #1330.

what i meant is like eslint-plugin-unicorn where you can develop custom rules locally or publish them to npm

@guest271314

This comment was marked as off-topic.

@7flash
Copy link

7flash commented Oct 28, 2024

Another way to do this using a script rather than commandline

// bun run fmt.js gist-plugin.js
import { $ } from "bun";
const file = Bun.argv.at(-1);
await Bun.write(file, await $`bun build ${file} --no-bundle`.text());

Unfortunately, I noticed, its not working properly with emoji present in my code, it replaces them with \uD83D etc

@guest271314

This comment was marked as off-topic.

@notramo
Copy link

notramo commented Oct 30, 2024

@huseeiin, Biome and OXC support more rules, e.g. many from the unicorn plugin and other sources. I guess if the rules are useful and well-implemented, then they accept it upstream, so separate plugin support is not needed. The Biome team is also working on 3rd party plugin support, based on GritQL, but I would recommend submitting the rules upstream, so it benefits everyone.

@zoonderkins
Copy link

zoonderkins commented Nov 15, 2024

It’s already 2024, and the JavaScript ecosystem still faces a new framework, library, linter, formatter, or bundler every six months. Hasn’t either Bun or Node tried to unify this yet?

My solution:
In the Bun project, inside package.json, I set "lint": "deno fmt"

Then, I run:

bun run lint
$ deno fmt
Checked 9 files

Solved my problem ~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests