dword-design / eslint-plugin-import-alias Goto Github PK
View Code? Open in Web Editor NEWAn ESLint plugin that enforces the use of import aliases. Also supports autofixing.
License: Other
An ESLint plugin that enforces the use of import aliases. Also supports autofixing.
License: Other
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.
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
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 ..
?
Hi - I'm having trouble with getting this plugin working. I followed the instructions in the README and get this error:
Error: Failed to load config "plugin:import-alias/recommended" to extend from.
๐
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.