eslint-import-resolver-custom-alias icon indicating copy to clipboard operation
eslint-import-resolver-custom-alias copied to clipboard

How to put an alias using regexp

Open wizevlad opened this issue 4 years ago • 2 comments

The problem, I have this folder structure:

+ src
    - components
    - pages
    - state
    - utils

My jsconfig.json sets src as baseUrl:

{
  "compilerOptions": {
    "baseUrl": "src"
  }
}

So I import files using this notation:

import getFilename from 'utils/files/getFilename'

Using this plugin, I need to create an alias for all 4 subfolders and I want to say: "Every direct child inside src should be aliased".

Is that doable? Something like:

"settings": {
    "import/resolver": {
      "eslint-import-resolver-custom-alias": {
        "alias": {
          "*": "./src/*"
        },
        "extensions": [".js", ".jsx"]
      }
    }
  },

wizevlad avatar Jul 08 '21 18:07 wizevlad

@wizevlad were you able to figure this out? I'd like to do something similar, no luck thus far.

jonathanwinglee avatar Oct 21 '21 18:10 jonathanwinglee

I have created a PR #5 , please see if this will solve the problem. Here is what I think: perhaps * is too complicated for the solution, as I don't think one would create some configuration like "root/*": "./src/*". Thus instead, I create a special case for empty string, i.e. "": "./src" instead.

Let me know if you have any feedback.

laysent avatar Oct 24 '21 05:10 laysent