All Projects → johvin → Eslint Import Resolver Alias

johvin / Eslint Import Resolver Alias

Licence: mit
a simple Node behavior import resolution plugin for eslint-plugin-import, supporting module alias

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Eslint Import Resolver Alias

Xo
❤️ JavaScript/TypeScript linter (ESLint wrapper) with great defaults
Stars: ✭ 6,277 (+5087.6%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin
ESLint configurations and additional rules for me
Stars: ✭ 19 (-84.3%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Jest
ESLint plugin for Jest
Stars: ✭ 699 (+477.69%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Babel
An ESlint rule plugin companion to babel-eslint
Stars: ✭ 391 (+223.14%)
Mutual labels:  eslint, eslint-plugin
Sowing Machine
🌱A React UI toolchain & JSX alternative
Stars: ✭ 64 (-47.11%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Sonarjs
SonarJS rules for ESLint
Stars: ✭ 458 (+278.51%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin I18n Json
Fully extendable eslint plugin for JSON i18n translation files.
Stars: ✭ 101 (-16.53%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Vue
Official ESLint plugin for Vue.js
Stars: ✭ 3,592 (+2868.6%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Monorepo
ESLint Plugin for monorepos
Stars: ✭ 56 (-53.72%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Lwc
Official ESLint rules for LWC
Stars: ✭ 51 (-57.85%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Testing Library
ESLint plugin to follow best practices and anticipate common mistakes when writing tests with Testing Library
Stars: ✭ 384 (+217.36%)
Mutual labels:  eslint, eslint-plugin
Typescript Eslint
✨ Monorepo for all the tooling which enables ESLint to support TypeScript
Stars: ✭ 10,831 (+8851.24%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Typescript
TypeScript plugin for ESLint
Stars: ✭ 342 (+182.64%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Simple Import Sort
Easy autofixable import sorting.
Stars: ✭ 493 (+307.44%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Html
An ESLint plugin to extract and lint scripts from HTML files.
Stars: ✭ 333 (+175.21%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Node
Additional ESLint's rules for Node.js
Stars: ✭ 740 (+511.57%)
Mutual labels:  eslint, eslint-plugin
Eslint Config Auto
Automatically configure ESLint based on project dependencies
Stars: ✭ 302 (+149.59%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Import
ESLint plugin with rules that help validate proper imports.
Stars: ✭ 3,722 (+2976.03%)
Mutual labels:  eslint-plugin, eslint
Eslint Plugin Vue I18n
🌐 ESLint plugin for Vue I18n
Stars: ✭ 50 (-58.68%)
Mutual labels:  eslint, eslint-plugin
Eslint Mdx
ESLint Parser/Plugin for MDX
Stars: ✭ 89 (-26.45%)
Mutual labels:  eslint, eslint-plugin

eslint-import-resolver-alias

Version npm Version node Build Status Download Dependencies peerDependencies Coverage Status Known Vulnerabilities License

This is a simple Node.js module import resolution plugin for eslint-plugin-import, which supports native Node.js module resolution, module alias/mapping and custom file extensions.

Installation

Prerequisites: Node.js >=4.x and corresponding version of npm.

npm install eslint-plugin-import eslint-import-resolver-alias --save-dev

Usage

Pass this resolver and its parameters to eslint-plugin-import using your eslint config file, .eslintrc or .eslintrc.js.

// .eslintrc.js
module.exports = {
  settings: {
    'import/resolver': {
      alias: {
        map: [
          ['babel-polyfill', 'babel-polyfill/dist/polyfill.min.js'],
          ['helper', './utils/helper'],
          ['material-ui/DatePicker', '../custom/DatePicker'],
          ['material-ui', 'material-ui-ie10']
        ],
        extensions: ['.ts', '.js', '.jsx', '.json']
      }
    }
  }
};

Note:

  • The alias config object contains two properties, map and extensions, both of which are array types
  • The item of map array is also array type which contains 2 string
    • The first string represents the alias of module name or path
    • The second string represents the actual module name or path
  • The map item ['helper', './utils/helper'] means that the modules which match helper or helper/* will be resolved to ./utils/helper or ./utils/helper/* which are located relative to the process current working directory (almost the project root directory). If you just want to resolve helper to ./utils/helper, use ['^helper$', './utils/helper'] instead. See issue #3
  • The order of 'material-ui/DatePicker' and 'material-ui' cannot be reversed, otherwise the alias rule 'material-ui/DatePicker' does not work
  • The default value of extensions property is ['.js', '.json', '.node'] if it is assigned to an empty array or not specified

If the extensions property is not specified, the config object can be simplified to the map array.

// .eslintrc.js
module.exports = {
  settings: {
    'import/resolver': {
      alias: [
        ['babel-polyfill', 'babel-polyfill/dist/polyfill.min.js'],
        ['helper', './utils/helper'],
        ['material-ui/DatePicker', '../custom/DatePicker'],
        ['material-ui', 'material-ui-ie10']
      ]
    }
  }
};

When the config is not a valid object (such as true), the resolver falls back to native Node.js module resolution.

// .eslintrc.js
module.exports = {
  settings: {
    'import/resolver': {
      alias: true
    }
  }
};

CHANGELOG

CHANGELOG

References

  • eslint-plugin-import/no-extraneous-dependencies
  • eslint-plugin-import/no-unresolved
  • eslint-module-utils/resolve
  • resolve
  • eslint-import-resolver-node
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].