eslint-import-resolver-typescript-bun
TypeScript icon, indicating that this package has built-in type declarations

0.0.87 • Public • Published

eslint-import-resolver-typescript-bun

GitHub Actions npm GitHub Release

Conventional Commits projen

This plugin simply adds workarounds to eslint-import-resolver-typescript when resolving Bun's modules.

You can use eslint-plugin-import on your Bun project directly with this resolver!

How it works

This resolver reads bun-types and list all Bun modules defined there. Currently, we assume all Bun modules start with bun e.g. bun, bun:test, etc.

Then, when resolving, if the requested module is one of the Bun modules detected above, the resolver returns { found: true, path: null }. Otherwise, it delegates to eslint-import-resolver-typescript.

Installation

# npm
npm i -D eslint-plugin-import eslint-import-resolver-typescript-bun

# pnpm
pnpm i -D eslint-plugin-import eslint-import-resolver-typescript-bun

# yarn
yarn add -D eslint-plugin-import eslint-import-resolver-typescript-bun

Configuration

All configurations are passed to eslint-import-resolver-typescript. Simply replace your resolver name from typescript to typescript-bun!

module.exports = {
  extends: ["plugin:import/recommended", "plugin:import/typescript"],
  parser: "@typescript-eslint/parser",
  parserOptions: {
    project: true,
  },
  plugins: ["@typescript-eslint"],
  root: true,
  settings: {
    "import/parsers": {
      "@typescript-eslint/parser": [".ts", ".tsx"],
    },
    "import/resolver": {
      "typescript-bun": {
        // ^^ HERE! ^^
        project: true,
        alwaysTryTypes: true,
      },
    },
  },
  rules: {
    "import/order": [
      "warn",
      {
        groups: ["builtin", "external"],
        alphabetize: {
          order: "asc",
          caseInsensitive: true,
        },
      },
    ],
  },
};

See eslint-import-resolver-typescript configuration here.

Debug

Use DEBUG environment variable provided by debug:

$ DEBUG=eslint-import-resolver-typescript\* bun x eslint src/index.ts
  eslint-import-resolver-typescript looking for: bun-types +0ms
  eslint-import-resolver-typescript matched node path: /workspaces/asideline/node_modules/bun-types/types.d.ts +101ms
  eslint-import-resolver-typescript-bun found bun modules: Set(5) { 'bun', 'bun:test', 'bun:sqlite', 'bun:jsc', 'bun:ffi' } +0ms
  eslint-import-resolver-typescript-bun matched bun modules: bun:test +2ms

Development

This project uses Projen and Yarn 1.

git clone https://github.com/opsbr/eslint-import-resolver-typescript-bun.git
cd eslint-import-resolver-typescript-bun
yarn install
yarn build

Acknowledgement

Author

OpsBR Software Technology Inc.

License

Apache-2.0

Readme

Keywords

none

Package Sidebar

Install

npm i eslint-import-resolver-typescript-bun

Weekly Downloads

774

Version

0.0.87

License

Apache-2.0

Unpacked Size

23.8 kB

Total Files

6

Last publish

Collaborators

  • riywo
  • opsbr-release