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

Handle custom groups #24

Closed
theKashey opened this issue Sep 12, 2019 · 5 comments
Closed

Handle custom groups #24

theKashey opened this issue Sep 12, 2019 · 5 comments

Comments

@theKashey
Copy link

Nowadays, absolute imports is a very popular thing, as well as monorepos with different features "stored" as a separate packages. However they are not packages.

Webpack aliases and yarn workspaces are breaking original idea behind the "groups" feature.

import React from 'react';              // 1. "external" package
import Button from 'components/Button'; // 2. "internal" package (or just an absolute URL)
import style from './style';            // 3. "relative" module
import "./messages";                    // 4. side effect

Technically these are:

  1. packages in node_modules
  2. packages not in node_modules
  3. relative path
  4. no import
  • 2 could be distinguished from 1 by calling require.resolve and checking path to include node_modules (obvious)
  • 2 could be distinguished from 1 by having some configuration rules, but I reckon it's not feature proof and quite fragile.

I could work on PR if you'll accept the idea

@lydell
Copy link
Owner

lydell commented Sep 12, 2019

Hi! Have you seen the discussion in #18? To me, this issue feels like a duplicate of #18.

@theKashey
Copy link
Author

Yep. Sounds like a duplicate.
From another perspective - it sounds like a possible ease solution for the problem, as long as "real" npm packages would be resolved into real paths, while "absolute" paths would not. In other words - you don't have to do much to get it supported.

@lydell
Copy link
Owner

lydell commented Sep 12, 2019

I’m not sure what you mean – what is your possible solution idea more in detail?

(I’m closing the issue since it is a duplicate, but feel free to answer here or in the other one.)

@lydell lydell closed this as completed Sep 12, 2019
@theKashey
Copy link
Author

  • get the module name
  • if it seems to me a "package" (or absolute)
  • call require.resolve.
  • if call was _unsuccessful, or does not contain node_modules(but I think it would be the first case) - it is an absolute import. Only the "real packages" would be resolved.

Thus the problem could be solved without any configuration needed from a user.

@lydell
Copy link
Owner

lydell commented Nov 22, 2019

This is now possible in v5.0.0 using
custom grouping.

For example:

{
  "rules": {
    "simple-import-sort/sort": [
      "error",
      {
        "groups": [["^\\u0000"], ["^@?\\w"], ["^components(/.*|$)"], ["^\\."]]
      }
    ]
  }
}

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

No branches or pull requests

2 participants