Skip to content

Commit

Permalink
⭐️New: Add vue/brace-style rule (#771)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi authored and michalsnik committed Jan 29, 2019
1 parent 40f0dd9 commit 94e4f0b
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/rules/README.md
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
@@ -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
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
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
@@ -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
@@ -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
}
]
}
]
})

0 comments on commit 94e4f0b

Please sign in to comment.