Skip to content

⭐️New: Add vue/brace-style rule #771

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

Merged
merged 3 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ For example:
| [vue/array-bracket-spacing](./array-bracket-spacing.md) | enforce consistent spacing inside array brackets | :wrench: |
| [vue/arrow-spacing](./arrow-spacing.md) | enforce consistent spacing before and after the arrow in arrow functions | :wrench: |
| [vue/block-spacing](./block-spacing.md) | disallow or enforce spaces inside of blocks after opening block and before closing block | :wrench: |
| [vue/brace-style](./brace-style.md) | enforce consistent brace style for blocks | :wrench: |
| [vue/component-name-in-template-casing](./component-name-in-template-casing.md) | enforce specific casing for the component naming style in template | :wrench: |
| [vue/eqeqeq](./eqeqeq.md) | require the use of `===` and `!==` | :wrench: |
| [vue/key-spacing](./key-spacing.md) | enforce consistent spacing between keys and values in object literal properties | :wrench: |
Expand Down
23 changes: 23 additions & 0 deletions docs/rules/brace-style.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
pageClass: rule-details
sidebarDepth: 0
title: vue/brace-style
description: enforce consistent brace style for blocks
---
# vue/brace-style
> enforce consistent brace style for blocks

- :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.

This rule is the same rule as core [brace-style] rule but it applies to the expressions in `<template>`.

## :books: Further reading

- [brace-style]

[brace-style]: https://eslint.org/docs/rules/brace-style

## :mag: Implementation

- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/brace-style.js)
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/brace-style.js)
1 change: 1 addition & 0 deletions lib/configs/no-layout-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
'vue/array-bracket-spacing': 'off',
'vue/arrow-spacing': 'off',
'vue/block-spacing': 'off',
'vue/brace-style': 'off',
'vue/html-closing-bracket-newline': 'off',
'vue/html-closing-bracket-spacing': 'off',
'vue/html-indent': 'off',
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
'attribute-hyphenation': require('./rules/attribute-hyphenation'),
'attributes-order': require('./rules/attributes-order'),
'block-spacing': require('./rules/block-spacing'),
'brace-style': require('./rules/brace-style'),
'comment-directive': require('./rules/comment-directive'),
'component-name-in-template-casing': require('./rules/component-name-in-template-casing'),
'eqeqeq': require('./rules/eqeqeq'),
Expand Down
9 changes: 9 additions & 0 deletions lib/rules/brace-style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @author Yosuke Ota
*/
'use strict'

const { wrapCoreRule } = require('../utils')

// eslint-disable-next-line
module.exports = wrapCoreRule(require('eslint/lib/rules/brace-style'))
69 changes: 69 additions & 0 deletions tests/lib/rules/brace-style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* @author Yosuke Ota
*/
'use strict'

const RuleTester = require('eslint').RuleTester
const rule = require('../../../lib/rules/brace-style')

const tester = new RuleTester({
parser: 'vue-eslint-parser',
parserOptions: { ecmaVersion: 2015 }
})

tester.run('brace-style', rule, {
valid: [
`<template><div :attr="function foo() {
return true;
}" /></template>`,
{
code: `<template><div :attr="function foo() { return true; }" /></template>`,
options: ['1tbs', { 'allowSingleLine': true }]
}
],
invalid: [
{
code: `
<template>
<div :attr="function foo()
{
return true;
}" />
</template>`,
output: `
<template>
<div :attr="function foo() {
return true;
}" />
</template>`,
errors: [
{
message: 'Opening curly brace does not appear on the same line as controlling statement.',
line: 4
}
]
},
{
code: `
<template>
<div :attr="function foo() { return true; }" />
</template>`,
output: `
<template>
<div :attr="function foo() {
return true;\u{20}
}" />
</template>`,
errors: [
{
message: 'Statement inside of curly braces should be on next line.',
line: 3
},
{
message: 'Closing curly brace should be on the same line as opening curly brace or on the line after the previous block.',
line: 3
}
]
}
]
})