Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(eslint-plugin): add brace-style [extension] (#810)
  • Loading branch information
a-tarasyuk authored and bradzacher committed Sep 6, 2019
1 parent e9fcf70 commit e01dc5f
Show file tree
Hide file tree
Showing 8 changed files with 1,213 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/eslint-plugin/README.md
Expand Up @@ -145,6 +145,7 @@ Then you should add `airbnb` (or `airbnb-base`) to your `extends` section of `.e
| [`@typescript-eslint/await-thenable`](./docs/rules/await-thenable.md) | Disallows awaiting a value that is not a Thenable | :heavy_check_mark: | | :thought_balloon: |
| [`@typescript-eslint/ban-ts-ignore`](./docs/rules/ban-ts-ignore.md) | Bans “// @ts-ignore” comments from being used | :heavy_check_mark: | | |
| [`@typescript-eslint/ban-types`](./docs/rules/ban-types.md) | Bans specific types from being used | :heavy_check_mark: | :wrench: | |
| [`@typescript-eslint/brace-style`](./docs/rules/brace-style.md) | Enforce consistent brace style for blocks | | :wrench: | |
| [`@typescript-eslint/camelcase`](./docs/rules/camelcase.md) | Enforce camelCase naming convention | :heavy_check_mark: | | |
| [`@typescript-eslint/class-name-casing`](./docs/rules/class-name-casing.md) | Require PascalCased class and interface names | :heavy_check_mark: | | |
| [`@typescript-eslint/consistent-type-assertions`](./docs/rules/consistent-type-assertions.md) | Enforces consistent usage of type assertions. | :heavy_check_mark: | | |
Expand Down
22 changes: 22 additions & 0 deletions packages/eslint-plugin/docs/rules/brace-style.md
@@ -0,0 +1,22 @@
# Enforce consistent brace style for blocks

## Rule Details

This rule extends the base [eslint/brace-style](https://eslint.org/docs/rules/brace-style) rule.
It supports all options and features of the base rule.

## How to use

```cjson
{
// note you must disable the base rule as it can report incorrect errors
"brace-style": "off",
"@typescript-eslint/brace-style": ["error"]
}
```

## Options

See [eslint/brace-style options](https://eslint.org/docs/rules/brace-style#options).

<sup>Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/master/docs/rules/brace-style.md)</sup>
2 changes: 2 additions & 0 deletions packages/eslint-plugin/src/configs/all.json
Expand Up @@ -6,6 +6,8 @@
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-ignore": "error",
"@typescript-eslint/ban-types": "error",
"brace-style": "off",
"@typescript-eslint/brace-style": "error",
"camelcase": "off",
"@typescript-eslint/camelcase": "error",
"@typescript-eslint/class-name-casing": "error",
Expand Down
45 changes: 45 additions & 0 deletions packages/eslint-plugin/src/rules/brace-style.ts
@@ -0,0 +1,45 @@
import {
TSESTree,
AST_NODE_TYPES,
} from '@typescript-eslint/experimental-utils';
import baseRule from 'eslint/lib/rules/brace-style';
import * as util from '../util';

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

export default util.createRule<Options, MessageIds>({
name: 'brace-style',
meta: {
type: 'layout',
docs: {
description: 'Enforce consistent brace style for blocks',
category: 'Stylistic Issues',
recommended: false,
},
messages: baseRule.meta.messages,
fixable: baseRule.meta.fixable,
schema: baseRule.meta.schema,
},
defaultOptions: ['1tbs'],
create(context) {
const rules = baseRule.create(context);
const checkBlockStatement = (
node: TSESTree.TSModuleBlock | TSESTree.TSInterfaceBody,
): void => {
rules.BlockStatement({
type: AST_NODE_TYPES.BlockStatement,
parent: node.parent,
range: node.range,
body: node.body as any, // eslint-disable-line @typescript-eslint/no-explicit-any
loc: node.loc,
});
};

return {
...rules,
TSInterfaceBody: checkBlockStatement,
TSModuleBlock: checkBlockStatement,
};
},
});
2 changes: 2 additions & 0 deletions packages/eslint-plugin/src/rules/index.ts
Expand Up @@ -3,6 +3,7 @@ import arrayType from './array-type';
import awaitThenable from './await-thenable';
import banTsIgnore from './ban-ts-ignore';
import banTypes from './ban-types';
import braceStyle from './brace-style';
import camelcase from './camelcase';
import classNameCasing from './class-name-casing';
import consistentTypeAssertions from './consistent-type-assertions';
Expand Down Expand Up @@ -67,6 +68,7 @@ export default {
'await-thenable': awaitThenable,
'ban-ts-ignore': banTsIgnore,
'ban-types': banTypes,
'brace-style': braceStyle,
camelcase: camelcase,
'class-name-casing': classNameCasing,
'consistent-type-assertions': consistentTypeAssertions,
Expand Down

0 comments on commit e01dc5f

Please sign in to comment.