Install the package (either in ~
or in your project dir) using:
npm i -D git+https://github.com/Jelmerro/eslint-plugin-padding-lines.git
Add padding-lines
to your Eslint config:
{
"plugins": [
"padding-lines"
],
"rules": {
"padding-lines/objects": "error",
"padding-lines/statements": "error"
}
}
That's it!
(That is, if you don't want newlines anywhere, keep reading for configuration)
I wanted to also control padding newlines between arrow functions definitions, and to control the padding newlines between objects (which are not statements in Espree AST). This package merely combines these padding rules into one convenience package, as Eslint decided to close and reject any PR that improves stylistic rules.
This rule controls the padding between any statements.
Custom configuration of statements
is exactly the same as the padding-line-between-statements
Eslint rule,
for which you can find the documentation here.
The major difference is that this package supports arrow functions using arrow
,
while Eslint refused to add it as they have deprecated stylistic rules.
Since by default this rule disallows any padding newline, you probably want to configure it. Personally I like to use something like this to control the padding newlines:
{
"plugins": [
"padding-lines"
],
"rules": {
"padding-lines/objects": "error",
"padding-lines/statements": [
"error",
{
"blankLine": "never",
"next": "*",
"prev": "*"
},
{
"blankLine": "always",
"next": [
"var",
"let",
"const"
],
"prev": "directive"
},
{
"blankLine": "always",
"next": [
"var",
"let",
"const"
],
"prev": "arrow"
},
{
"blankLine": "always",
"next": "arrow",
"prev": "arrow"
},
{
"blankLine": "always",
"next": "arrow",
"prev": [
"var",
"let",
"const"
]
},
{
"blankLine": "any",
"next": "*",
"prev": [
"import",
"cjs-import"
]
},
{
"blankLine": "always",
"next": [
"export",
"cjs-export"
],
"prev": "*"
},
{
"blankLine": "always",
"next": [
"export",
"cjs-export"
],
"prev": [
"export",
"cjs-export"
]
}
]
}
}
Custom configuration of objects
can be set to either always
or never
,
by default set to never
, so you can choose to make it always with:
{
"rules": {
"padding-lines/objects": ["error", "always"]
}
}
Since Eslint have deprecated stylistic rules so this was rejected from addition.
This package is based on a lot of different sources and refined to work properly, all of which are licensed under the MIT license, as which I also pulish my modifications to it. For exact author information, please refer to the LICENSE. Special thanks to:
- DockYard for creating the object padding rule
- Bavly Abdelmasih for adding the arrow option to the existing rule
While their code has been rewritten to solve some code and stylistic issues, without them this package would probably not exist.