Skip to content

sbnc-eu/eslint-plugin-sbnc-rules

Repository files navigation

ESLint Plugin: SBNC Rules

This plugin includes some specialised ESLint rules.

The current version of the rules are based on the v8.13.0 version of ESLint and are tested to be compatible with ESLint v7 and v8.

Installation

You'll first need to install ESLint:

npm i eslint --save-dev

Next, install eslint-plugin-sbnc-rules:

npm install eslint-plugin-sbnc-rules --save-dev

Usage

Add sbnc-rules to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
    "plugins": [
        "sbnc-rules"
    ]
}

Then configure the rules you want to use under the rules section. Since these rules are a superset of the built in rules with the same names those need to be disabled for the replacements to work as intended.

{
    "rules": {
      
      "space-in-parens"           : "off",
      "sbnc-rules/space-in-parens": [ "error", "loose", { "exceptions": ["bracket unclosed"] } ],
      
      "padded-blocks"             : "off",
      "object-curly-newline"      : "off",
      "sbnc-rules/padded-blocks"  : [ "error", "loose", { "allowSingleLineBlocks": true, "noBottomPadding": true, "includeObjects": true } ]
      
    }
}

Supported Rules

This Plugin contains two rules. Each of these are an extended versions of the rules under the same name provided with ESLint. These rules should behave exactly the same as their original counterparts if the rule configuration is the same. However, they allow some additional configuration options to further fine-tune their behaviour.

For detailed information and examples about the rules refer to their respective documentation under the docs/rules folder:

space-in-parens

This rule provides extra options to control when spaces in parens should be used.

The first option has a new value loose. This means to only apply spaces around the brackets if there is more than one item in the bracket separated by space(s).

The second option allows new exceptions:

  • bracket lines defines an exception for parenthesis in lines that only contain brackets and whitespaces (on either side of the subject parenthesis)
  • bracket sides (deprecated) defines an exception for parenthesis when the inner side of the bracket only contain other brackets and whitespaces within the same line - note that the inner side continues after the closing pair of the parenthesis until the end of the line
  • bracket unclosed defines an exception for parenthesis when the inner side of the bracket only contain other brackets and whitespaces and the closing pair of the parenthesis is on another line
  • bracket within defines an exception for parenthesis when inside the bracket only contain other brackets and whitespaces within the same line - note that the inside ends where the closing parenthesis is found or where the line ends

padded-blocks

This rule provides extra options to control when padding lines in curly brace contained blocks should be used.

The first option has a new value loose. This means to only apply padding around the brackets if there is at least one empty (padding) line inside the block's body.

The second option allows a new setting:

  • noBottomPadding which can be used to avoid padding the bottom of blocks regardless of the first option's value
  • includeObjects which can be used to extend the padding behaviour to Objects

Additional info

The plugin scaffolding has been generated using yo and generator-eslint.


Bence Szalai - https://sbnc.eu/

For similar extended rules of the typescript-eslint rules check out my other plugin: eslint-plugin-sbnc-typescript-rules.