oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.27k stars 2.69k forks source link

Documentation for Bun global intellisense in JavaScript & eslint "no-undef" #5114

Open NyxaYu opened 1 year ago

NyxaYu commented 1 year ago

What is the type of issue?

Documentation is missing

What is the issue?

I wanted to try out Bun recently and so I set it up in my existing JS project, everything went smoothly until I tried using the Bun global.

The first issues was that the Bun global had the "any" type and would not provide any intellisense on it. To fix this I added the following lines to my jsconfig.json:

"compilerOptions": {
    "types": [ "bun-types" ]
}

NOTE: When I was originally writing this issue I had my own jsconfig.json that prevented bun init from overwriting it and didn't know that those lines would be added by default!
The second issues was that ESLint would fail to resolve this type and gave me the following error: 'Bun' is not defined. eslint(no-undef)

To fix this I added these lines into my .eslintrc.json:

"globals": {
    "Bun": false
}

These issues may be trivial to some however before today I didn't know about such features. Overall I think that adding some documentation for both of these in the form of a migration guide and ESLint guide would be helpful to other users who are in the same situation as me.

Where did you find it?

No response

akshatmishra25 commented 1 year ago

Can you assign me this issue as I have written some documentation regarding this.

akshatmishra25 commented 12 months ago

Here is some sample documentation I've written for the project Bun JavaScript Project Integration Guide Introduction This guide will walk you through the process of integrating Bun into your existing JavaScript project. It covers configuration steps and how to resolve common issues related to type checking and ESLint.

Prerequisites Before you begin, ensure you have the following:

Node.js and npm installed on your machine. An existing JavaScript project. Installation First, let's install Bun in your project: npm install bun Configuration 1. Updating jsconfig.json Issue: Bun Global Type is "any" If you're facing issues with the Bun global having the "any" type and not providing IntelliSense, you can resolve this by adding the following lines to your jsconfig.json: { "compilerOptions": { "types": [ "bun-types" ] } } Note: If you already have a custom jsconfig.json, ensure that it doesn't prevent Bun from overwriting these lines, as they are added by default.

2. Updating .eslintrc.json Issue: ESLint Fails to Resolve "Bun" If ESLint is failing to resolve the "Bun" type and you encounter the error "'Bun' is not defined. eslint(no-undef)", you can fix this by adding the following lines to your .eslintrc.json: { "globals": { "Bun": false } } Usage Now that you've configured Bun in your project, you can start using it for your JavaScript development.

Migration Guide If you are migrating your project to use Bun, consider the following steps:

Installation: Install Bun as shown in the installation section.

Configuration: Update your jsconfig.json and .eslintrc.json files following the instructions in the configuration section to ensure proper type checking and ESLint integration.

Code Adjustments: Review your code for any specific adjustments required to work with Bun.

Testing: Thoroughly test your project to ensure that Bun is working as expected.

ESLint Guide To make the most out of ESLint with Bun, follow these steps:

Configuration: Ensure that your .eslintrc.json file includes the "globals" configuration as mentioned in the configuration section.

Rules: Consider adding or modifying ESLint rules to match your project's coding standards. Bun works seamlessly with ESLint to enforce code quality.

Conclusion You've successfully integrated Bun into your JavaScript project and resolved common configuration issues. With Bun and ESLint working together, you can maintain code quality and improve your development workflow.