Skip to content

Commit 18dab15

Browse files
ota-meshimysticatea
authored andcommitted
New: add vue/dot-location rule (#794)
1 parent 4d01589 commit 18dab15

File tree

6 files changed

+115
-0
lines changed

6 files changed

+115
-0
lines changed

docs/rules/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ For example:
146146
| [vue/camelcase](./camelcase.md) | enforce camelcase naming convention | |
147147
| [vue/comma-dangle](./comma-dangle.md) | require or disallow trailing commas | :wrench: |
148148
| [vue/component-name-in-template-casing](./component-name-in-template-casing.md) | enforce specific casing for the component naming style in template | :wrench: |
149+
| [vue/dot-location](./dot-location.md) | enforce consistent newlines before and after dots | :wrench: |
149150
| [vue/eqeqeq](./eqeqeq.md) | require the use of `===` and `!==` | :wrench: |
150151
| [vue/key-spacing](./key-spacing.md) | enforce consistent spacing between keys and values in object literal properties | :wrench: |
151152
| [vue/match-component-file-name](./match-component-file-name.md) | require component name property to match its file name | |

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

lib/configs/no-layout-rules.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
'vue/block-spacing': 'off',
1111
'vue/brace-style': 'off',
1212
'vue/comma-dangle': 'off',
13+
'vue/dot-location': 'off',
1314
'vue/html-closing-bracket-newline': 'off',
1415
'vue/html-closing-bracket-spacing': 'off',
1516
'vue/html-indent': 'off',

lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
'comma-dangle': require('./rules/comma-dangle'),
1818
'comment-directive': require('./rules/comment-directive'),
1919
'component-name-in-template-casing': require('./rules/component-name-in-template-casing'),
20+
'dot-location': require('./rules/dot-location'),
2021
'eqeqeq': require('./rules/eqeqeq'),
2122
'html-closing-bracket-newline': require('./rules/html-closing-bracket-newline'),
2223
'html-closing-bracket-spacing': require('./rules/html-closing-bracket-spacing'),

lib/rules/dot-location.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/dot-location'))

tests/lib/rules/dot-location.js

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* @author Yosuke Ota
3+
*/
4+
'use strict'
5+
6+
const RuleTester = require('eslint').RuleTester
7+
const rule = require('../../../lib/rules/dot-location')
8+
9+
const tester = new RuleTester({
10+
parser: 'vue-eslint-parser',
11+
parserOptions: { ecmaVersion: 2015 }
12+
})
13+
14+
tester.run('dot-location', rule, {
15+
valid: [
16+
`<template>
17+
<div
18+
:attr="foo.
19+
bar"
20+
/>
21+
</template>`,
22+
{
23+
code: `
24+
<template>
25+
<div
26+
:attr="foo
27+
.bar"
28+
/>
29+
</template>`,
30+
options: ['property']
31+
}
32+
],
33+
invalid: [
34+
{
35+
code: `
36+
<template>
37+
<div
38+
:attr="foo
39+
.bar"
40+
/>
41+
</template>`,
42+
output: `
43+
<template>
44+
<div
45+
:attr="foo.
46+
bar"
47+
/>
48+
</template>`,
49+
errors: [
50+
{
51+
message: 'Expected dot to be on same line as object.',
52+
line: 5
53+
}
54+
]
55+
},
56+
{
57+
code: `
58+
<template>
59+
<div
60+
:attr="foo.
61+
bar"
62+
/>
63+
</template>`,
64+
options: ['property'],
65+
output: `
66+
<template>
67+
<div
68+
:attr="foo
69+
.bar"
70+
/>
71+
</template>`,
72+
errors: [
73+
{
74+
message: 'Expected dot to be on same line as property.',
75+
line: 4
76+
}
77+
]
78+
}
79+
]
80+
})

0 commit comments

Comments
 (0)