Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit db06136

Browse files
ota-meshimichalsnik
authored andcommitted
⭐️New: Add vue/block-spacing rule (vuejs#770)
1 parent 6da3cae commit db06136

File tree

6 files changed

+150
-0
lines changed

6 files changed

+150
-0
lines changed

docs/rules/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ For example:
141141
|:--------|:------------|:---|
142142
| [vue/array-bracket-spacing](./array-bracket-spacing.md) | enforce consistent spacing inside array brackets | :wrench: |
143143
| [vue/arrow-spacing](./arrow-spacing.md) | enforce consistent spacing before and after the arrow in arrow functions | :wrench: |
144+
| [vue/block-spacing](./block-spacing.md) | disallow or enforce spaces inside of blocks after opening block and before closing block | :wrench: |
144145
| [vue/component-name-in-template-casing](./component-name-in-template-casing.md) | enforce specific casing for the component naming style in template | :wrench: |
145146
| [vue/eqeqeq](./eqeqeq.md) | require the use of `===` and `!==` | :wrench: |
146147
| [vue/key-spacing](./key-spacing.md) | enforce consistent spacing between keys and values in object literal properties | :wrench: |

docs/rules/block-spacing.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/block-spacing
5+
description: disallow or enforce spaces inside of blocks after opening block and before closing block
6+
---
7+
# vue/block-spacing
8+
> disallow or enforce spaces inside of blocks after opening block and before closing block
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 [block-spacing] rule but it applies to the expressions in `<template>`.
13+
14+
## :books: Further reading
15+
16+
- [block-spacing]
17+
18+
[block-spacing]: https://eslint.org/docs/rules/block-spacing
19+
20+
## :mag: Implementation
21+
22+
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/block-spacing.js)
23+
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/block-spacing.js)

lib/configs/no-layout-rules.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = {
77
rules: {
88
'vue/array-bracket-spacing': 'off',
99
'vue/arrow-spacing': 'off',
10+
'vue/block-spacing': 'off',
1011
'vue/html-closing-bracket-newline': 'off',
1112
'vue/html-closing-bracket-spacing': 'off',
1213
'vue/html-indent': 'off',

lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
'arrow-spacing': require('./rules/arrow-spacing'),
1212
'attribute-hyphenation': require('./rules/attribute-hyphenation'),
1313
'attributes-order': require('./rules/attributes-order'),
14+
'block-spacing': require('./rules/block-spacing'),
1415
'comment-directive': require('./rules/comment-directive'),
1516
'component-name-in-template-casing': require('./rules/component-name-in-template-casing'),
1617
'eqeqeq': require('./rules/eqeqeq'),

lib/rules/block-spacing.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/block-spacing'))

tests/lib/rules/block-spacing.js

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/**
2+
* @author Yosuke Ota
3+
*/
4+
'use strict'
5+
6+
const RuleTester = require('eslint').RuleTester
7+
const rule = require('../../../lib/rules/block-spacing')
8+
9+
const tester = new RuleTester({
10+
parser: 'vue-eslint-parser',
11+
parserOptions: { ecmaVersion: 2015 }
12+
})
13+
14+
tester.run('block-spacing', rule, {
15+
valid: [
16+
'<template><div :attr="function foo() { return true; }" /></template>',
17+
{
18+
code: '<template><div :attr="function foo() {return true;}" /></template>',
19+
options: ['never']
20+
}
21+
],
22+
invalid: [
23+
{
24+
code: `
25+
<template>
26+
<div :attr="function foo() {return true;}" />
27+
</template>`,
28+
output: `
29+
<template>
30+
<div :attr="function foo() { return true; }" />
31+
</template>`,
32+
errors: [
33+
{
34+
messageId: 'missing',
35+
data: {
36+
location: 'after',
37+
token: '{'
38+
},
39+
// message: 'Requires a space after \'{\'',
40+
line: 3
41+
},
42+
{
43+
messageId: 'missing',
44+
data: {
45+
location: 'before',
46+
token: '}'
47+
},
48+
// message: 'Requires a space before \'}\'',
49+
line: 3
50+
}
51+
]
52+
},
53+
{
54+
code: `
55+
<template>
56+
<button @click="() => {return true;}" />
57+
</template>`,
58+
output: `
59+
<template>
60+
<button @click="() => { return true; }" />
61+
</template>`,
62+
errors: [
63+
{
64+
messageId: 'missing',
65+
data: {
66+
location: 'after',
67+
token: '{'
68+
},
69+
// message: 'Requires a space after \'{\'',
70+
line: 3
71+
},
72+
{
73+
messageId: 'missing',
74+
data: {
75+
location: 'before',
76+
token: '}'
77+
},
78+
// message: 'Requires a space before \'}\'',
79+
line: 3
80+
}
81+
]
82+
},
83+
{
84+
code: `
85+
<template>
86+
<div :attr="function foo() { return true; }" />
87+
</template>`,
88+
options: ['never'],
89+
output: `
90+
<template>
91+
<div :attr="function foo() {return true;}" />
92+
</template>`,
93+
errors: [
94+
{
95+
messageId: 'extra',
96+
data: {
97+
location: 'after',
98+
token: '{'
99+
},
100+
// message: 'Unexpected space(s) after \'{\'',
101+
line: 3
102+
},
103+
{
104+
messageId: 'extra',
105+
data: {
106+
location: 'before',
107+
token: '}'
108+
},
109+
// message: 'Unexpected space(s) before \'}\'',
110+
line: 3
111+
}
112+
]
113+
}
114+
]
115+
})

0 commit comments

Comments
 (0)