Giter VIP home page Giter VIP logo

tslint-origin-ordered-imports-rule's Introduction

The project is deprecated, since tslint stopped its developing.

Build Status

TSLint Origin Ordered Imports Rule

Custom rule for tslint

Strict order for imports ("Lib import" must be higher than "User import") + your own import groups defined by regexps.

๐Ÿš€ This plugin needs minimum configuration to start:

npm i -D tslint-origin-ordered-imports-rule

tslint.json

"rulesDirectory": [
    "node_modules/tslint-origin-ordered-imports-rule/dist"
],
"rules": {
    "origin-ordered-imports": [ true ]
}

Wrong:

import MyClass from './my-class';
import * as _ from 'lodash';

Right:

import * as _ from 'lodash';
import MyClass from './my-class';

Then you might set one-blank-line option to require a blank line between import groups. In such a case, the previous code becomes wrong.

Right:

import * as _ from 'lodash';

import MyClass from './my-class';

Apart from one-blank-line, there are a few other options:

  • no-blank-lines
  • at-least-one-blank-line
  • any-number-of-blank-lines

This plugin was created to be as simple as possible, with zero-configuration. It could still be used in that way, but if you need more configurable tool just define the array which describes your own order.

tsconfig.json

"rules": {
    "origin-ordered-imports": [ 
        true, 
        "one-blank-line",
        [
            "lib",
            "^@custom/.+",
            "user"
        ] 
    ]
}

Wrong:

import * as _ from 'lodash';
import * as moment from 'moment';

import MyClass from './my-class';
import MyClass2 from './my-class2';

import Foo from '@custom/foo';
import Bar from '@custom/bar';

Right:

import * as _ from 'lodash';
import * as moment from 'moment';

import Foo from '@custom/foo';
import Bar from '@custom/bar';

import MyClass from './my-class';
import MyClass2 from './my-class2';

Actually, you can omit lib and user items as they will be added automatically to the beginning and the ending respectively.

Testing

To test the rule just run:

npm run compile
npm run test

Licensing

The code in this project is licensed under MIT license.

tslint-origin-ordered-imports-rule's People

Contributors

dependabot[bot] avatar marcuzy avatar okrasavin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

tslint-origin-ordered-imports-rule's Issues

Missing peer dependency

Yarn 2 yields the following error:

โžค YN0002: โ”‚ tslint-origin-ordered-imports-rule@npm:1.2.1 doesn't provide typescript@>=2.1.0 || >=2.1.0-dev || >=2.2.0-dev || >=2.3.0-dev || >=2.4.0-dev || >=2.5.0-dev || >=2.6.0-dev || >=2.7.0-dev || >=2.8.0-dev || >=2.9.0-dev || >= 3.0.0-dev || >= 3.1.0-dev requested by tsutils@npm:2.29.0

See https://yarnpkg.com/advanced/error-codes#yn0002---missing_peer_dependency for description of the problem.

Could you add typescript as a peer-dependency?

multiple custom groups

Hi! First of all, thanks for a great tool.
It does help us a lot, but we need more complex grouping of internal imports - several block depending on path and filenames. Is it possible to provide an array or hash of customRules or achieve same behavior in another way?

Rule manage absolute imports of a custom path as a vendor import

First of all, thanks for your TSLint plugin, very useful.

I tried to order a custom path import after a relative import and the error appears, but it says "Import of node_modules must be higher than custom import".

Is possibile to manage custom path with a different rule? Or maybe, simply change the error message?
For example "Absolute import must be higher than relative import"

This plugin does not work

The rules seem to be completly ignored, even in the examples, maybe this used to work on older TS versions?

Rule to check that there is an extra line between node_modules and custom imports

Hi,

I've been using your package for more than half a year. Thanks for the work you do!

I am asking you to add an extra rule (possibly with false flag by default) that will check that there is an extra line between node_modules imports and our custom ones.

Example:

import { Router } from '@angular/router';
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';

import { FormTypes } from '../../local/enums/form-types.enum';

Keep order for custom groups

Hi! Thanks for the plugin!
But I'm not sure if it's desired behavior:
My rule:

    "origin-ordered-imports": [
      true,
      "no-blank-lines",
      [
        "^\\./",
        "^@/"
      ]
    ]

So I expect imports with prefix ./ go before imports with @/, but I can't see the warning in this case:

import { Module } from '@nestjs/common'
import { SomeModule } from '@/api/some.module'
import { PostController } from './post.controller'

I expect a warning that ./post.controller should go before @/api/some.module

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.