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 brace-style [extension] #810

Merged
merged 20 commits into from Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
85080ca
feat(eslint-plugin): add brace-style [extension]
a-tarasyuk Aug 6, 2019
2414b61
Merge branch 'master' into feature/brace-style
a-tarasyuk Aug 10, 2019
01013ee
Merge branch 'master' into feature/brace-style
a-tarasyuk Aug 14, 2019
e000806
Merge branch 'master' into feature/brace-style
a-tarasyuk Aug 15, 2019
1a0f860
Merge branch 'master' into feature/brace-style
a-tarasyuk Aug 19, 2019
55e69c9
Merge branch 'master' into feature/brace-style
a-tarasyuk Aug 19, 2019
27157be
Merge branch 'master' of https://github.com/typescript-eslint/typescr…
a-tarasyuk Aug 19, 2019
cb3e5e2
Merge branch 'master' into feature/brace-style
a-tarasyuk Aug 19, 2019
6eb1640
Merge branch 'master' into feature/brace-style
a-tarasyuk Aug 19, 2019
82a4ada
Merge branch 'master' of https://github.com/typescript-eslint/typescr…
a-tarasyuk Aug 20, 2019
44f523e
feat(eslint-plugin): check module/namespace brace style
a-tarasyuk Aug 20, 2019
ac6091c
Merge branch 'feature/brace-style' of https://github.com/a-tarasyuk/t…
a-tarasyuk Aug 20, 2019
f56e585
Merge branch 'master' into feature/brace-style
a-tarasyuk Aug 21, 2019
363eeda
Merge branch 'master' into feature/brace-style
a-tarasyuk Aug 27, 2019
475cfda
Merge branch 'master' into feature/brace-style
a-tarasyuk Aug 29, 2019
bfd236d
Merge branch 'master' into feature/brace-style
a-tarasyuk Sep 5, 2019
989409e
Merge branch 'master' of https://github.com/typescript-eslint/typescr…
a-tarasyuk Sep 6, 2019
e4890f2
feat(fix): fix eslint errors
a-tarasyuk Sep 6, 2019
cd391c2
Merge branch 'feature/brace-style' of https://github.com/a-tarasyuk/t…
a-tarasyuk Sep 6, 2019
112b1e4
Merge branch 'master' into feature/brace-style
bradzacher Sep 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
38 changes: 38 additions & 0 deletions packages/eslint-plugin/src/rules/brace-style.ts
@@ -0,0 +1,38 @@
import { 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);

return {
...rules,
TSInterfaceBody(node) {
return 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,
});
},
};
},
});
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