Eslint-plugin-import: Is there any way around having no-multiple-empty-lines and newline-after-import together?

Created on 11 Feb 2020  路  6Comments  路  Source: benmosher/eslint-plugin-import

I'd like to have 2 spaces between imports, but for the rest of my sources, only allow a max of 1.

        "import/newline-after-import": [
            "error",
            {
                count: 2,
            },
        ],
        "no-multiple-empty-lines": [
            "error",
            {
                max: 1,
            }
        ],

Unfortunately these get in a bit of a scuffle 馃槅

question

Most helpful comment

this is not an issue with rule itself but rather with your configuration no-multiple-empty-lines is configured in this case to allow only 1 line between statements but you are enforcing 2 empty lines after import, rules does not know about other rules (they are isolated) as they should be.

both of those conditions can't be valid at same time


{
  "import/newline-after-import": ["error", { "count": 2 }],
  "no-multiple-empty-lines": ["error", { "max": 2 }]
}

or

{
  "import/newline-after-import": ["error", { "count": 1 }],
  "no-multiple-empty-lines": ["error", { "max": 1 }]
}

All 6 comments

Can you explain a bit more? What's the code you currently want to be valid, and where does an error appear with various configs of these two rules?

this is not an issue with rule itself but rather with your configuration no-multiple-empty-lines is configured in this case to allow only 1 line between statements but you are enforcing 2 empty lines after import, rules does not know about other rules (they are isolated) as they should be.

both of those conditions can't be valid at same time


{
  "import/newline-after-import": ["error", { "count": 2 }],
  "no-multiple-empty-lines": ["error", { "max": 2 }]
}

or

{
  "import/newline-after-import": ["error", { "count": 1 }],
  "no-multiple-empty-lines": ["error", { "max": 1 }]
}

Obviously. The question is how to configure ESLint so that only 1 empty line is allowed between everything except for certain cases.

I like the Python way: 2 newlines between classes, function, declarations, blocks of constant definitions, and blocks of imports, but at most 1 everywhere else.

I don't believe eslint rules exist that can permit that. I think you'd need to write your own rule; that style is highly unidiomatic for JS.

highly unidiomatic

Hahaha it鈥檚 just empty lines. I don鈥檛 think I鈥檝e ever seen a strong opinion about those before now.

The existence of this rule is because many folks have strong opinions about never having more than 1 empty line in a row :-)

Was this page helpful?
0 / 5 - 0 ratings