Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] special match type for side-effect imports #22

Open
quezak opened this issue Jan 31, 2019 · 2 comments
Open

[feature request] special match type for side-effect imports #22

quezak opened this issue Jan 31, 2019 · 2 comments
Labels
feature-request Feature requests

Comments

@quezak
Copy link

quezak commented Jan 31, 2019

I'd like to enforce side-effect-only imports to be in a separate import group at the top of the file -- the ones without the from keyword, e.g. import 'reflect-metadata' or import 'tsconfig-paths/register'.

Typescript Import Sorter, the vscode plugin that I use for sorting imports, allows to do this through a type: 'importMember' param (though the name is not really descriptive for me, but it's explained below).

Maybe would it be possible to add such a matching type to your linter rule too?

@Gelio
Copy link
Owner

Gelio commented Feb 2, 2019

It seems to be doable. Here is a snippet that describes differences between different syntaxes for imports declarations: https://astexplorer.net/#/gist/adb7b38f4ffe0b54727c16ce654f0285/latest

I can add a new configuration option for each matching-rule that would specify the type of import declarations that it matches, which would be one of the four in the snippet above. That could overly complicate the configuration, so I reckon just having side-effect-imports-only: true would be enough. A matching rule that would match all the side effect imports would look as follows:

{
  "type": "project",
  "matches": ".*",
  "imports-group": "side effects",
  "side-effect-imports-only": true
}

@quezak Do you think that would suffice?

@Gelio Gelio added the feature-request Feature requests label Feb 2, 2019
@quezak
Copy link
Author

quezak commented Feb 2, 2019

Looks great, thanks for looking into this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Feature requests
Projects
None yet
Development

No branches or pull requests

2 participants