Skip to content

All the Eslint newline padding rules in one plugin

License

Notifications You must be signed in to change notification settings

Jelmerro/eslint-plugin-padding-lines

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eslint-plugin-padding-lines

All the Eslint newline padding rules in one plugin

Installation

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)

Why

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.

padding-lines/statements

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"
                ]
            }
        ]
    }
}

padding-lines/objects

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.

LICENSE

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:

While their code has been rewritten to solve some code and stylistic issues, without them this package would probably not exist.

About

All the Eslint newline padding rules in one plugin

Topics

Resources

License

Stars

Watchers

Forks