Comments (6)
@marcuzy: I've created a fork of your code, which implements support for aliases, like I need it:
https://github.com/jens-duttke/tslint-origin-ordered-imports-rule
The rule is: First absolute paths, then aliases (starting with "@"), then relative paths (starting with ".").
So this is correct:
import * as _ from 'lodash';
import MyAction from '@my-action';
import MyClass from './my-class';
But this is wrong:
import MyAction from '@my-action';
import * as _ from 'lodash';
import MyClass from './my-class';
It doesn't check if the alias links to a node_modules package, nor does it check if there is a node module which starts with an "@". But since both things are very unlikely, it works fine for me.
It would be nice if you could implement this, or a similar solution into your package.
Or even better: if it would be possible to configure that totally free in the tslint.json, e.g.
"origin-ordered-imports": [true, [
"^@thisImportCanAlwaysBeOnTop$", // (Reg ex) An import of a module matching this name, can always be the first one
1, // one-blank-line
"^[A-Z]", // (Reg ex) Modules starting with uppercase letters
0, // optional, to explicitly indicate no-blank-lines
"^[a-z]", // (Reg ex) Modules starting with lowercase letters
1, // one-blank-line
"^@", // (Reg ex) Modules starting with @
1, // one-blank-line
"^\." // (Reg ex) Modules starting with .
]],
from tslint-origin-ordered-imports-rule.
@jens-duttke I'll consider your idea, thanx. I found out that tslint provides access to the path
section of tsconfig.json
so it's possible to implement a support for aliases without any configuration. I see the only issue here, if the rule considers the path
section then it'll need to read the project directory to be sure that files are existent. I hope, this solution can be optimized (ex. scan the project directory once and cache it or get access to tslint's tree of files if it's possible).
from tslint-origin-ordered-imports-rule.
Custom map from tsconfig.json
Tested imports
from tslint-origin-ordered-imports-rule.
It's a curious point. I've never used this feature. Seems, it's impossible to find out whether it's node_module or something from path
section. Anyway, I'll take a look.
from tslint-origin-ordered-imports-rule.
I'd love this too, obviously the simpler the better.
One option is to use a no-implicit-dependencies
-style whitelist for modules that would force them to be treated as local modules.
from tslint-origin-ordered-imports-rule.
🎉 Just published a beta version which supports custom rules 🎉.
You could try this:
npm i -D tslint-origin-ordered-imports-rule@beta
With tsconfig.json like this:
"rules": {
"origin-ordered-imports": [
true,
"one-blank-line",
[
"lib",
"^@docebo/.+",
"user"
]
]
}
This config defines three import groups, their order and requires "one-blank-line"
between them.
"lib"
and "user"
are built-in types which work like in previous versions. See updated docs.
Please, test the beta and write here any issues you will find. 🖖
from tslint-origin-ordered-imports-rule.
Related Issues (8)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tslint-origin-ordered-imports-rule.