Giter VIP home page Giter VIP logo

Comments (12)

lydell avatar lydell commented on May 21, 2024 20

@keemor Hi!

You need to put everything in the same array, like this:

{
  "plugins": ["simple-import-sort"],
  "extends": "react-app",
  "rules": {
    "simple-import-sort/sort": [
      "warn",
      {
        "groups": [
          [
            // Packages. `react` related packages come first.
            "^react",
            "^@?\\w",
            // Internal packages.
            "^(components|modules|utils)(/.*|$)",
            // Side effect imports.
            "^\\u0000",
            // Parent imports. Put `..` last.
            "^\\.\\.(?!/?$)", "^\\.\\./?$",
            // Other relative imports. Put same-folder imports and `.` last.
            "^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$",
            // Style imports.
            "^.+\\.s?css$"
          ]
        ]
      }
    ],
    "import/first": "warn",
    "import/newline-after-import": "warn",
    "import/no-duplicates": "warn",
  }
}

(I didn’t test that before posting, so forgive me if I made a mistake 🙏)

from eslint-plugin-simple-import-sort.

lydell avatar lydell commented on May 21, 2024 18

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

For example:

{
  "rules": {
    "simple-import-sort/imports": [
      "error",
      {
        "groups": [["^\\u0000", "^@?\\w", "^[^.]", "^\\."]]
      }
    ]
  }
}

(Edited for newer version based on #25 (comment))

from eslint-plugin-simple-import-sort.

ymkz avatar ymkz commented on May 21, 2024 3

Thanks for the reply. OK, I undetstand plugin design.

I want to remove line breaks between all import statements. This is my personal opinion because I usually don't put a newline between import statements. So, not important. But I would be happy if option was provided like https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md#newlines-between-ignorealwaysalways-and-inside-groupsnever.

Thank you for your polite response!

from eslint-plugin-simple-import-sort.

hrougier avatar hrougier commented on May 21, 2024 2

Hi,

Having this option would be nice for people using typescript.

Migrating from tslint to eslint, this plugin is the only one that can behave like tslint ordered-imports rule... except that tslint default rule configuration disables new line between groups.

Would be great to be able to have the same configuration as tslint.

from eslint-plugin-simple-import-sort.

huzaifa-99 avatar huzaifa-99 commented on May 21, 2024 2

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

For example:

{
  "rules": {
    "simple-import-sort/sort": [
      "error",
      {
        "groups": [["^\\u0000", "^@?\\w", "^[^.]", "^\\."]]
      }
    ]
  }
}

Just to expand on this.

For future visitors, "simple-import-sort/sort" will give error (above v6.0.0)

  • Definition for rule 'simple-import-sort/sort' was not found.eslint(simple-import-sort/sort)

Replace the "simple-import-sort/sort" with "simple-import-sort/imports", like this

"simple-import-sort/imports": [
      "error",
      {
        "groups": [["^\\u0000", "^@?\\w", "^[^.]", "^\\."]]
      }
]

It's also mentioned in the readme here.

Thanks.

from eslint-plugin-simple-import-sort.

lydell avatar lydell commented on May 21, 2024 1

I have a thing coming up that will allow customizing this.

from eslint-plugin-simple-import-sort.

santomegonzalo avatar santomegonzalo commented on May 21, 2024 1

This feature of grouping is great but will be nice to make an example on the documentation because it was clear only after searching newline

from eslint-plugin-simple-import-sort.

lydell avatar lydell commented on May 21, 2024

Hi!

This plugin has no options by design. There is currently no way of removing that newline.

Would you like to tell me more about this unwanted line break? Do you want no linebreaks at all between imports? Or just between those two groups that you showed? Why is it important? Etc.

from eslint-plugin-simple-import-sort.

lydell avatar lydell commented on May 21, 2024

@hrougier https://palantir.github.io/tslint/rules/ordered-imports/

Groups of imports are delineated by blank lines.

But you say the default is having no blank lines between groups?

from eslint-plugin-simple-import-sort.

hrougier avatar hrougier commented on May 21, 2024

But you say the default is having no blank lines between groups?

That's it, blank lines between groups is an option which is not enabled by default:

"rules": {
    "ordered-imports": true // rule activated, no blank lines
  }
"rules": {
    "ordered-imports": [true, { "grouped-imports": true }] // to enable blank lines
  }

from eslint-plugin-simple-import-sort.

lydell avatar lydell commented on May 21, 2024

Ok. I guess their docs is a little misleading, then. I have an idea for this that I want to play with this week.

from eslint-plugin-simple-import-sort.

keemor avatar keemor commented on May 21, 2024

Hi @santomegonzalo, @lydell :)
How to remove empty lines between groups? My .eslint looks like this:

{
  "plugins": ["simple-import-sort"],
  "extends": "react-app",
  "rules": {
    "simple-import-sort/sort": [
      "warn",
      {
        "groups": [
          // Packages. `react` related packages come first.
          ["^react", "^@?\\w"],
          // Internal packages.
          ["^(components|modules|utils)(/.*|$)"],
          // Side effect imports.
          ["^\\u0000"],
          // Parent imports. Put `..` last.
          ["^\\.\\.(?!/?$)", "^\\.\\./?$"],
          // Other relative imports. Put same-folder imports and `.` last.
          ["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"],
          // Style imports.
          ["^.+\\.s?css$"]
        ]
      }
    ],
    "import/first": "warn",
    "import/newline-after-import": "warn",
    "import/no-duplicates": "warn",
  }
}

from eslint-plugin-simple-import-sort.

Related Issues (20)

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.