Coder Social home page Coder Social logo

dword-design / eslint-plugin-import-alias Goto Github PK

View Code? Open in Web Editor NEW
47.0 2.0 7.0 2.34 MB

An ESLint plugin that enforces the use of import aliases. Also supports autofixing.

License: Other

JavaScript 99.46% Shell 0.54%
alias aliases autofix babel babel-plugin-module-resolver enforce eslint fix import lint

eslint-plugin-import-alias's Issues

Prefer alias rule

Hi,

I don't get how to use the prefer-alias rule. There is no example in the documentation.

I'm using it this way atm but it doesn't work :

"@dword-design/import-alias/prefer-alias": {
        "@components": "./src/components",
        "@api": "./src/api",
        "@assets": "./src/assets",
        "@constants": "./src/constants",
        "@context": "./src/context",
        "@hook": "./src/hook",
        "@icons": "./src/icons",
        "@screens": "./src/screens",
        "@styles": "./src/styles",
        "@types": "./src/types",
        "@utils": "./src/utils"
      }

Thanks

Doesn't work for imports in the same directory

When importing from the same directory, this rule doesn't get applied. It considers this valid:

import { Foo } from './foo'

Expectation:

import { Foo } from '@/path/to/foo'

All my valid imports have the error: Unexpected subpath import via alias

Real world example:

Unexpected subpath import via alias '@lib/constants/a2.constants'. Use './constants/a2.constants' instead

Configuration in .eslintrc.js:

'@dword-design/import-alias/prefer-alias': [
  'error',
  {
    'alias': {
      '@lib': './src/'
    }
  }
],

Is there a way to get this to work with . and not just ..?

[Feature request]: Rewrite aliases to other aliases

I'm using Nuxt, and Nuxt maps the "root" directory to ~~. Because of this mapping, VSCode will often autocomplete paths to, say, a script file, to something like:

import { Foo } from '~~/legacy/scripts/Foo'

However, to reduce verbosity in commonly-used paths, I have aliases like ~js to refer to ~~/legacy/scripts.

What I would like is the ability to rewrite not just relative paths to alias paths, but alias paths to other alias paths.

So, on save (or eslint --fix), I would like the above re-written to:

import { Foo } from '~js/Foo'

Is it possible to include more customization into what is re-written? This seems somewhat related to #133, in that some customization / filters would be nice.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.