Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

[feat] added ter-padding-line-between-statements rule (closes #361) #371

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ These rules are purely matters of style and are quite subjective.
|:x:|[operator-assignment](http://eslint.org/docs/rules/operator-assignment)|operator-assignment|require assignment operator shorthand where possible or prohibit it entirely|
|:x:|[operator-linebreak](http://eslint.org/docs/rules/operator-linebreak)|operator-linebreak|enforce operators to be placed before or after line breaks|
|:white_check_mark:|[padded-blocks](http://eslint.org/docs/rules/padded-blocks)|[ter-padded-blocks](https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/terPaddedBlocksRule.md)|enforce padding within blocks|
|:white_check_mark:|[padding-line-between-statements](https://eslint.org/docs/rules/padding-line-between-statements)|[ter-padding-line-between-statements](https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/terPaddingLineBetweenStatementsRule.md)|Require or disallow padding lines between statements |
|:ballot_box_with_check:|[quote-props](http://eslint.org/docs/rules/quote-props)|[object-literal-key-quotes](https://palantir.github.io/tslint/rules/object-literal-key-quotes)|require quotes around object literal property names|
|:ballot_box_with_check:|[quotes](http://eslint.org/docs/rules/quotes)|[quotemark](http://palantir.github.io/tslint/rules/quotemark/)|specify whether backticks, double or single quotes should be used|
|:x:|[require-jsdoc](http://eslint.org/docs/rules/require-jsdoc)|require-jsdoc|Require JSDoc comment|
Expand Down
160 changes: 160 additions & 0 deletions src/docs/rules/terPaddingLineBetweenStatementsRule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<!-- Start:AutoDoc:: Modify `src/readme/rules.ts` and run `gulp readme` to update block -->
## ter-padding-line-between-statements (ESLint: [padding-line-between-statements](https://eslint.org/docs/rules/padding-line-between-statements))
[![rule_source](https://img.shields.io/badge/%F0%9F%93%8F%20rule-source-green.svg)](https://github.com/buzinas/tslint-eslint-rules/blob/master/src/rules/terPaddingLineBetweenStatementsRule.ts)
[![test_source](https://img.shields.io/badge/%F0%9F%93%98%20test-source-blue.svg)](https://github.com/buzinas/tslint-eslint-rules/blob/master/src/test/rules/terPaddingLineBetweenStatementsRuleTests.ts)

Require or disallow padding lines between statements

#### Rationale

This rule requires or disallows blank lines between the given 2 kinds of statements.
Properly blank lines help developers to understand the code.

### Config

This rule does nothing if no configurations are provided.
A configuration is an object which has 3 properties; `blankLine`, `prev` and `next`.

`prev` and `next` specify the type of statements between which to check for blank lines.
They can be one of the following, or an array of the following.

- `"*"` is a wildcard that matches any statement.
- `"block"`
- `"block-like"`
- `"break"`
- `"case"`
- `"class"`
- `"const"`
- `"continue"`
- `"debugger"`
- `"default"`
- `"do"`
- `"empty"`
- `"enum"`
- `"export"`
- `"expression"`
- `"for"`
- `"function"`
- `"if"`
- `"import"`
- `"interface"`
- `"let"`
- `"return"`
- `"switch"`
- `"throw"`
- `"try"`
- `"var"`
- `"while"`
- `"with"`

`blankLine` can be one of `"always"`, `"never"` or `"any"`

- `"always"` requires one or more blank lines between the statement pair.
- `"never"` disallows blank lines between the statement pair.
- `"any"` just ignores the statement pair.

If a statement pair matches multiple configurations, the last matched configuration will be used.

#### Examples

```json
"ter-padding-line-between-statements": [
true,
{ "blankLine": "always", "prev": "interface", "next": "*" },
{ "blankLine": "always", "prev": "*", "next": "interface" }
]
```

```json
"ter-padding-line-between-statements": [
true,
{ "blankLine": "never", "prev": ["var", "let", "const"], "next": ["var", "let", "const"] }
]
```
#### Schema

```json
{
"type": "array",
"items": [
{
"type": "object",
"properties": {
"blankLine": {
"enum": [
"always",
"never",
"any"
]
},
"prev": {
"enum": [
"*",
"block",
"block-like",
"break",
"case",
"class",
"const",
"continue",
"debugger",
"default",
"do",
"empty",
"enum",
"export",
"expression",
"for",
"function",
"if",
"import",
"interface",
"let",
"return",
"switch",
"throw",
"try",
"var",
"while",
"with"
]
},
"next": {
"enum": [
"*",
"block",
"block-like",
"break",
"case",
"class",
"const",
"continue",
"debugger",
"default",
"do",
"empty",
"enum",
"export",
"expression",
"for",
"function",
"if",
"import",
"interface",
"let",
"return",
"switch",
"throw",
"try",
"var",
"while",
"with"
]
}
},
"additionalProperties": false
}
]
}
```
<!-- End:AutoDoc -->
16 changes: 16 additions & 0 deletions src/readme/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2484,6 +2484,22 @@ const rules: IRule[] = [
]
~~~`
},
{
available: true,
eslintRule: 'padding-line-between-statements',
tslintRule: 'ter-padding-line-between-statements',
category: 'Stylistic Issues',
description: 'Require or disallow padding lines between statements ',
eslintUrl: 'https://eslint.org/docs/rules/padding-line-between-statements',
provider: 'tslint-eslint-rules',
usage: `~~~json
"ter-padding-line-between-statements": [
true,
{ "blankLine": "always", "prev": ["interface", "enum"], "next": "*" },
{ "blankLine": "always", "prev": "*", "next": ["interface", "enum"] }
]
~~~`
},
{
available: true,
eslintRule: 'quote-props',
Expand Down
Loading