Skip to content

Latest commit

 

History

History
77 lines (59 loc) · 2.06 KB

File metadata and controls

77 lines (59 loc) · 2.06 KB

eslint-import-resolver-typescript

Build Status

This plugin adds typescript support to eslint-plugin-import.

This means you can:

  • import/require files with extension .ts/.tsx!
  • Use paths defined in tsconfig.json.

Installation

npm install --save-dev eslint-plugin-import @typescript-eslint/parser eslint-import-resolver-typescript

Configuration

Add the following to your .eslintrc config:

{
  "plugins": ["import"],
  "rules": {
    // turn on errors for missing imports
    "import/no-unresolved": "error"
  },
  "settings": {
    "import/parsers": {
      "@typescript-eslint/parser": [".ts", ".tsx"]
    },
    "import/resolver": {
      // use <root>/tsconfig.json
      "typescript": {},

      // use <root>/path/to/folder/tsconfig.json
      "typescript": {
        "directory": "./path/to/folder"
      },

      // Multiple tsconfigs (Useful for monorepos)

      // use a glob pattern
      "typescript": {
        "directory": "./packages/**/tsconfig.json"
      },

      // use an array
      "typescript": {
        "directory": [
          "./packages/module-a/tsconfig.json",
          "./packages/module-b/tsconfig.json"
        ]
      },

      // use an array of glob patterns
      "typescript": {
        "directory": [
          "./packages/**/tsconfig.json",
          "./other-packages/**/tsconfig.json"
        ]
      }
    }
  }
}

Contributing

  • Make sure your change is covered by a test import.
  • Make sure that npm test passes without a failure.
  • Make sure your code is formatted npm format.

We have an automatic travis build which will run the above on your PRs. If either fails, we won't be able to merge your PR until it's fixed.