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

Considering internal files as external libs when using "baseUrl": "./src" on tsconfig #106

Closed
lveillard opened this issue Apr 27, 2022 · 3 comments

Comments

@lveillard
Copy link

lveillard commented Apr 27, 2022

Hello!
I'm using
"baseUrl": "./src", in my tsconfig file in order to import my modules without the annoying ../...... things

However this makes some weird sorting like these:

import { Meta } from 'layout';
import { Designer } from 'layout/desginer/Designer';
import { Main } from 'Main';
import { UserMiddleware } from 'middleware';
import { NextPage } from 'next';
import React from 'react';

where all nut the two last ones are internal libs
Is there a way to fix this? thanks!

btw in case it helps, this eslintr config works properly:

  "import/order": [
          "error",
          {
            "groups": ["builtin", "external", "internal"],
            "pathGroups": [
              {
                "pattern": "react",
                "group": "external",
                "position": "before"
              }
            ],
            "pathGroupsExcludedImportTypes": ["react"],
            "newlines-between": "always",
            "alphabetize": {
              "order": "asc",
              "caseInsensitive": true
            }
          }
        ],
        ```
@lydell
Copy link
Owner

lydell commented Apr 27, 2022

Hi!

Regarding tsconfig.json: I thought a lot about adding automatic support for paths and baseUrl in there, but came to the conclusion that it’s complexity I don’t need myself so I don’t want to maintain it: #31 (comment)

This section in the docs is interesting as well: https://github.com/lydell/eslint-plugin-simple-import-sort#custom-grouping

If you’re looking at custom grouping because you want to move src/Button, @company/Button and similar – also consider using names that do not look like npm packages, such as @/Button and ~company/Button. Then you won’t need to customize the grouping at all, and as a bonus things might be less confusing for other people working on the code base.

Otherwise you’ll basically need to duplicate your baseUrl config in this plugin’s options, and possibly use fs.readdirSync: #31 (comment)

Finally, if you already have a working import/order setup, just out of curiosity I’m interested in why you’re looking into switching to this plugin?

@lydell
Copy link
Owner

lydell commented May 10, 2022

Closing because I don’t think there’s anything I’d like to change, and there was no response to the import/order question.

@lydell lydell closed this as completed May 10, 2022
@lveillard
Copy link
Author

Because im using this boilerplate:
https://github.com/ixartz/Next-js-Boilerplate

They removed the import/order config and added this package. I check it from time to time and i do as they do because they tend to take rigth decisions for DX.

But in this case i have my custom baseurl so it does not work properly.

I reverted it and kept using my config, but wanted to share it with you and add the config, in case you wanted to make it compatible for those cases also.

But i totally understand your decision, and the package is a quick win for everyone not modifying the baseurl which is 99% of the people 👌

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