question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to remove newline between import groups?

See original GitHub issue

Thanks for nice plugin!

I tried to use this and had one question. How to remove newline between import groups? (Or is there no option to remove line breaks?)

import fetch from 'cross-fetch'
import { NextPage } from 'next'
import Link from 'next/link'
import React from 'react'

// I want to delete ↑ line...
import { Head } from '~/components/abstracts/head'

The config file used is shown below.

My ESLint config

{
  "root": true,
  "env": {
    "es6": true,
    "node": true,
    "browser": true
  },
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaFeatures": { "jsx": true },
    "sourceType": "module"
  },
  "plugins": [
    "react",
    "import",
    "unicorn",
    "security",
    "prettier",
    "react-hooks",
    "simple-import-sort",
    "@typescript-eslint"
  ],
  "extends": [
    "eslint:recommended",
    "plugin:import/errors",
    "plugin:import/warnings",
    "plugin:import/typescript",
    "plugin:react/recommended",
    "plugin:unicorn/recommended",
    "plugin:security/recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:prettier/recommended",
    "prettier/@typescript-eslint",
    "prettier/unicorn",
    "prettier/react"
  ],
  "rules": {
    "prefer-const": "error",
    "react/prop-types": "off",
    "simple-import-sort/sort": "error",
    "react-hooks/rules-of-hooks": "error",
    "react-hooks/exhaustive-deps": "warn",
    "import/newline-after-import": "error",
    "unicorn/prevent-abbreviations": "off",
    "unicorn/consistent-function-scoping": "off",
    "@typescript-eslint/ban-ts-ignore": "off",
    "@typescript-eslint/explicit-function-return-type": "off",
    "@typescript-eslint/explicit-member-accessibility": "off",
    "@typescript-eslint/consistent-type-definitions": ["error", "type"]
  },
  "settings": {
    "react": {
      "version": "detect"
    },
    "import/resolver": {
      "babel-module": {}
    },
    "import/parsers": {
      "@typescript-eslint/parser": [".ts", ".tsx"]
    }
  }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

11reactions
lydellcommented, May 7, 2020

@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 🙏)

10reactions
lydellcommented, Jul 3, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Formatting empty line between third party imports and other ...
Using the following eslint rule works: { "import/order": [ "error", { groups: [ ["builtin", "external"] ], "newlines-between": "always" } ...
Read more >
How to remove carriage returns (line breaks) from cells in Excel
Select one or more cells where you want to delete line breaks. On your Excel ribbon, go to the Ablebits Data tab >...
Read more >
re — Regular expression operations — Python 3.11.1 ...
The solution is to use Python's raw string notation for regular expression patterns; backslashes are not handled in any special way in a...
Read more >
New line character for Descriptive fields in CSV Import
I am using Atom 2.0 instance and using the command line interface to perform the imports. We tried using the pipe "|" character...
Read more >
Set hyphenation and line breaks in Illustrator - Adobe Support
You can prevent words from breaking at the end of lines—for example, proper names or words that could be misread when hyphenated. You...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found