Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eslint-plugin): add brace-style [extension] (#810)
- Loading branch information
1 parent
e9fcf70
commit e01dc5f
Showing
8 changed files
with
1,213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.