lydell / eslint-plugin-simple-import-sort

Easy autofixable import sorting.
MIT License
2.13k stars 71 forks source link

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

Closed lveillard closed 2 years ago

lveillard commented 2 years ago

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 commented 2 years ago

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: https://github.com/lydell/eslint-plugin-simple-import-sort/issues/31#issuecomment-939271796

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: https://github.com/lydell/eslint-plugin-simple-import-sort/issues/31#issuecomment-654152415

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 commented 2 years ago

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

lveillard commented 2 years ago

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 👌