Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eslint-plugin): add extension rule padding-line-between-statements #3418

Merged
75 changes: 38 additions & 37 deletions packages/eslint-plugin/README.md

Large diffs are not rendered by default.

@@ -0,0 +1,28 @@
# require or disallow padding lines between statements (`padding-line-between-statements`)

## Rule Details

This rule extends the base [`eslint/padding-line-between-statements`](https://eslint.org/docs/rules/padding-line-between-statements) rule.
yasarsid marked this conversation as resolved.
Show resolved Hide resolved

## How to use

```jsonc
{
// note you must disable the base rule as it can report incorrect errors
"padding-line-between-statements": "off",
"@typescript-eslint/padding-line-between-statements": [
"error",
{
"blankLine": "always",
"prev": "var",
"next": "return"
}
]
}
```

## Options

See [`eslint/padding-line-between-statements` options](https://eslint.org/docs/rules/padding-line-between-statements#options).
yasarsid marked this conversation as resolved.
Show resolved Hide resolved

<sup>Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/master/docs/rules/padding-line-between-statements.md)</sup>
2 changes: 2 additions & 0 deletions packages/eslint-plugin/src/configs/all.ts
Expand Up @@ -116,6 +116,8 @@ export = {
'@typescript-eslint/non-nullable-type-assertion-style': 'error',
'object-curly-spacing': 'off',
'@typescript-eslint/object-curly-spacing': 'error',
'padding-line-between-statements': 'off',
'@typescript-eslint/padding-line-between-statements': 'error',
'@typescript-eslint/prefer-as-const': 'error',
'@typescript-eslint/prefer-enum-initializers': 'error',
'@typescript-eslint/prefer-for-of': 'error',
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-plugin/src/rules/index.ts
Expand Up @@ -81,6 +81,7 @@ import noUselessConstructor from './no-useless-constructor';
import noVarRequires from './no-var-requires';
import nonNullableTypeAssertionStyle from './non-nullable-type-assertion-style';
import objectCurlySpacing from './object-curly-spacing';
import paddingLineBetweenStatements from './padding-line-between-statements';
import preferAsConst from './prefer-as-const';
import preferEnumInitializers from './prefer-enum-initializers';
import preferForOf from './prefer-for-of';
Expand Down Expand Up @@ -199,6 +200,7 @@ export default {
'no-var-requires': noVarRequires,
'non-nullable-type-assertion-style': nonNullableTypeAssertionStyle,
'object-curly-spacing': objectCurlySpacing,
'padding-line-between-statements': paddingLineBetweenStatements,
'prefer-as-const': preferAsConst,
'prefer-enum-initializers': preferEnumInitializers,
'prefer-for-of': preferForOf,
Expand Down
@@ -0,0 +1,35 @@
import baseRule from 'eslint/lib/rules/padding-line-between-statements';
import {
InferOptionsTypeFromRule,
InferMessageIdsTypeFromRule,
createRule,
} from '../util';

export type Options = InferOptionsTypeFromRule<typeof baseRule>;
export type MessageIds = InferMessageIdsTypeFromRule<typeof baseRule>;

export default createRule<Options, MessageIds>({
name: 'padding-line-between-statements',
meta: {
type: 'layout',
docs: {
description: 'require or disallow padding lines between statements',
category: 'Stylistic Issues',
recommended: false,
extendsBaseRule: true,
},
fixable: 'whitespace',
schema: baseRule.meta.schema,
messages: {
unexpectedBlankLine: 'Unexpected blank line before this statement.',
expectedBlankLine: 'Expected blank line before this statement',
},
},
defaultOptions: [{ blankLine: 'any', prev: '*', next: '*' }],
create(context) {
const rules = baseRule.create(context);
return {
...rules,
};
},
yasarsid marked this conversation as resolved.
Show resolved Hide resolved
});