Skip to content

Commit f9e79a6

Browse files
committed
⭐️New: Add vue/brace-style rule
1 parent 9c49dcc commit f9e79a6

File tree

6 files changed

+104
-0
lines changed

6 files changed

+104
-0
lines changed

docs/rules/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ For example:
140140
| Rule ID | Description | |
141141
|:--------|:------------|:---|
142142
| [vue/array-bracket-spacing](./array-bracket-spacing.md) | enforce consistent spacing inside array brackets | :wrench: |
143+
| [vue/brace-style](./brace-style.md) | enforce consistent brace style for blocks | :wrench: |
143144
| [vue/component-name-in-template-casing](./component-name-in-template-casing.md) | enforce specific casing for the component naming style in template | :wrench: |
144145
| [vue/eqeqeq](./eqeqeq.md) | require the use of `===` and `!==` | :wrench: |
145146
| [vue/key-spacing](./key-spacing.md) | enforce consistent spacing between keys and values in object literal properties | :wrench: |

docs/rules/brace-style.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
pageClass: rule-details
3+
sidebarDepth: 0
4+
title: vue/brace-style
5+
description: enforce consistent brace style for blocks
6+
---
7+
# vue/brace-style
8+
> enforce consistent brace style for blocks
9+
10+
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
11+
12+
This rule is the same rule as core [brace-style] rule but it applies to the expressions in `<template>`.
13+
14+
## :books: Further reading
15+
16+
- [brace-style]
17+
18+
[brace-style]: https://eslint.org/docs/rules/brace-style
19+
20+
## :mag: Implementation
21+
22+
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/brace-style.js)
23+
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/brace-style.js)

lib/configs/no-layout-rules.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
module.exports = {
77
rules: {
88
'vue/array-bracket-spacing': 'off',
9+
'vue/brace-style': 'off',
910
'vue/html-closing-bracket-newline': 'off',
1011
'vue/html-closing-bracket-spacing': 'off',
1112
'vue/html-indent': 'off',

lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
'array-bracket-spacing': require('./rules/array-bracket-spacing'),
1111
'attribute-hyphenation': require('./rules/attribute-hyphenation'),
1212
'attributes-order': require('./rules/attributes-order'),
13+
'brace-style': require('./rules/brace-style'),
1314
'comment-directive': require('./rules/comment-directive'),
1415
'component-name-in-template-casing': require('./rules/component-name-in-template-casing'),
1516
'eqeqeq': require('./rules/eqeqeq'),

lib/rules/brace-style.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @author Yosuke Ota
3+
*/
4+
'use strict'
5+
6+
const { wrapCoreRule } = require('../utils')
7+
8+
// eslint-disable-next-line
9+
module.exports = wrapCoreRule(require('eslint/lib/rules/brace-style'))

tests/lib/rules/brace-style.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* @author Yosuke Ota
3+
*/
4+
'use strict'
5+
6+
const RuleTester = require('eslint').RuleTester
7+
const rule = require('../../../lib/rules/brace-style')
8+
9+
const tester = new RuleTester({
10+
parser: 'vue-eslint-parser',
11+
parserOptions: { ecmaVersion: 2015 }
12+
})
13+
14+
tester.run('brace-style', rule, {
15+
valid: [
16+
`<template><div :attr="function foo() {
17+
return true;
18+
}" /></template>`,
19+
{
20+
code: `<template><div :attr="function foo() { return true; }" /></template>`,
21+
options: ['1tbs', { 'allowSingleLine': true }]
22+
}
23+
],
24+
invalid: [
25+
{
26+
code: `
27+
<template>
28+
<div :attr="function foo()
29+
{
30+
return true;
31+
}" />
32+
</template>`,
33+
output: `
34+
<template>
35+
<div :attr="function foo() {
36+
return true;
37+
}" />
38+
</template>`,
39+
errors: [
40+
{
41+
message: 'Opening curly brace does not appear on the same line as controlling statement.',
42+
line: 4
43+
}
44+
]
45+
},
46+
{
47+
code: `
48+
<template>
49+
<div :attr="function foo() { return true; }" />
50+
</template>`,
51+
output: `
52+
<template>
53+
<div :attr="function foo() {
54+
return true;\u{20}
55+
}" />
56+
</template>`,
57+
errors: [
58+
{
59+
message: 'Statement inside of curly braces should be on next line.',
60+
line: 3
61+
},
62+
{
63+
message: 'Closing curly brace should be on the same line as opening curly brace or on the line after the previous block.',
64+
line: 3
65+
}
66+
]
67+
}
68+
]
69+
})

0 commit comments

Comments
 (0)